Create data type : Type « Postgre SQL « PostgreSQL






Create data type

postgres=#
postgres=#
postgres=# CREATE TYPE sum_prod AS (sum int, product int);
CREATE TYPE
postgres=#
postgres=# CREATE FUNCTION sum_n_product (int, int) RETURNS sum_prod
postgres-# AS 'SELECT $1 + $2, $1 * $2'
postgres-# LANGUAGE SQL;
CREATE FUNCTION
postgres=#
postgres=# select sum_n_product (2, 1);
     REATE
 sum_n_product
---------------
 (3,2)
(1 row)

postgres=#
postgres=# drop function sum_n_product (int, int) cascade;
DROP FUNCTION
postgres=# drop type sum_prod cascade;
DROP TYPE
postgres=#
postgres=#

           
       








Related examples in the same category

1.Declaration of Composite Types
2.Using the %TYPE attribute
3.Row function with defined data type
4.Create data type and use it as a column data type