PostgreSQL: Call a Stored Procedure for Every Row

I guess that newbies in PostgreSQL like me have first question when they create a store procedure:

How do I call it?

The answer is simple; you just execute

.

Then, usually immediately the second question pops up:

I wrote a procedure which I need to call for each row in a table. How do I do that?

The answer is, just as simple; you execute

.

A Short Explanation

Let’s assume a table:

and a procedure:

The procedure is designed to be called for each row in the REFERENCE_XML_DATA table and perform some processing.

The calling statement is:

Then, the CONTENT and ASIDE fields in the REFERENCE_XML_DATA will be interpreted as PRIMARY_CONTENT and SECONDARY_CONTENT respectively.

Simple.

HTH,


A little experiment: If you find this post and ad below useful, please check the ad out :-)




3 thoughts on “PostgreSQL: Call a Stored Procedure for Every Row

  1. Hi,

    Thanks for this helpful tutorial! I’m wondering what if my stored procedure returns table instead of void? For each row, I would like to call my stored procedure which returns a full table.

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top