| From: | "syohonn(at)gmail(dot)com" <syohonn(at)gmail(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Pass in variable from user??? |
| Date: | 2006-05-13 21:15:52 |
| Message-ID: | 1147554952.782465.146620@i40g2000cwc.googlegroups.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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';
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Martijn van Oosterhout | 2006-05-13 21:18:10 | Re: INSERT RULE doesn't allow OLD, so how does one work with serial datatypes? |
| Previous Message | Karen Hill | 2006-05-13 21:11:14 | INSERT RULE doesn't allow OLD, so how does one work with serial datatypes? |