From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joseph Syjuco <joseph@asti.dost.gov.ph>
Cc: postgres <pgsql-sql@postgresql.org>
Subject: Re: assign count() result to a declared variable in plpgsql
Date: Mon, 24 Jun 2002 12:12:33 -0400
Message-ID: <18786.1024935153@sss.pgh.pa.us> (raw)
In-Reply-To: <1024932336.15861.8.camel@Askr>
References: <1024932336.15861.8.camel@Askr>
Joseph Syjuco <joseph@asti.dost.gov.ph> writes:
> i want to put my count() result in a plpgsql declared integer variable
> declare f_count_var integer;
> begin
> select into f_count_var count(empno) from employee
> end;
> tried this one but it doesnt work
Works for me:
regression=# create function foo() returns int as '
regression'# declare f_count_var integer;
regression'# begin
regression'# select into f_count_var count(unique1) from tenk1;
regression'# return f_count_var;
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select foo();
foo
-------
10000
(1 row)
What PG version are you using?
regards, tom lane
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: tgl@sss.pgh.pa.us, joseph@asti.dost.gov.ph
Subject: Re: assign count() result to a declared variable in plpgsql
In-Reply-To: <18786.1024935153@sss.pgh.pa.us>
* 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