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

* SQL functions - bug?
@ 2000-06-05 08:32  Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
  0 siblings, 1 reply; 2+ messages in thread

From: Kovacs Zoltan Sandor @ 2000-06-05 08:32 UTC (permalink / raw)
  To: pgsql-sql

I realized the following facts using SQL language functions:

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?

I am using 7.0 (8th May).

Regards,
Zoltan




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

* Re: SQL functions - bug?
@ 2000-06-05 15:55  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2000-06-05 15:55 UTC (permalink / raw)
  To: Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>; +Cc: pgsql-sql

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



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


end of thread, other threads:[~2000-06-05 15:55 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-06-05 08:32 SQL functions - bug? Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
2000-06-05 15:55 ` Tom Lane <tgl@sss.pgh.pa.us>

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