Thread: Problem with alter table (creating a foreing key post facto)

Problem with alter table (creating a foreing key post facto)

From
Emmanuel Charpentier
Date:
A curious problem with 7.3.1 : I wanted to add a foreing key constraint to
a table already created and populated. No way, according to Postgres :

Welcome to psql 7.3.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
        \h for help with SQL commands
        \? for help on internal slash commands
        \g or terminate with semicolon to execute query
        \q to quit

essai=# \d tablea
                             Table "public.tablea"
  Column |  Type   |                        Modifiers
--------+---------+----------------------------------------------------------
  keya   | integer | not null default nextval('public.tablea_keya_seq'::text)
  vala   | text    |
Indexes: tablea_pkey primary key btree (keya)

essai=# \d tableb
                             Table "public.tableb"
  Column |  Type   |                        Modifiers
--------+---------+----------------------------------------------------------
  keyb   | integer | not null default nextval('public.tableb_keyb_seq'::text)
  refa   | integer | not null
  valb   | text    |
Indexes: tableb_pkey primary key btree (keyb)

essai=# alter table tableb add constraint lien_a_a foreing key (refa)
references tablea (keya);
ERROR:  parser: parse error at or near "foreing" at character 44
essai=# alter table tableb add foreing key (refa) references tablea (keya);
ERROR:  parser: parse error at or near "(" at character 36

WTF ????

Any ideas ?

Sincerely,

                    Emmanuel Charpentier


Re: Problem with alter table (creating a foreing key post

From
Stephan Szabo
Date:
On Tue, 21 Jan 2003, Emmanuel Charpentier wrote:

> A curious problem with 7.3.1 : I wanted to add a foreing key constraint to
> a table already created and populated. No way, according to Postgres :

It helps if you spell foreign correctly. ;)

> essai=# alter table tableb add constraint lien_a_a foreing key (refa)
> references tablea (keya);
> ERROR:  parser: parse error at or near "foreing" at character 44
> essai=# alter table tableb add foreing key (refa) references tablea (keya);
> ERROR:  parser: parse error at or near "(" at character 36




Re: Problem with alter table (creating a foreing key post

From
Emmanuel Charpentier
Date:
Stephan Szabo wrote:

>On Tue, 21 Jan 2003, Emmanuel Charpentier wrote:
>
>
>>A curious problem with 7.3.1 : I wanted to add a foreing key constraint to
>>a table already created and populated. No way, according to Postgres :
>>
>
>It helps if you spell foreign correctly. ;)
>
[ Feeling *very* silly ... ] Apologies ! English not being my mother
tongue, I overlooked this (although I checked lots of time before
helling for help ...).

>
>
>essai=# alter table tableb add constraint lien_a_a foreing key (refa)
>references tablea (keya);
>ERROR:  parser: parse error at or near "foreing" at character 44
>essai=# alter table tableb add foreing key (refa) references tablea (keya);
>ERROR:  parser: parse error at or near "(" at character 36
>
Thank you !

                    Emmanuel Charpentier




Re: Problem with alter table (creating a foreing key post facto)

From
Dennis Gearon
Date:
spaces not allowed in names, perhaps?


1/20/2003 11:35:38 PM, Emmanuel Charpentier <charpent@bacbuc.dyndns.org> wrote:

>A curious problem with 7.3.1 : I wanted to add a foreing key constraint to
>a table already created and populated. No way, according to Postgres :
>
>Welcome to psql 7.3.1, the PostgreSQL interactive terminal.
>
>Type:  \copyright for distribution terms
>        \h for help with SQL commands
>        \? for help on internal slash commands
>        \g or terminate with semicolon to execute query
>        \q to quit
>
>essai=# \d tablea
>                             Table "public.tablea"
>  Column |  Type   |                        Modifiers
>--------+---------+----------------------------------------------------------
>  keya   | integer | not null default nextval('public.tablea_keya_seq'::text)
>  vala   | text    |
>Indexes: tablea_pkey primary key btree (keya)
>
>essai=# \d tableb
>                             Table "public.tableb"
>  Column |  Type   |                        Modifiers
>--------+---------+----------------------------------------------------------
>  keyb   | integer | not null default nextval('public.tableb_keyb_seq'::text)
>  refa   | integer | not null
>  valb   | text    |
>Indexes: tableb_pkey primary key btree (keyb)
>
>essai=# alter table tableb add constraint lien_a_a foreing key (refa)
>references tablea (keya);
>ERROR:  parser: parse error at or near "foreing" at character 44
>essai=# alter table tableb add foreing key (refa) references tablea (keya);
>ERROR:  parser: parse error at or near "(" at character 36
>
>WTF ????
>
>Any ideas ?
>
>Sincerely,
>
>                    Emmanuel Charpentier
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>