Received: from fileserver002.intecsystems.co.uk ([194.200.14.125]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f18DVfx08624; Thu, 8 Feb 2001 08:31:42 -0500 (EST) (envelope-from Michael.Ansley@intec-telecom-systems.com) Received: from fileserver002.intecsystems.co.uk (unverified) by fileserver002.intecsystems.co.uk (Content Technologies SMTPRS 4.1.5) with ESMTP id ; Thu, 8 Feb 2001 13:35:15 +0000 Received: by FILESERVER002 with Internet Mail Service (5.5.2650.21) id <1QKP7HDD>; Thu, 8 Feb 2001 13:35:15 -0000 Message-ID: <7F124BC48D56D411812500D0B747251480F3E2@FILESERVER002> From: Michael Ansley To: "'Jan Wieck'" , Tom Lane Cc: pgsql-hackers@postgreSQL.org, pgsql-sql@postgreSQL.org Subject: RE: [SQL] Re: PL/pgsql EXECUTE 'SELECT INTO ...' Date: Thu, 8 Feb 2001 13:35:14 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/alternative ; boundary="----_=_NextPart_001_01C091D3.F78B2B16" X-Archive-Number: 200102/271 X-Sequence-Number: 4402 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C091D3.F78B2B16 Content-Type: text/plain; charset="iso-8859-1" What I wrote wasn't about temp tables, it was about selecting into plpgsql variables. It would appear that Jan's syntax gets around this problem. MikeA -----Original Message----- From: Jan Wieck [mailto:janwieck@Yahoo.com] Sent: 08 February 2001 13:30 To: Tom Lane Cc: Jan Wieck; pgsql-hackers@postgreSQL.org; pgsql-sql@postgreSQL.org Subject: [SQL] Re: PL/pgsql EXECUTE 'SELECT INTO ...' Tom Lane wrote: > I have looked a little bit at what it'd take to make SELECT INTO inside > an EXECUTE work the same as it does in plain plpgsql --- that is, the > INTO should reference plpgsql variables, not a destination table. > It looks to me like this is possible but would require some nontrivial > re-engineering inside plpgsql. What I'm visualizing is that EXECUTE > should read its string argument not just as an SPI_exec() string, but > as an arbitrary plpgsql proc_stmt. This would offer some interesting > capabilities, like building a whole FOR-loop for dynamic execution. > But there are a number of problems to be surmounted, notably arranging > for the parsetree built by the plpgsql compiler not to be irretrievably > memory-leaked. (That ties into something I'd wanted to do anyway, > which is to have the plpgsql compiler build its trees in a memory > context associated with the function, not via malloc().) > > This does not look like something to be tackling when we're already > in late beta, unfortunately. So we have to decide what to do for 7.1. > If we do nothing now, and then implement this feature in 7.2, we will > have a backwards compatibility problem: EXECUTE 'SELECT INTO ...' > will completely change in meaning. > > I am inclined to keep our options open by forbidding EXECUTE 'SELECT > INTO ...' for now. That's more than a tad annoying, because that leaves > no useful way to do a dynamically-built SELECT, but if we don't forbid > it I think we'll regret it later. You can do something like FOR record_var IN EXECUTE LOOP ... END LOOP; In this case, the executed over SPI_exec() must return tuples (0-n). Otherwise you'll get a runtime error. Inside the loop you have access to the tuples via the record. Is that the dynamically-built SELECT capability you've been missing? There's not that much need for mucking with temp tables in EXECUTE as all this discussion looks to me. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com # _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify Nick West - Global Infrastructure Manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ------_=_NextPart_001_01C091D3.F78B2B16 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable RE: [SQL] Re: PL/pgsql EXECUTE 'SELECT INTO ...'

What I wrote wasn't about temp tables, it was about selec= ting into plpgsql variables.  It would appear that Jan's syntax gets a= round this problem.

MikeA


-----Original Message-----
From: Jan Wieck [m= ailto:janwieck@Yahoo.com]
Sent: 08 February 2001 13:30
To: Tom Lane
Cc: Jan Wieck; pgsql-hackers@postgreSQL.org; pgsql-sql@p= ostgreSQL.org
Subject: [SQL] Re: PL/pgsql EXECUTE 'SELECT INTO ...'


Tom Lane wrote:
> I have looked a little bit at what it'd take to mak= e SELECT INTO inside
> an EXECUTE work the same as it does in plain plpgsq= l --- that is, the
> INTO should reference plpgsql variables, not a dest= ination table.
> It looks to me like this is possible but would requ= ire some nontrivial
> re-engineering inside plpgsql.  What I'm visua= lizing is that EXECUTE
> should read its string argument not just as an SPI_= exec() string, but
> as an arbitrary plpgsql proc_stmt.  This would= offer some interesting
> capabilities, like building a whole FOR-loop for dy= namic execution.
> But there are a number of problems to be surmounted= , notably arranging
> for the parsetree built by the plpgsql compiler not= to be irretrievably
> memory-leaked.  (That ties into something I'd = wanted to do anyway,
> which is to have the plpgsql compiler build its tre= es in a memory
> context associated with the function, not via mallo= c().)
>
> This does not look like something to be tackling wh= en we're already
> in late beta, unfortunately.  So we have to de= cide what to do for 7.1.
> If we do nothing now, and then implement this featu= re in 7.2, we will
> have a backwards compatibility problem: EXECUTE 'SE= LECT INTO ...'
> will completely change in meaning.
>
> I am inclined to keep our options open by forbiddin= g EXECUTE 'SELECT
> INTO ...' for now.  That's more than a tad ann= oying, because that leaves
> no useful way to do a dynamically-built SELECT, but= if we don't forbid
> it I think we'll regret it later.

    You can do something like

        FOR record_var= IN EXECUTE <string-expr> LOOP
         &n= bsp;  ...
        END LOOP;

    In this case, the <string-expr> = executed over SPI_exec() must
    return tuples (0-n). Otherwise you'll= get a runtime error.

    Inside the loop you have access to the= tuples via the record.
    Is  that  the dynamically-b= uilt SELECT capability you've been
    missing?

    There's not that much need for mucking= with  temp  tables  in
    EXECUTE as all this discussion looks = to me.


Jan

--

#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D#
# It's easier to get forgiveness for being wrong than fo= r being right. #
# Let's break this rule - forgive me.   &= nbsp;           &nbs= p;            &= nbsp;     #
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D JanWieck@Yahoo.com #



_________________________________________________________=
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
Nick West - Global Infrastructure Manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************
------_=_NextPart_001_01C091D3.F78B2B16--