Обсуждение: Help for plpgsql!!

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

Help for plpgsql!!

От
"joel xue"
Дата:
Dear Sir/Madam, My table is :
Attribute |   Type    | Modifier
-----------+-----------+----------
empname   | text      |
salary    | integer   |
last_date | timestamp |
last_name | name      |
My function and trigger is:
create function isFull()
returns opaque as ' begin   select count(*) into tmp1 from emp;   if tmp1.count >= 5 then     select min(last_date)
intotmp2 from emp;     delete from emp where last_date=tmp2.min;     drop table tmp2;   end if;   drop table tmp1; end;
'
language 'plpgsql';
create trigger isfull before insert on emp for each row execute procedure 
isFull
();

But my error messages is :
ERROR:  parser: parse error at or near "tmp1"

I can finish these steps in psql environment,why it could not work well in 
plpgsql?Can you help me?
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.



Re: Help for plpgsql!!

От
hubert depesz lubaczewski
Дата:
On Wed, Oct 18, 2000 at 09:53:23PM +0000, joel xue wrote:
> create function isFull()
> returns opaque as '
>   begin
>     select count(*) into tmp1 from emp;                          ^^^^

you didn't declare tmp1. before begin write
declare
tmp1 int4;

depesz

-- 
hubert depesz lubaczewski
------------------------------------------------------------------------    najwspanialszą rzeczą jaką dało nam
nowoczesnespołeczeństwo,     jest niesamowita wręcz łatwość unikania kontaktów z nim ...