From: | dev(at)archonet(dot)com |
---|---|
To: | "Boulat Khakimov" <boulat(at)inet-interactif(dot)com>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Writing SQL functions in Postgres |
Date: | 2001-03-08 18:55:46 |
Message-ID: | 20010308185546.120762A478@mainbox.archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Boulat Khakimov <boulat(at)inet-interactif(dot)com> said:
> I want to write an SQL function in postgres that returns
> row as a result.
>
> The problem is the select statement inside the funtion has
> a two table join. So I dont know what to put after SETOF
>
> CREATE FUNCTION dummy()
> RETURNS SETOF ?????
> AS 'select a.name,b.cc
> from tblusers a,
> tbldocs b
> where a.name=b.name'
> LANGUAGE 'SQL';
>
>
> SETOF tblusers -- doesnt work
> ERROR: function declared to return type tblusers does not retrieve
> (tblusers.*)
>
> neither does SETOF tbldocs
>
> SETOF tblusers,tbldocs wont work either.
There's good news and bad news.
The good news is that if you define a view "tblboth" that selects from your two tables you can then do "returns setof tblboth".
The bad news is that your function won't return a set of records - you'll get a list of OIDs (at least I think they're OIDs). Check the mailing archives for more on this.
You can do your example with a simple view, but if you want a parameterised view you'll have to wait until 7.2 (I think it's on the todo list)
- Richard Huxton
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Davis | 2001-03-08 19:36:34 | Access tables inside pl/pgsql functions |
Previous Message | Tom Lane | 2001-03-08 17:50:33 | Re: Re: How to drop an <unnamed> trigger |