pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6336: SQL stored procedure returing 'int' calling into SRF does not raise error ...
2+ messages / 2 participants
[nested] [flat]

* BUG #6336: SQL stored procedure returing 'int' calling into SRF does not raise error ...
@ 2011-12-14 19:06  jlrobins@socialserve.com
  0 siblings, 0 replies; 2+ messages in thread

From: jlrobins@socialserve.com @ 2011-12-14 19:06 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      6336
Logged by:          James Robinson
Email address:      jlrobins@socialserve.com
PostgreSQL version: 9.1.2
Operating system:   OSX
Description:        

calling into generate_series() within a 'returns int' (singular) SQL stored
function doesn't raise error (plpgsql does):

-- SQL function elides over fact that generate_series() is a SRF
create function foo_sql()
returns int as
$$
  select * from generate_series(1,5)
$$ language sql stable;

select foo_sql();

/*

whoa --- returns, and just one int.
 foo
-----
   1
*/


create function foo_plpgsql()
returns int as
$$
declare
  retvar int;
begin
  retvar := generate_series(1,5);
  return retvar;
end;
$$ language plpgsql stable;

-- properly fails --- ERROR:  query "SELECT generate_series(1,5)" returned
more than one row
select foo_plpgsql();





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

* Re: BUG #6336: SQL stored procedure returing 'int' calling into SRF does not raise error ...
@ 2011-12-15 01:47  Kevin Grittner <Kevin.Grittner@wicourts.gov>
  0 siblings, 0 replies; 2+ messages in thread

From: Kevin Grittner @ 2011-12-15 01:47 UTC (permalink / raw)
  To: pgsql-bugs; jlrobins@socialserve.com

wrote:
 
> calling into generate_series() within a 'returns int' (singular)
> SQL stored function doesn't raise error (plpgsql does):
> 
> -- SQL function elides over fact that generate_series() is a SRF
> create function foo_sql()
> returns int as
> $$
> select * from generate_series(1,5)
> $$ language sql stable;
> 
> select foo_sql();
> 
> /*
> 
> whoa --- returns, and just one int.
> foo
> -----
> 1
> */
 
This is functioning as designed and documented.  The first two
sentences of the documentation of SQL functions are:
 
| SQL functions execute an arbitrary list of SQL statements,
| returning the result of the last query in the list. In the simple
| (non-set) case, the first row of the last query's result will be
| returned.
 
http://www.postgresql.org/docs/9.1/interactive/xfunc-sql.html
 
-Kevin



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


end of thread, other threads:[~2011-12-15 01:47 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-12-14 19:06 BUG #6336: SQL stored procedure returing 'int' calling into SRF does not raise error ... jlrobins@socialserve.com
2011-12-15 01:47 Re: BUG #6336: SQL stored procedure returing 'int' calling into SRF does not raise error ... Kevin Grittner <Kevin.Grittner@wicourts.gov>

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