plpgsql question

From: Matthew Peter <survivedsushi(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: plpgsql question
Date: 2006-01-04 23:51:09
Message-ID: 20060104235109.1076.qmail@web35201.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm trying to do a simple SELECT * in plpgsql that returns a set of records as a row w/ columns, not a row into a variable, w/ some conditionals.

The function below is semi-pseudo with what I'm trying to... If anyone could give me an example that works by returning it as a resultset maintaining the columns, that would be awesome and I could take it from there.

I've read the pl/pgsql section of the docs and the Douglas book but I'm still confused on this issue...

Thanks

create or replace function getrecord(int,text) RETURNS SETOF records as $$
DECLARE
-- event := rows to return from the table below

BEGIN
event := SELECT * FROM my_tbl
WHERE 1 = 1
and my_tbl_id IN (0$1) ||
' IF $2 IS NOT NULL THEN' || and username = $2 || 'END IF;'
; -- end sql statement

RETURN event;

END;
$$ LANGUAGE plpgsql;



---------------------------------
Yahoo! DSL Something to write home about. Just $16.99/mo. or less

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric Busto 2006-01-05 00:43:01 unsubscribe
Previous Message Sven Willenberger 2006-01-04 22:39:35 Re: insert serial numbers