Skip site navigation (1) Skip section navigation (2)

ECPG: CREATE TABLE ... FOREIGN KEY(col) REFERENCES table(col)

From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: pgsql-bugs(at)postgresql(dot)org
Cc: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>,pgsql-interfaces(at)postgresql(dot)org,Michael Meskes <meskes(at)postgresql(dot)org>
Subject: ECPG: CREATE TABLE ... FOREIGN KEY(col) REFERENCES table(col)
Date: 2002-06-18 11:02:30
Message-ID: 15631.4934.470775.776160@kelvin.csl.co.uk (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-interfaces
Hi,

When creating a table in embedded SQL, a foreign key construct like:

 FOREIGN KEY(col) REFERENCES table(col)

is not accepted by ecpg. Consider the following code fragment (error
checking omitted):

  EXEC SQL CREATE TABLE
    colscales(id   INTEGER     NOT NULL,
	      name VARCHAR(64) NOT NULL,
	      auto INTEGER     NOT NULL,
	      PRIMARY KEY(id),
	      UNIQUE(name));

  EXEC SQL CREATE TABLE colscaledata(scale_id  INTEGER     NOT NULL,
				     order_id  INTEGER     NOT NULL,
				     threshold FLOAT       NOT NULL,
				     colour    VARCHAR(10) NOT NULL,
				     FOREIGN KEY(scale_id) REFERENCES colscales(id));

This results in the following output from ecpg:

  src/colourscales_table.pc:55: ERROR: parse error, unexpected `NO', expecting `NOT' or `DEFERRABLE' or `INITIALLY' at or near "NO"

This is with ecpg 2.9.0, PostgreSQL 7.2 on Linux. The same(ish)
statments create the tables without problem with psql.

Obviously the workaround is to use something like:

 FOREIGN KEY(col) REFERENCES table

but this would not work if the desired column was not the primary
key...

BRegards, Lee Kindness.


Responses

pgsql-bugs by date

Next:From: pgsql-bugsDate: 2002-06-18 11:14:50
Subject: Bug #693: python interface doesn't handle int8 correctly.
Previous:From: David M. KaplanDate: 2002-06-18 03:47:27
Subject: pg_hba.conf confusion

pgsql-interfaces by date

Next:From: Henshall, Stuart - WCPDate: 2002-06-18 11:30:49
Subject: Re: Views and Access 2000
Previous:From: Peter EisentrautDate: 2002-06-17 21:22:38
Subject: Re: Where is PLbash ??

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group