X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 3F94B9FA32D for ; Sun, 14 May 2006 12:29:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 93868-10 for ; Sun, 14 May 2006 12:28:59 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.225]) by postgresql.org (Postfix) with ESMTP id E64FB9F9430 for ; Sun, 14 May 2006 12:28:58 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id i23so667157wra for ; Sun, 14 May 2006 08:28:58 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=EKW8LjsV2VEPEY5qWmGKFdHvnm/hJeCsk0WAZsw78lXosTP/uYZKvj9nZJ5BdnwerWsz/jfarZs6fVIcsTlBaOE+GhjpvyaK5Ab8q2NEKALPPnsoFqNADAAt+YS1wWpIz64zsua4k5iTNhTdfXjcba+H2ARKk4zGSRdfHleEIj0= Received: by 10.65.197.9 with SMTP id z9mr2949373qbp; Sun, 14 May 2006 08:28:58 -0700 (PDT) Received: by 10.65.239.19 with HTTP; Sun, 14 May 2006 08:28:58 -0700 (PDT) Message-ID: Date: Sun, 14 May 2006 11:28:58 -0400 From: "Scott Yohonn" To: "pgsql-sql@postgresql.org" Subject: PL/PGSQL - How to pass in variables? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_29089_5238540.1147620538034" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/105 X-Sequence-Number: 25136 ------=_Part_29089_5238540.1147620538034 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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'; ------=_Part_29089_5238540.1147620538034 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Using PL/PGSQL, I am trying to create a procedure to display the
c= ount 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 th= e row count.
I am able to hardcode the variable for table and get the appropriate <= br>results from my count function (see below), but cannot pass in a
var= iable and have the function work. Any suggesstions???
 
CREATE F= UNCTION get_table_count(tablename text) RETURNS integer AS $$
DECLARE
     
     -= -tablename ALIAS FOR $1;
     
  &= nbsp;   rowcount INTEGER;
   BEGIN
  &n= bsp;  
     SELECT INTO rowcount count(*) FROM tablename;=
     
     RETURN rowco= unt;
     
   END;
 $$ LAN= GUAGE 'plpgsql';
 
------=_Part_29089_5238540.1147620538034--