PostgreSQL converting crappy mapping function to a table

Hey all --

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.
 
I sussed it:
Code:
create or replace function add_codes(y varchar[], z varchar) returns void AS $$
declare
  x: varchar;
begin
  foreach x in ARRAY y
  LOOP
    insert into code_lookup ( V_IN, V_OUT ) values ( X, z );
  END LOOP;
end;
$$
language plpgsql;

select add_codes(ARRAY[/* list of two-character values */, 'Q' );
select add_codes(ARRAY[/* another list of two-character values */, 'Z');
etc.
 
Late to the party, but I can't pass up a SQL question, especially when my first thought is such a different approach. Assuming the 2 character codes contain only A-Z, I'd build out every possible code and run them all through the actual function:
Code:
with Letters as (select regexp_split_to_table('ABCDEFGHIJKLMNOPQRSTUVWXYZ','') as Letter)
, Codes as (select A.Letter||B.Letter as Code
			from Letters as A
			cross join Letters as B
			order by A.Letter
			, B.Letter)
insert into code_lookup
(
	V_IN
	, V_OUT
)
select Code as V_IN
, lookup_function(V_IN) as V_OUT
from Codes
where lookup_function(V_IN) is not null;
That way there's no chance of missing some quirk in the logic that changes a lookup value, and nobody has to extract all the codes from the function. The string in regexp_split_to_table can be expanded to whatever the actual valid characters in the input codes are.