BUG #5035: cast 'text' to 'name' doesnt work in plpgsql function
От | |
---|---|
Тема | BUG #5035: cast 'text' to 'name' doesnt work in plpgsql function |
Дата | |
Msg-id | 200909041027.n84ARiNB078986@wwwmaster.postgresql.org обсуждение исходный текст |
Ответы |
Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsql
function
|
Список | pgsql-bugs |
The following bug has been logged online: Bug reference: 5035 Logged by: Email address: tkarlik@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.
В списке pgsql-bugs по дате отправления: