pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ryan Mooney <ryan@pcslink.com>
To: pgsql-interfaces@postgresql.org
Subject: ECPG insert into table name as a variable
Date: Tue, 23 Sep 2003 11:12:07 -1000
Message-ID: <20030923211207.GB13521@pcslink.com> (raw)



I was doing testing on an app and wanted to make a table name a variable
so I can change it via a config file (instead of re-compile/relink).

like so:
  EXEC SQL INSERT INTO :tname (host, point, type, cooked) VALUES (:host, :name, :type, :cooked);

This fails ecpg preprocess with "ERROR: syntax error at or near ":tname" whereas if the table 
name is specified statically it works fine, like:
  EXEC SQL INSERT INTO tname (host, point, type, cooked) VALUES (:host, :name, :type, :cooked);

When I tried hacking the resulting C code (as a test exercise) like:

  { ECPGdo(__LINE__, 0, 1, NULL, "insert into ? ( host  , point  , type  , cooked ) values (  ? ,  ? ,  ? ,  ? )",
  ECPGt_char,&(tname),(long)0,(long)1,1*sizeof(char),
  ECPGt_char,&(host),(long)0,(long)1,1*sizeof(char),
  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
  ECPGt_char,&(name),(long)0,(long)1,1*sizeof(char),
  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
  ECPGt_char,&(type),(long)1,(long)1,1*sizeof(char),
  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
  ECPGt_char,&(cooked),(long)1,(long)1,1*sizeof(char),
  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
  ECPGt_char,(starttime),(long)30,(long)1,30*sizeof(char),
  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
  ECPGt_char,(interval),(long)30,(long)1,30*sizeof(char),
  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,

it got all funny and didn't work very well (well ok it didn't work at all):
  pg.pgc:129 SQL Insert failed: Invalid statement name (null) in line 124.

So, I was wondering am I just missing some obvious way to do this, or
is this not supported at all?

Thanks


-- 
>-=-=-=-=-=-=-<>-=-=-=-=-=-<>-=-=-=-=-=-<>-=-=-=-=-=-<>-=-=-=-=-=-=-<
Ryan Mooney          				 ryan@pcslink.com 
<-=-=-=-=-=-=-><-=-=-=-=-=-><-=-=-=-=-=-><-=-=-=-=-=-><-=-=-=-=-=-=-> 



view thread (3+ messages)  latest in thread

Message-ID: <20030923211207.GB13521@pcslink.com>
Permalink:  ../20030923211207.GB13521@pcslink.com/
Also on:    postgresql.org/message-id/20030923211207.GB13521@pcslink.com

 · 

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: ryan@pcslink.com
  Subject: Re: ECPG insert into table name as a variable
  In-Reply-To: <20030923211207.GB13521@pcslink.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