pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Writing SQL functions in Postgres
2+ messages / 2 participants
[nested] [flat]

* Writing SQL functions in Postgres
@ 2001-03-08 16:44  Boulat Khakimov <boulat@inet-interactif.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Boulat Khakimov @ 2001-03-08 16:44 UTC (permalink / raw)
  To: pgsql-sql

Hi,

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.

Anyone was able to returns a row that is a result of few table joins
inside the
function???

Regards,
Boulat Khakimov

 
-- 
Nothing Like the Sun



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Writing SQL functions in Postgres
@ 2001-03-08 18:55  dev@archonet.com
  parent: Boulat Khakimov <boulat@inet-interactif.com>
  0 siblings, 0 replies; 2+ messages in thread

From: dev@archonet.com @ 2001-03-08 18:55 UTC (permalink / raw)
  To: Boulat Khakimov <boulat@inet-interactif.com>; pgsql-sql

Boulat Khakimov <boulat@inet-interactif.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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-03-08 18:55 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-08 16:44 Writing SQL functions in Postgres Boulat Khakimov <boulat@inet-interactif.com>
2001-03-08 18:55 ` dev@archonet.com

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox