From: Sean Davis <sdavis2@mail.nih.gov>
To: dpandey@secf.com
Cc: 'PostgreSQL' <pgsql-sql@postgresql.org>
Subject: Re: dynamic 'INSERT' query?
Date: Thu, 14 Apr 2005 07:59:05 -0400
Message-ID: <e9917654069296414165126cade4505c@mail.nih.gov> (raw)
In-Reply-To: <20050414114131.C840B53726@svr1.postgresql.org>
References: <20050414114131.C840B53726@svr1.postgresql.org>
On Apr 14, 2005, at 7:37 AM, Dinesh Pandey wrote:
> How can we set A1, A2 values in dynamic 'INSERT’ query?
>
>
>
> DECLARE
>
> _record RECORD;
>
> _sql VARCHAR(2000);
>
>
>
> FOR _record IN SELECT A1, A2 FROM A
>
> LOOP
>
>
>
> _sql := 'INSERT INTO B VALUES (:A1, :A2)’;
>
>
>
> EXECUTE (_sql);
>
>
>
> END LOOP;
>
>
>
> =================================================================
>
> I can do this as (but I need another way instead of using || operator).
>
>
>
> _sql := 'INSERT INTO B VALUES (‘ || _record.A1 || ’,’ || _record.A2 ||
> ’)’;
>
Dinesh,
I think what you are showing here IS the way to build up a dynamic sql
statement. I'm not sure that you can write a prepared statement within
the body of a function, which would then look more like what you are
suggesting you want to do--perhaps others on the list can enlighten us
about that. In any case, why won't using the || operator work for you?
Sean
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sdavis2@mail.nih.gov, dpandey@secf.com
Subject: Re: dynamic 'INSERT' query?
In-Reply-To: <e9917654069296414165126cade4505c@mail.nih.gov>
* 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