From: | Moshe Jacobson <moshe(at)neadwerx(dot)com> |
---|---|
To: | giozh <giozh(at)yahoo(dot)it> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: unable to call a function |
Date: | 2013-07-04 16:19:17 |
Message-ID: | CAJ4CxL=CwK2-uYZ-PJ-MSbiKLmHwxo3+mMNZsnfRioRuvaRSYA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
You are passing the literal value "table_name" as the table, and
"column_name" as the column.
You need to concatenate the substituted values onto the string with the ||
operator:
return execute 'select exists(select * from ' || quote_ident(table_name) ||
' where ' || quote_ident(table_column) || ' = ' || id || ')';
(not tested)
On Thu, Jul 4, 2013 at 11:53 AM, giozh <giozh(at)yahoo(dot)it> 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?
>
>
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/unable-to-call-a-function-tp5762590.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
--
Moshe Jacobson
Nead Werx, Inc. | Manager of Systems Engineering
2323 Cumberland Parkway, Suite 201 | Atlanta, GA 30339
moshe(at)neadwerx(dot)com | www.neadwerx.com
"Quality is not an act, it is a habit." -- Aristotle
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2013-07-04 16:20:45 | Re: unable to call a function |
Previous Message | boraldomaster | 2013-07-04 16:08:12 | Re: How to create a cursor that is independent of transactions and doesn't calculated when created ? |