From: Kevin B. <db@ke5in.com>
To: pgsql-sql@postgresql.org
Subject: assign the row count of a query to a variable
Date: Fri, 14 Jan 2005 15:43:04 -0500 (EST)
Message-ID: <1386.67.87.30.165.1105735384.squirrel@www.ke5in.com> (raw)
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';
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: db@ke5in.com
Subject: Re: assign the row count of a query to a variable
In-Reply-To: <1386.67.87.30.165.1105735384.squirrel@www.ke5in.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox