Re: Pass in variable from user???

From: "Michael Artz" <mlartz(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Pass in variable from user???
Date: 2006-05-15 13:10:05
Message-ID: e9c163070605150610r40a1af1fw46fe7a93cd07aeb7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Use 'EXECUTE' to dynamically build SQL:

http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
<http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN>
-Mike

On 13 May 2006 14:15:52 -0700, syohonn(at)gmail(dot)com <syohonn(at)gmail(dot)com> wrote:
>
> 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';
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dave Page 2006-05-15 13:14:08 Re: GUI Interface
Previous Message A. Kretschmer 2006-05-15 13:03:11 Re: Pass in variable from user???