Search Postgresql Archives

Re: unable to call a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/04/2013 10:14 AM, giozh wrote:
something gone wrong the same...

REATE OR REPLACE FUNCTION check_if_if_exist(id integer, table_name
character, table_column character)
   RETURNS boolean AS
$BODY$

DECLARE res BOOLEAN;

BEGIN
	EXECUTE 'SELECT EXISTS(SELECT * FROM'||table_name||
		'WHERE'||table_column||'='||$1||')' INTO res USING id;
	RETURN res;
END;

select check_if_exist(10, 'prova', 'identificatore');


RROR:  function check_if_exist(integer, unknown, unknown) does not exist
LINE 1: select check_if_exist(10, 'prova', 'identificatore');
                ^
HINT:  No function matches the given name and argument types. You might need
to add explicit type casts.


Not sure if there is a cut and paste error involved but the function should be something like:

CREATE OR REPLACE FUNCTION utility.check_if_if_exist(id integer, table_name character, table_column character)
 RETURNS boolean
 LANGUAGE plpgsql
AS $BODY$

DECLARE res BOOLEAN;

BEGIN
    EXECUTE 'SELECT EXISTS(SELECT * FROM '||table_name||
        ' WHERE '||table_column||'='||$1||')' INTO res USING id;
    RETURN res;
END;
$BODY$;

I also put in some spaces to make the query work.


--
Adrian Klaver
adrian.klaver@xxxxxxxxx


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux