From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | giozh <giozh(at)yahoo(dot)it> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: unable to call a function |
Date: | 2013-07-04 16:20:45 |
Message-ID: | 51D5A0DD.9060003@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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:
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | giozh | 2013-07-04 16:33:14 | Re: unable to call a function |
Previous Message | Moshe Jacobson | 2013-07-04 16:19:17 | Re: unable to call a function |