sql - Syntax for user defined composite type literal -
i have udts (user defined types) in code (postgresql 9.2)
create type pairs_t (keyname varchar, e_value varchar); create type values_t (e_values varchar[]); create type allvalues_t (regions values_t, products pairs_t);
and used in:
create or replace function foo( in _x allvalues_t[] ) returns void $$ begin...
the actual udts in application more complex.
but cannot figure out how type test case. e.g., if wanted (a,prod-a),(b,prod-b)
products , () regions, how select * foo(...)
statement in pgadmin sql window like? should ...
be?
i appreciate if post guide or page describes syntax. have looked @ postgresql man pages no luck.
check out create type
in manual.
your example defines type allvalues_t
, later uses allvalues
. values_t
-> value_t
. looks simple typos. can't sloppy if want right.
syntax of composite type:
select * foo(('{"(\"(\"\"{arr_a,arr_b}\"\")\",\"(foo,bar)\")","(\"(\"\"{arr_a,arr_b}\"\")\",\"(foo,bar)\")"}'))
how can find out yourself?
create temp table pairs_t (keyname varchar, e_value varchar); -- or create type more permanent solution. insert pairs_t values ('foo', 'bar'); create temp table values_t (e_values varchar[]); insert values_t values ('{arr_a, arr_b}'); create temp table allvalues_t (regions values_t, products pairs_t); insert allvalues_t values((select x values_t x), (select x pairs_t x)); create temp table test (t allvalues_t[]); insert test values (array[(select x allvalues_t x), (select x allvalues_t x)]); select * test select x allvalues_t x;
Comments
Post a Comment