Reputation: 429
I want to declare variable as
v_nk varchar;
then assign the variable
v_nk := ''S001234','S23401','S34509','S9900'';
and use this variable in select query
select * from mytable where nk in (v_nk);
I want to use this in one of my program(plpgsql) can you please tell me how I should use it?
Upvotes: 0
Views: 97
Reputation: 3266
You can use array :
v_nk := ARRAY [ 'S001234'::text ,'S23401','S34509','S9900'];
OR
v_nk := '{S001234,S23401,S34509,S9900}'::text[];
and use this variable in select query:
select * from mytable where nk = ANY (v_nk);
Upvotes: 3
Reputation: 577
you can define array instead of variable like this:
DECLARE nk_array VARCHAR(30)[] = '{'S001234','S23401','S34509','S9900' }';
select * from mytable where nk in nk_array;
Upvotes: 1