postgresql - Return 0 or 1 rows from function -
is possible function return 1 record, return 0 records if there empty result set. example:
if have empty table contains no data...
create table foo ( fooid serial constraint pk_foo primary key, foovalue integer not null );
... , function ...
create or replace function get_onefoo() returns foo $$ select fooid, foovalue foo limit 1 $$ language sql;
... ...
select get_onefoo()
... results in ...
total query runtime: 11 ms. 1 row retrieved.
... ...
select fooid, foovalue foo limit 1
... results in ...
total query runtime: 10 ms. 0 rows retrieved.
returns setof foo
in instead of
returns foo
the later returns composite type:
http://www.postgresql.org/docs/current/static/rowtypes.html
http://www.postgresql.org/docs/current/static/extend-type-system.html#aen51678
Comments
Post a Comment