| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Joseph Syjuco <joseph(at)asti(dot)dost(dot)gov(dot)ph> |
| Cc: | postgres <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: assign count() result to a declared variable in plpgsql |
| Date: | 2002-06-24 16:12:33 |
| Message-ID: | 18786.1024935153@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Joseph Syjuco <joseph(at)asti(dot)dost(dot)gov(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruce Momjian | 2002-06-24 16:16:36 | Re: variance aggregate function incorrect? Reference Materials |
| Previous Message | Tom Lane | 2002-06-24 15:39:25 | Re: variance aggregate function incorrect? Reference Materials reg create aggregate |