Differences between ROWTYPE, TYPE, and RECORD in postgresql?
From PostgreSQL's documentation:
TYPE
provides the data type of a variable or table column. You can use this to declare variables that will hold database values. For example, let's say you have a column nameduser_id
in yourusers
table. To declare a variable with the same data type asusers.user_id
you write:user_id users.user_id%TYPE;
.ROWTYPE
: A variable of a composite type is called a row variable (or row-type variable). Such a variable can hold a whole row of aSELECT
orFOR
query result, so long as that query's column set matches the declared type of the variable. The individual fields of the row value are accessed using the usual dot notation, for examplerowvar.field
.RECORD
: Record variables are similar to row-type variables, but they have no predefined structure. They take on the actual row structure of the row they are assigned during aSELECT
orFOR
command. The substructure of a record variable can change each time it is assigned to. A consequence of this is that until a record variable is first assigned to, it has no substructure, and any attempt to access a field in it will draw a run-time error.
See the link for more in-depth examples.