CREATE OR REPLACE FUNCTION get_user(test integer)
RETURNS SETOF test AS $BODY$
DECLARE r record;
BEGIN
FOR r IN SELECT * FROM test where id=$1 LOOP
RETURN NEXT r;
END LOOP;
if not found then
for r in WITH a (id, a, c ) as (
insert into test values($1,$1,$1), ($1+200,$1,$1+20000) returning *)select * from a LOOP
return NEXT r;
end loop;
end if;
END;
$BODY$
RETURNS SETOF test AS $BODY$
DECLARE r record;
BEGIN
FOR r IN SELECT * FROM test where id=$1 LOOP
RETURN NEXT r;
END LOOP;
if not found then
for r in WITH a (id, a, c ) as (
insert into test values($1,$1,$1), ($1+200,$1,$1+20000) returning *)select * from a LOOP
return NEXT r;
end loop;
end if;
END;
$BODY$
LANGUAGE plpgsql;
table_regx = re.compile("FROM (?P<table_name>.*?)(LIMIT|ORDER|GROUP|HAVING|WHERE|LEFT|RIGHT|INNER|$)", re.I)