Re: dynamic 'INSERT' query?

From: "Dinesh Pandey" <dpandey(at)secf(dot)com>
To: "'Juris Zeltins'" <juris(dot)zeltins(at)gmail(dot)com>
Cc: "'PostgreSQL'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: dynamic 'INSERT' query?
Date: 2005-04-14 12:03:13
Message-ID: 20050414120634.D513853646@svr1.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


FOR _record IN SELECT A1, A2 FROM A

LOOP

--[Dinesh Pandey] -- Sorry I didn't get this part.
_sql := "INSERT INTO B VALUES ( '*" || _record.A1 || "'** , '" || _record.A2
|| "' ***)";

EXECUTE (_sql);

END LOOP;

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 ||
> ')';
>
> =================================================================
>
> Regards
> Dinesh Pandey
>
>
>
*---------------------------------------------------------------------------
-------*
> *Dinesh Pandey*
> Sr. Software Engineer
>

Browse pgsql-sql by date

  From Date Subject
Next Message Dinesh Pandey 2005-04-14 14:28:40 Prepared query ?
Previous Message Sean Davis 2005-04-14 11:59:05 Re: dynamic 'INSERT' query?