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 9C7573A217B for ; Fri, 14 Jan 2005 21:16:06 +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 18999-02 for ; Fri, 14 Jan 2005 21:15:53 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 198093A2175 for ; Fri, 14 Jan 2005 21:15:53 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j0ELFnkA054788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 14 Jan 2005 14:15:51 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j0ELFnR8042790; Fri, 14 Jan 2005 14:15:49 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j0ELFmkh042789; Fri, 14 Jan 2005 14:15:48 -0700 (MST) (envelope-from mfuhr) Date: Fri, 14 Jan 2005 14:15:48 -0700 From: Michael Fuhr To: "Kevin B." Cc: pgsql-sql@postgresql.org Subject: Re: assign the row count of a query to a variable Message-ID: <20050114211548.GA42739@winnie.fuhr.org> References: <1386.67.87.30.165.1105735384.squirrel@www.ke5in.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1386.67.87.30.165.1105735384.squirrel@www.ke5in.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/103 X-Sequence-Number: 19891 On Fri, Jan 14, 2005 at 03:43:04PM -0500, Kevin B. wrote: > I'm trying to assign the row count of a query to a variable in a function > but I'm not having any luck. Please be more specific than "not having any luck." What are you expecting to happen and what actually does happen? > 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. See the "Basic Statements" and "Expressions" sections of the PL/pgSQL documentation. Either of the following should work: var := count(*) FROM T; SELECT INTO var count(*) FROM T; -- Michael Fuhr http://www.fuhr.org/~mfuhr/