Re: plpgsql function - Mailing list pgsql-general

From Yury Don
Subject Re: plpgsql function
Date
Msg-id 1344512862.20000906102509@vpcit.ru
Whole thread Raw
In response to plpgsql function  (Marcin Mazurek <M.Mazurek@poznan.multinet.pl>)
Responses Re: plpgsql function  (Marcin Mazurek <M.Mazurek@poznan.multinet.pl>)
List 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@vpcit.ru



pgsql-general by date:

Previous
From: "Just Me"
Date:
Subject: ODBC problems solved with latest drivers
Next
From: Tom Lane
Date:
Subject: Re: psql: FATAL 1: Index pg_class_relname_index is not a btree