Declaring Variables LIKE Columns
If you use the LIKE clause, the database server assigns the variable the same data type as a specified column in a table, synonym, or view.
The data types of variables that are defined as database columns are resolved at runtime; therefore, column and table do not need to exist at compile time.
You can use the LIKE keyword to declare that a variable is like a serial column. This declares:
- An INTEGER variable if the column is of the SERIAL data type
- An INT8 variable if the column is of the SERIAL8 data type
- A BIGINT variable if the column is of the BIGSERIAL data type
For example, if the column serialcol in the mytab table
has the SERIAL data type, you can create the following SPL function:
CREATE FUNCTION func1() DEFINE local_var LIKE mytab.serialcol; RETURN; END FUNCTION;
The variable local_var is treated as an INTEGER variable.