Types From Tables in PL/pgSQL
In PL/pgSQL, functions can reuse types of columns in tables.
Similarly, you can hold the entire row in a variable.
Note that %rowtype
is meant for variable declaration, not for return types.
In a Return Type
If you’d like the return type of a function to be a table’s row type, you can use returns setof table_name
.
id | title | author |
---|---|---|
1 | The Great Gatsby | F. Scott Fitzgerald |
The record
type
You can also use type record
, which is a row type with no predefined structure.
Wow! You read the whole thing. People who make it this far sometimes
want to receive emails when I post something new.
I also have an RSS feed.