Submitted on: 04-12-2001
Description:
Eval() for PostgreSQL. I used this so that I can dig into the default value for a column (in pg_attrdef), which gives me PostgreSQL expressions, like 'f'::bool or 3.5::float. This 'evaluates' that into the value that I can insert (via ODBC front-end) back into the database.
Code:
-- author: Joel Burton
-- license: public domain
CREATE FUNCTION eval(text) RETURNS text AS '
declare
b record;
q text;
begin
q := 'SELECT (' || $1 || ')::text as a';
for b in execute q loop
return b.a;
end loop;
end;
' language 'plpgsql';
|