Re: PL/PGSQL - How to pass in variables? - Mailing list pgsql-sql

From Jean-Paul Argudo
Subject Re: PL/PGSQL - How to pass in variables?
Date
Msg-id 44675072.8030104@argudo.org
Whole thread Raw
In response to PL/PGSQL - How to pass in variables?  ("Scott Yohonn" <syohonn@gmail.com>)
List pgsql-sql
Hi Scott,

You'll have to execute dynamic SQL (see doc chapter "36.6.5. Executing
Dynamic Commands") for your function to work:

CREATE FUNCTION get_table_count(tablename text) RETURNS integer AS
$$
DECLARE   --tablename ALIAS FOR $1;    rowcount INTEGER; BEGIN
   execute 'SELECT count(*) FROM '||tablename into rowcount;   return rowcount;
 END;
$$ LANGUAGE 'plpgsql';


select get_table_count('bar');
get_table_count
-----------------              3
(1 row)




Cheers,

-- 
Jean-Paul Argudo
www.PostgreSQLFr.org
www.dalibo.com


pgsql-sql by date:

Previous
From: "Scott Yohonn"
Date:
Subject: PL/PGSQL - How to pass in variables?
Next
From: "Jaime Casanova"
Date:
Subject: Re: PL/PGSQL - How to pass in variables?