assign count() result to a declared variable in plpgsql

Поиск
Список
Период
Сортировка
Искать

assign count() result to a declared variable in plpgsql

От:
Joseph Syjuco <joseph@asti.dost.gov.ph>
Дата:

i want to put my count() result in a plpgsql declared integer variable


declare f_count_var integer;
beginselect into f_count_var count(empno) from employee
end;

tried this one but it doesnt work










Re: assign count() result to a declared variable in plpgsql

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Joseph Syjuco  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



Re: assign count() result to a declared variable in plpgsql

От:
Jeff Eckermann <jeff_eckermann@yahoo.com>
Дата:
try:
f_count_var := count(empno) from employee;

--- Joseph Syjuco  wrote:
> 
> 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
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please
> send an appropriate
> subscribe-nomail command to majordomo@postgresql.org
> so that your
> message can get through to the mailing list cleanly
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



FAQ