Using UNION inside a cursor

From: "Kumar" <sgnerd(at)yahoo(dot)com(dot)sg>
To: "psql" <pgsql-sql(at)postgresql(dot)org>
Subject: Using UNION inside a cursor
Date: 2003-10-30 08:53:48
Message-ID: 007c01c39ec4$5af992f0$7502a8c0@hdsc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dear Friends,

I am working on Postgresql 7.3.4 on RH Linux Server 7.3.

I have problem in executing the following procedure

CREATE OR REPLACE FUNCTION list_history()
RETURNS refcursor AS
'DECLARE
ref REFCURSOR;
BEGIN
OPEN ref FOR
(SELECT * FROM history WHERE obs_type = \'AA\' )
UNION
(SELECT * FROM history WHERE obs_type = \'TA\');

RETURN ref;
END;'
LANGUAGE 'plpgsql' VOLATILE;

While executing this I got the following error

WARNING: plpgsql: ERROR during compile of list_history near line 5
ERROR: syntax error at "("

While I execute the following code it is working fine and fetches values.
(SELECT * FROM history WHERE obs_type = \'AA\' )
UNION
(SELECT * FROM history WHERE obs_type = \'TA\');

Where I am wrong. Please shed some light,

Regards
Kumar

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message sad 2003-10-30 09:31:54 unescaped output of bytea
Previous Message Paul Ganainm 2003-10-29 19:26:50 Re: Help on update that subselects other records in table, uses joins