Re: plpgsql function

From: Yury Don <yura(at)vpcit(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql function
Date: 2000-09-06 04:25:09
Message-ID: 1344512862.20000906102509@vpcit.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Marcin,

Once, Tuesday, September 05, 2000, 8:42:59 PM, you wrote:

MM> Hi,
MM> creation of following function works just fine but usage not:):
MM> mtldb=# select mtldb_wykonane(0);
MM> ERROR: unexpected SELECT query in exec_stmt_execsql()
MM> Can You help me find an error?
MM> tia

MM> CREATE FUNCTION mtldb_wykonane (integer) RETURNS integer AS '
MM> DECLARE
MM> zlecenie alias for $1;
MM> tls integer;
MM> twz integer;
MM> BEGIN
MM> SELECT count(*) as ls FROM serwery;
MM> tls:=new.ls;
MM> SELECT count(*) as wz FROM wykonanie
MM> WHERE zadanie_id=zlecenie AND kiedy IS NOT NULL;
MM> twz:=new.wz;

MM> if tls>twz
MM> RETURN -1;
MM> end if;
MM> if tls=twz
MM> RETURN 1;
MM> end if;
MM> END;
MM> ' LANGUAGE 'plpgsql' ;

Try

CREATE FUNCTION mtldb_wykonane (integer) RETURNS integer AS '
DECLARE
zlecenie alias for $1;
tls integer;
twz integer;
BEGIN
SELECT count(*) as ls into tls FROM serwery;
SELECT count(*) as wz into twz FROM wykonanie
WHERE zadanie_id=zlecenie AND kiedy IS NOT NULL;

if tls>twz
RETURN -1;
end if;
if tls=twz
RETURN 1;
end if;
END;
' LANGUAGE 'plpgsql' ;

BTW, "NEW" can be used only in trigger procedures.

--
Best regards,
Yury ICQ 11831432
mailto:yura(at)vpcit(dot)ru

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ricardo Timaran 2000-09-06 04:49:47 Compilator Postgres
Previous Message Michael Labhard 2000-09-05 22:20:10 Error building JDBC Driver