postgresql - PL/pgSQL - %TYPE and ARRAY -


is possible use %type , array together?

create function role_update(   in id "role".role_id % type,   in name   "role".role_name % type,   in user_id_list "user".user_id % type[],   in permission_id_list  int[] ) 

i got syntax error this, don't want duplicate column type, want use "user".user_id % type instead of int because easier modify column type later.

as manual explains here:

the type of column referenced writing table_name.column_name%type. using feature can make function independent of changes definition of table.

the same functionality can used in returns clause.

but there no simple way derive array type referenced column, @ least none know of.

about modifying column type later:
aware type of syntax syntactical convenience derive type table column? once created, there no link whatsoever table or column involved.

it helps keep whole create script in sync. id doesn't later changes live objects in database.

related answer on dba.se:


Comments