Thread: reference constraint creation problem

reference constraint creation problem

From
kmh496
Date:
hello everybody!!

i am trying to emulate mysql enum's by creating another table, putting
in the allowed values for the enum, and creating a REFERENCE CONSTRAINT
to it.  So, i have the created reference table:

mod=# \d qp_qualchoice_goodchoice_constraint_table;
Table "mod_schema.qp_qualchoice_goodchoice_constraint_table"
   Column   |         Type         | Modifiers
------------+----------------------+-----------
 goodChoice | character varying(3) | not null
Indexes:
    "qp_qualchoice_goodchoice_constraint_table_pkey" PRIMARY KEY, btree
("goodChoice")

mod=# select * from qp_qualchoice_goodchoice_constraint_table;
 goodChoice
------------
 n
 y
(2 rows)

mod=# \q


but when i try to do the following table which references it........

--
-- Table structure for table qp_qualchoice
--

CREATE TABLE qp_qualchoice (
  "qid" int2 NOT NULL default '0',
  "choiceid" int2 NOT NULL default '0',
 "goodChoice" varchar CONSTRAINT qp_qualchoice_goodChoice_constraint
REFERENCES qp_qualchoice_goodChoice_constraint_table (goodChoice)
default 'n',
  "choiceText" text NOT NULL,
  "addate" date default NULL,
  "moddate" date default NULL,
  "battery_id" varchar(15) default 'klpt4'
)  ;


i get this error:

psql:pg_sql.sql:44: ERROR:  column "goodchoice" referenced in foreign
key constraint does not exist


BUT THAT COLUMN EXISTS, so where is my mistake?

thanks to all.....

joseph.



--
<a href="http://openandout.com/~jcs/">who am I?</a>.






Re: reference constraint creation problem

From
"A. Kretschmer"
Date:
am  15.06.2006, um 23:18:58 +0900 mailte kmh496 folgendes:
>    Column   |         Type         | Modifiers
> ------------+----------------------+-----------
>  goodChoice | character varying(3) | not null
       ^
       |
       'C'


> REFERENCES qp_qualchoice_goodChoice_constraint_table (goodChoice)
                                                        ^        ^
                                                        |        |

my guess: you need there "


>
> psql:pg_sql.sql:44: ERROR:  column "goodchoice" referenced in foreign
                                          ^
                                          |
                                          'c'


HTH, Andreas
--
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47215,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    ===