Re: Need help on SP

From: "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at>
To: "Ashish Karalkar *EXTERN*" <ashish_karalkar(at)yahoo(dot)com>, "slony" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Need help on SP
Date: 2007-01-17 08:03:05
Message-ID: 52EF20B2E3209443BC37736D00C3C1380C56479D@EXADV1.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 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

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-01-17 08:22:09 Re: The jdbc and current_timestamp
Previous Message stevegy 2007-01-17 06:08:36 The jdbc and current_timestamp