pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Meskes <meskes@postgresql.org>
To: Antonello De Santis <ua01020@flashnet.it>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] Questions about pq library and ecpg
Date: Sat, 10 Apr 1999 12:00:11 +0200
Message-ID: <19990410120011.D2048@gmx.net> (raw)
In-Reply-To: <99032716072200.01169@zeman>
References: <99032716072200.01169@zeman>

On Sat, Mar 27, 1999 at 03:43:23PM +0100, Antonello De Santis wrote:
> ...
> Is it possible to accomplish a query on a table whose name is specified in a
> variable? That is, something like the following:
> 
> strcpy(str, 'table');
> result=PQexec(conn, "insert into str values('Rome', 10)");
> 
> I guess a code like the above one would not give the expected result..... Is
> there a way to work that out?
> I'm trying to use the ecpg preprocessor to pass arguments of a query in
> variables, but I get a few errors.... Here's the piece of code that doesn't
> work:
> ...

Yes, that won't work. But if you commands do not have to transfer data from
the database to C variables you can use "exec sql execute immediate :str"
for whatever command you wrote into the variable string. Or you could use
PREPARE to prepare the statement and then use EXECUTE to execute it as often
as you like.

Check test1.pgc in the source tree for an example.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net          | Use PostgreSQL!



view thread (4+ messages)  latest in thread

Message-ID: <19990410120011.D2048@gmx.net>
Permalink:  ../19990410120011.D2048@gmx.net/
Also on:    postgresql.org/message-id/19990410120011.D2048@gmx.net

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: meskes@postgresql.org, ua01020@flashnet.it
  Subject: Re: [INTERFACES] Questions about pq library and ecpg
  In-Reply-To: <19990410120011.D2048@gmx.net>

* 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