pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL functions - bug?
Date: Mon, 05 Jun 2000 11:55:26 -0400
Message-ID: <12315.960220526@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.05.10006051019070.19686-100000@pc10.radnoti-szeged.sulinet.hu>
References: <Pine.LNX.4.05.10006051019070.19686-100000@pc10.radnoti-szeged.sulinet.hu>

Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu> writes:
> There is a function "function_y(...)" which returns int4; a table z and
> two functions:

> CREATE FUNCTION function_x1() RETURNS int4 AS '
> select function_y(any_of_fields_of_table_z) from z;
> ' LANGUAGE 'SQL';

> This calls function_y(...) only with the first row of the query output of
> the select statement. Instead of this,

> CREATE FUNCTION function_x2() RETURNS int4 AS '
> select function_y(z_field_any) from z;
> select 1;
> ' LANGUAGE 'SQL';

> works properly (the important thing for me is to call function_y with
> all rows of the select query). So, the second workaround is OK, but in my
> opinion function_x1() also should call function_y(...) for as many rows as
> exist in the output. Is this a bug?

The only bug I could see in function_x1() is that perhaps the system
should raise an error if the final select of the function tries to yield
more than one tuple, rather than just stopping its evaluation after one
tuple.  (In effect, there's an implicit LIMIT 1 on that select.)

You've declared a function returning int4; that is to say, *one* int4
per call.  No more.  The behavior you are after requires a different
declaration:

regression=# CREATE FUNCTION function_x1() RETURNS SETOF int4 AS '
regression'# select f1 from int4_tbl;
regression'# ' LANGUAGE 'SQL';
CREATE
regression=# select function_x1();
  ?column?
-------------
           0
      123456
     -123456
  2147483647
 -2147483647
(5 rows)

Functions returning sets have a lot of restrictions on them, some of
which you will no doubt find out the hard way :-(.  But the basic
feature works.

			regards, tom lane



view thread (2+ messages)

Message-ID: <12315.960220526@sss.pgh.pa.us>
Permalink:  ../12315.960220526@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12315.960220526@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tip@pc10.radnoti-szeged.sulinet.hu
  Subject: Re: SQL functions - bug?
  In-Reply-To: <12315.960220526@sss.pgh.pa.us>
  References: <Pine.LNX.4.05.10006051019070.19686-100000@pc10.radnoti-szeged.sulinet.hu> <12315.960220526@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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