pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Ansley <Michael.Ansley@intec-telecom-systems.com>
Cc: Jan Wieck <JanWieck@Yahoo.com>
Cc: sqllist <pgsql-sql@postgresql.org>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [SQL] PL/PGSQL function with parameters
Date: Tue, 06 Feb 2001 11:16:01 -0500
Message-ID: <25204.981476161@sss.pgh.pa.us> (raw)
In-Reply-To: <7F124BC48D56D411812500D0B747251480F3D4@FILESERVER002>
References: <7F124BC48D56D411812500D0B747251480F3D4@FILESERVER002>

Michael Ansley <Michael.Ansley@intec-telecom-systems.com> writes:
> CREATE FUNCTION table_count(varchar) RETURNS integer AS '
> DECLARE
> 	SQL varchar;
> 	RES integer;
> BEGIN
> 	SQL = ''SELECT * INTO temp1 FROM '' || $1;
> 	EXECUTE SQL;
> 	SELECT count(*) INTO RES FROM temp1;
> 	RETURN(RES)
> END;
> '
> LANGUAGE 'plpgsql';

> What I couldn't get it to do was to select directly into the variable RES.

I tried this, and it seems that "SELECT ... INTO foo" is not executed
correctly by EXECUTE --- the INTO is handled as an ordinary select-into-
table construct rather than plpgsql's select-into-variable.

While I have not looked closely, I seem to recall that plpgsql handles
INTO by stripping that clause out of the statement before it's passed to
the SQL engine.  Evidently that's not happening in the EXECUTE case.

Jan, do you agree this is a bug?  Is it reasonable to try to repair it
for 7.1?  If we do not change the behavior of EXECUTE now, I fear it
will be too late --- some people will come to depend on the existing
behavior.

			regards, tom lane



view thread (15+ messages)  latest in thread

Message-ID: <25204.981476161@sss.pgh.pa.us>
Permalink:  ../25204.981476161@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25204.981476161@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Michael.Ansley@intec-telecom-systems.com, JanWieck@Yahoo.com, pgsql-hackers@postgresql.org
  Subject: Re: [SQL] PL/PGSQL function with parameters
  In-Reply-To: <25204.981476161@sss.pgh.pa.us>
  References: <7F124BC48D56D411812500D0B747251480F3D4@FILESERVER002> <25204.981476161@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox