The following bug has been logged online: Bug reference: 5035 Logged by: Email address: tkar...@ultimo.pl PostgreSQL version: 8.3.6 Operating system: Linux Description: cast 'text' to 'name' doesnt work in plpgsql function Details:
Comparing 'text' to 'name' in plpgsl function needs explicit casting to name: CREATE OR REPLACE FUNCTION table_exists(tblname text) RETURNS boolean AS ' DECLARE exists boolean; BEGIN SELECT 1 INTO exists FROM pg_class WHERE relname = name($1); RETURN exists; END; ' LANGUAGE 'plpgsql' IMMUTABLE; test_db=# select table_exists('test_table'); table_exists -------------- (1 row) Time: 0,561 ms test_db=# select 1 from pg_class where relname = 'test_table'; ?column? ---------- (0 rows) Time: 0,337 ms Without casting function executes much slower: CREATE OR REPLACE FUNCTION table_exists(tblname text) RETURNS boolean AS ' DECLARE exists boolean; BEGIN SELECT 1 INTO exists FROM pg_class WHERE relname = name($1); RETURN exists; END; ' LANGUAGE 'plpgsql' IMMUTABLE; test_db=# select table_exists('test_table'); table_exists -------------- (1 row) Time: 15,022 ms Database contains more than 20 000 pg_class tuples. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs