Hey all --
I have this function that should really have been a lookup/mapping table. Its a series of
I want to convert all those lists into entries in a lookup table which looks like
while inserting the value. I'd love to have something like
But I can't seem to find anything that would work like that in the PostgreSQL manual. The closest thing I can find is some arrays stuff, but I can't figure out the right syntax to make that work ...
But I get a syntax error at the opening bracket. I tried replacing with curly braces, but got the same result.
I'd appreciate a nudge in the right direction.
I have this function that should really have been a lookup/mapping table. Its a series of
Code:
IF V_IN in ( /* list of two-character codes */ )
THEN V_OUT = 'Q'
ELSEIF V_IN in ( /* list of more two-character codes */ )
THEN V_OUT = 'X'
END;
RETURN V_OUT;
I want to convert all those lists into entries in a lookup table which looks like
Code:
create table code_lookup (
V_IN varchar(2) primary key not null,
V_OUT varchar(2) not null
);
while inserting the value. I'd love to have something like
Code:
insert into code_lookup ( v_in, v_out ) select v, 'Q' from /* list of two-character codes from above */
But I can't seem to find anything that would work like that in the PostgreSQL manual. The closest thing I can find is some arrays stuff, but I can't figure out the right syntax to make that work ...
Code:
DO
$$
DECLARE
x varchar[];
BEGIN
SELECT x SLICE 1 IN ARRAY [ 'ZZ', 'QQ', /* etc. ]
LOOP
insert into code_lookup ( v_in, v_out ) values ( x, 'Q' );
END LOOP;
END;
$$
LANGUAGE plpgsql;
But I get a syntax error at the opening bracket. I tried replacing with curly braces, but got the same result.
I'd appreciate a nudge in the right direction.