pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ramakrishnan Muralidharan <ramakrishnanm@pervasive-postgres.com>
To: dpandey@secf.com
To: pgsql-sql@postgresql.org
Subject: Re: 'Select INTO" in Execute (dynamic query )
Date: Wed, 20 Apr 2005 15:51:25 +0530
Message-ID: <02767D4600E59A4487233B23AEF5C5992A407C@blrmail1.aus.pervasive.com> (raw)

         Hi,
 
            It is not possible to access a local variable in EXECUTE Command and give a syntax error. FOR..IN..LOOP is the best option
            
            CREATE OR REPLACE FUNCTION TestQry( vCon teXt )
            RETURNS VARCHAR AS $$
            DECLARE
               var1 varchar(10);
               var2 varchar(10);
               result varchar( 20 ); 
               rRec  RECORD; 
            BEGIN
   
                 FOR rRec IN EXECUTE( 'SELECT A1,A2 FROM  '||vCon ) LOOP
                       var1 = rRec.A1;
                       var2 = rRec.A2;
                 END LOOP;
  
               RETURN VAR1||VAR2;
   
            END;
            $$ LANGUAGE 'plpgsql';
 
         Regards,
         R.Muralidharan.

-----Original Message-----
From: Dinesh Pandey [mailto:dpandey@secf.com]
Sent: Monday, April 18, 2005 9:35 PM
To: pgsql-sql@postgresql.org; pgsql-general@postgresql.org
Subject: [SQL] 'Select INTO" in Execute (dynamic query )



Hi

 

What's wrong with this code (ERROR:  syntax error at or near "INTO" at character 8)?

 

Problem: I want to put A1, A2 values in two variables vara, varb.

 

CREATE OR REPLACE FUNCTION test(text) 

RETURNS VARCHAR AS $$

Declare

          vara    VARCHAR(10) :='';

          varb    VARCHAR(10) :='';

          result  VARCHAR(10) :='Result';

          

BEGIN           

          EXECUTE(

                   'Select INTO vara, varb A1, A2 from '|| $1 

          );

          

RETURN result||': '|| vara ||' '|| varb;

 

END;

$$ LANGUAGE plpgsql;

 

 

Regards
Dinesh Pandey




 

view thread (3+ messages)

Message-ID: <02767D4600E59A4487233B23AEF5C5992A407C@blrmail1.aus.pervasive.com>
Permalink:  ../02767D4600E59A4487233B23AEF5C5992A407C@blrmail1.aus.pervasive.com/
Also on:    postgresql.org/message-id/02767D4600E59A4487233B23AEF5C5992A407C@blrmail1.aus.pervasive.com

 · 

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: ramakrishnanm@pervasive-postgres.com, dpandey@secf.com
  Subject: Re: 'Select INTO" in Execute (dynamic query )
  In-Reply-To: <02767D4600E59A4487233B23AEF5C5992A407C@blrmail1.aus.pervasive.com>
  References: <02767D4600E59A4487233B23AEF5C5992A407C@blrmail1.aus.pervasive.com>

* 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