Re: unable to call a function
От | Adrian Klaver |
---|---|
Тема | Re: unable to call a function |
Дата | |
Msg-id | 51D5A0DD.9060003@gmail.com обсуждение исходный текст |
Ответ на | unable to call a function (giozh <giozh@yahoo.it>) |
Список | pgsql-general |
On 07/04/2013 08:53 AM, giozh wrote: > i've write this function that search if inside a specified table there's a > specified value: > > CREATE FUNCTION check_if_if_exist(id INTEGER, table_name character(50), > table_column character(20) ) RETURNS BOOLEAN AS $$ > > BEGIN > RETURN EXECUTE 'SELECT EXISTS(SELECT * FROM table_name WHERE table_column = > id)'; > END; > > $$ LANGUAGE plpgsql > > but when i try to call it i always receive an error and the function will > not call. where is the problem? Try: CREATE OR REPLACE FUNCTION utility.check_if_if_exist(id integer, table_name character, table_column character) RETURNS boolean LANGUAGE plpgsql AS $function$ DECLARE _exists boolean; BEGIN EXECUTE 'SELECT EXISTS(SELECT * FROM '|| table_name || ' WHERE ' || table_column ||' = $1)' INTO _exists USING id ; RETURN _exists; END; More information here: http://www.postgresql.org/docs/9.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN -- Adrian Klaver adrian.klaver@gmail.com
В списке pgsql-general по дате отправления: