Search Postgresql Archives

Re: Need help on SP

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

 



> I want to store count(*) of a table in a variable ,
> for that I have declared a variable and wrote a
> statment but it is giving me error.
> can anybody please help me..
> 
> CREATE OR REPLACE FUNCTION foreign_keys_tables(OUT
> par_result charecter varying, IN  par_tablename
> character varying , IN par_clomnname,IN par_colvalue
> integer) AS
> $BODY$)
> DECALRE

This is obviously a typo, as has been pointed out.

>  countno integer;
> BEGIN
> Select count(*) into countno from par_tablename where
> par_columnname=par_colvalue;

You cannot use a variable as tablename in static SQL.
You will have to use dynamic SQL (EXECUTE '...') for that.

> if countno>0 then 
> par_result='yes'
> else 
> par_result='No'
> end if
> 
> END; 
>  $BODY$
>   LANGUAGE 'plpgsql' VOLATILE;

Yours,
Laurenz Albe


[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