From: | Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> |
---|---|
To: | <dpandey(at)secf(dot)com> |
Cc: | "'PostgreSQL'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: dynamic 'INSERT' query? |
Date: | 2005-04-14 11:59:05 |
Message-ID: | e9917654069296414165126cade4505c@mail.nih.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Dinesh Pandey | 2005-04-14 12:03:13 | Re: dynamic 'INSERT' query? |
Previous Message | Andreas Joseph Krogh | 2005-04-14 11:53:12 | Re: Very low performance on table with only 298 rows |