Re: EXECUTE command in stored procedure - Mailing list pgsql-general

From Guy Rouillier
Subject Re: EXECUTE command in stored procedure
Date
Msg-id D4D1632DC736E74AB95FE78CD609007923B134@mtxexch01.add0.masergy.com
Whole thread Raw
In response to EXECUTE command in stored procedure  ("Arunagiri K" <arungi.pgsql@gmail.com>)
List pgsql-general
Arunagiri K wrote:
> Dear All,
>
> How can I use EXCEUTE command in stored procedures?
> When using like this
>
> EXECUTE 'SELECT INTO REGNO REG_NO FROM ADMISSION WHERE SNAME = ' ||
> STUDNAME ;
>
> STUDNAME is a local variable;
>
> I am getting error like this
>
> ERROR:  syntax error at or near "INTO" at character 8
>
> How can I solve this.

You don't mention which version of PostgreSQL you are using, or which
stored procedure language.  I'll assume 8.1.x and PL/pgSQL.  See section
36.6 in the documentation.  Specifically, 36.6.5 says:

"SELECT INTO is not currently supported within EXECUTE."

However, if I'm understanding what you are trying to do, you shouldn't
need the EXECUTE at all.  Doing a simple SELECT INTO should work for
you.  Note also that since you are only retrieving a single value, you
can also avoid INTO altogether with something like:

REGNO := (select regno from admission where sname = myname);

--
Guy Rouillier

pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: How to force the parser to use index scan instead of
Next
From: "stevegy"
Date:
Subject: Re: Hi, For the UTF-8 encoding