X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EF82C3A200F for ; Fri, 14 Jan 2005 20:43:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14857-02 for ; Fri, 14 Jan 2005 20:43:37 +0000 (GMT) Received: from echo3.echoechoplus.com (echo3.echoechoplus.com [66.98.254.65]) by svr1.postgresql.org (Postfix) with ESMTP id 0D6613A1A20 for ; Fri, 14 Jan 2005 20:43:38 +0000 (GMT) X-ClientAddr: 127.0.0.1 Received: from ke5in.com (localhost.localdomain [127.0.0.1]) by echo3.echoechoplus.com (8.12.10/8.12.10) with SMTP id j0EKh3Yt028065 for ; Fri, 14 Jan 2005 15:43:04 -0500 Received: from ool-43571ea5.dyn.optonline.net ([67.87.30.165]) (SquirrelMail authenticated user db@ke5in.com) by www.ke5in.com with HTTP; Fri, 14 Jan 2005 15:43:04 -0500 (EST) Message-ID: <1386.67.87.30.165.1105735384.squirrel@www.ke5in.com> Date: Fri, 14 Jan 2005 15:43:04 -0500 (EST) Subject: assign the row count of a query to a variable From: "Kevin B." To: pgsql-sql@postgresql.org Reply-To: db@ke5in.com User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-EchoEchoPlus-MailScanner-Information: Please contact the ISP for more information X-EchoEchoPlus-MailScanner: Not scanned: please contact your Internet E-Mail Service Provider for details X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200501/101 X-Sequence-Number: 19889 Hi, I'm trying to assign the row count of a query to a variable in a function but I'm not having any luck. Could someone tell me the syntax? I've been looking in the docs and googling for a long time but just can't find the answer. I've tried: CREATE OR REPLACE FUNCTION ret1() RETURNS int4 AS ' BEGIN declare var int4; begin --select var count(*) from T; --select var (count(*)) from T; --select var = count(*) from T; var = select count(*) from T; return var; END; END; ' LANGUAGE 'plpgsql';