From: Scott Yohonn <syohonn@gmail.com>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: PL/PGSQL - How to pass in variables?
Date: Sun, 14 May 2006 11:28:58 -0400
Message-ID: <ff1df1410605140828s2ac7c170j9d7c4e5b2b0a1f5c@mail.gmail.com> (raw)
Using PL/PGSQL, I am trying to create a procedure to display the
count of rows in any single table of a database. The End-user would
pass in a table name and the prodecure would display the table name
with the row count.
I am able to hardcode the variable for table and get the appropriate
results from my count function (see below), but cannot pass in a
variable and have the function work. Any suggesstions???
CREATE FUNCTION get_table_count(tablename text) RETURNS integer AS $$
DECLARE
--tablename ALIAS FOR $1;
rowcount INTEGER;
BEGIN
SELECT INTO rowcount count(*) FROM tablename;
RETURN rowcount;
END;
$$ LANGUAGE 'plpgsql';
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: syohonn@gmail.com
Subject: Re: PL/PGSQL - How to pass in variables?
In-Reply-To: <ff1df1410605140828s2ac7c170j9d7c4e5b2b0a1f5c@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox