What is a "non-SETOF function"?
What's a non-SETOF function?
It's a function returning a single (scalar) value, e.g. an integer
or a varchar
, e.g.
select upper('foo')`
upper()
is a "non-SETOF" function, it only returns a single value. So a function that is e.g. defined as returns integer
can't return the complete result of a SELECT query, it needs to use return 42;
but it can't use return query ...
;
what's a SETOF function?
It's a function that returns a result set - similar to a table (it's typically declared as returns table (...)
. And you can use it like a table:
select *
from some_set_returning_function();
Fabien Snauwaert
Current interests include NLP, data-visualization, UI/UX and web-apps. Using a variety of tools to get the job done but most prominently: HTML5/CSS3/JS, D3, jQuery; PHP/MySQL; and Python and command-line tools. Also very interested in languages in general; creating rich, interesting games for learning and teaching. Learn English · Apprendre l'anglais · Old personal blog
Updated on July 06, 2022Comments
-
Fabien Snauwaert almost 2 years
Getting into PL/pgSQL…
I'm still learning the syntax. Sometimes, I'd run into this error message:
ERROR: cannot use RETURN QUERY in a non-SETOF function
This sounds sort of cryptic and I could not find information in the Postgres documentation. Hence the question:
- What's a non-SETOF function?
And likewise, assuming there's such a thing, what's a SETOF function?
-
lucastamoios over 2 yearsJust to add, returning a row would also make a function "non-SETOF".