Thread: PERFORM statement

PERFORM statement

From
Mike Christensen
Date:
I was reading about Postgres stored procs in the FAQ:

https://wiki.postgresql.org/wiki/FAQ#Does_PostgreSQL_have_stored_procedures.3F

It claims that an alternative syntax to:

SELECT theNameOfTheFunction(arg1, arg2);

Is:

PERFORM theNameOfTheFunction(arg1, arg2);

However, when I try the following:

CREATE TABLE app_for_leave
(
  sno integer NOT NULL,
  eid integer,
  ename varchar(20),
  sd date,
  ed date,
  sid integer,
  status boolean DEFAULT false,
  CONSTRAINT pk_snoa PRIMARY KEY (sno)
);

CREATE FUNCTION MyInsert(_sno integer, _eid integer, _sd date, _ed date, _sid integer, _status boolean)
  RETURNS void AS
  $BODY$
      BEGIN
        INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status)
        VALUES(_sno, _eid, _sd, _ed, _sid, _status);
      END;
  $BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;

PERFORM MyInsert(1,101,'2013-04-04','2013-04-04',2,'f' );

I get the error:

ERROR: syntax error at or near "PERFORM"
SQL state: 42601
Character: 1

Is the FAQ out of date or was this feature removed?  I'm using 9.2.1.  Thanks!

Mike

Re: PERFORM statement

From
Tony Theodore
Date:

On 09/07/2013, at 2:20 PM, Mike Christensen <mike@kitchenpc.com> wrote:

PERFORM MyInsert(1,101,'2013-04-04','2013-04-04',2,'f' );

I get the error:

ERROR: syntax error at or near "PERFORM"
SQL state: 42601
Character: 1

Is the FAQ out of date or was this feature removed?  I'm using 9.2.1.  Thanks!

I believe PERFORM is a PL/pgSQL construct, not an SQL one. You'd need to execute it inside a function.

Cheers,

Tony


Re: PERFORM statement

From
Mike Christensen
Date:
Ah ok that makes sense.  The FAQ wasn't exactly clear about that.


On Mon, Jul 8, 2013 at 9:38 PM, Tony Theodore <tony.theodore@gmail.com> wrote:

On 09/07/2013, at 2:20 PM, Mike Christensen <mike@kitchenpc.com> wrote:

PERFORM MyInsert(1,101,'2013-04-04','2013-04-04',2,'f' );

I get the error:

ERROR: syntax error at or near "PERFORM"
SQL state: 42601
Character: 1

Is the FAQ out of date or was this feature removed?  I'm using 9.2.1.  Thanks!

I believe PERFORM is a PL/pgSQL construct, not an SQL one. You'd need to execute it inside a function.

Cheers,

Tony



Re: PERFORM statement

From
Raymond O'Donnell
Date:
On 09/07/2013 05:20, Mike Christensen wrote:
> I was reading about Postgres stored procs in the FAQ:
>
> https://wiki.postgresql.org/wiki/FAQ#Does_PostgreSQL_have_stored_procedures.3F
>
> It claims that an alternative syntax to:
>
> SELECT theNameOfTheFunction(arg1, arg2);
>
> Is:
>
> PERFORM theNameOfTheFunction(arg1, arg2);
>
> However, when I try the following:
>
> CREATE TABLE app_for_leave
> (
>   sno integer NOT NULL,
>   eid integer,
>   ename varchar(20),
>   sd date,
>   ed date,
>   sid integer,
>   status boolean DEFAULT false,
>   CONSTRAINT pk_snoa PRIMARY KEY (sno)
> );
>
> CREATE FUNCTION MyInsert(_sno integer, _eid integer, _sd date, _ed date,
> _sid integer, _status boolean)
>   RETURNS void AS
>   $BODY$
>       BEGIN
>         INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status)
>         VALUES(_sno, _eid, _sd, _ed, _sid, _status);
>       END;
>   $BODY$
>   LANGUAGE 'plpgsql' VOLATILE
>   COST 100;
>
> PERFORM MyInsert(1,101,'2013-04-04','2013-04-04',2,'f' );
>
> I get the error:
>
> ERROR: syntax error at or near "PERFORM"
> SQL state: 42601
> Character: 1

PERFORM only works inside a pl/pgsql function. You use it when you want
to discard the result of a SELECT. So, for example, instead of this -

  select foo from bar ...

- you would do this:

  perform foo from bar ...

If you need the result, you would use SELECT INTO <variable>.

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie