From: Richard Huxton <dev@archonet.com>
To: dpandey@secf.com
Cc: PostgreSQL <pgsql-sql@postgresql.org>
Subject: Re: Prepared query ?
Date: Thu, 14 Apr 2005 15:58:53 +0100
Message-ID: <425E852D.2020808@archonet.com> (raw)
In-Reply-To: <20050414143144.1704853689@svr1.postgresql.org>
References: <20050414143144.1704853689@svr1.postgresql.org>
Dinesh Pandey wrote:
> How can I
>
> 1. Write a prepared query and
> 2. Set values at run time and
> 3. Execute that query for different values.
> LOOP
> …..
> …..
> sql := INSERT INTO MYTABLE VALUES(?, ?);
> --EXECUTE (sql);
You don't say what language you want to use, but assuming it's plpgsql,
then for the simple case you can just do:
LOOP
INSERT INTO mytable VALUES (var1, var2);
END LOOP
Now, let's say you wanted to change mytable as well as the values, you'd use
sql := ''INSERT INTO '' || quote_ident(my_table_variable) || ''
VALUES ...etc'';
EXECUTE sql;
Does that help?
--
Richard Huxton
Archonet Ltd
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: dev@archonet.com, dpandey@secf.com
Subject: Re: Prepared query ?
In-Reply-To: <425E852D.2020808@archonet.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