Skip site navigation (1) Skip section navigation (2)

plpgsql : adding record variable to table

From: thomas veymont <thomas(dot)veymont(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: plpgsql : adding record variable to table
Date: 2012-04-18 17:55:55
Message-ID: CAHcTkqqDPniDCF_eLqVrHfyYtZUXoGuh21w9_BToMSrJEbUung@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
(sorry my previous email was truncated)

hi,

Here is what I want to do :

I want to check each row of a table against some conditions (this
check needs some
processing stuff I can easily code with pl/pgsql).

If the row is OK, I want to add it in a "resulting table",
else I just ignore the current row and go to next one.

My function looks like this : (simplified)

FUNCTION myfunction (...)  RETURNS TABLE ( elem1 , elem2, elem3 ...)
DECLARE
   g RECORD
BEGIN
 FOR g in SELECT colum1, column2, ... FROM someTable
   LOOP
      -- do some processing on "g", then decide wheter I want to
select it or not
     IF (g is selected) THEN >>add g to resulting_table<<
   END LOOP
  RETURN resulting_table

How should I write the "add g to resulting table" part ?

thanks,
Tom

Responses

pgsql-sql by date

Next:From: Pavel StehuleDate: 2012-04-18 18:03:21
Subject: Re: plpgsql : adding record variable to table
Previous:From: thomas veymontDate: 2012-04-18 17:41:53
Subject: plpgsql : adding record variable to table

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group