syntax error foreign key

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

syntax error foreign key

Matthew Terenzio
db=# ALTER TABLE ONLY table ADD CONSTRAINT "$1" FOREIGN KEY (user)
REFERENCES users(user_id);
ERROR:  syntax error at or near "user" at character 56

I'm either blind or something besides syntax can cause this error. no?


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
Reply | Threaded
Open this post in threaded view
|

Re: syntax error foreign key

Matthew Terenzio

On Aug 16, 2005, at 9:37 PM, Matthew Terenzio wrote:

> db=# ALTER TABLE ONLY table ADD CONSTRAINT "$1" FOREIGN KEY (user)
> REFERENCES users(user_id);
> ERROR:  syntax error at or near "user" at character 56
>
> I'm either blind or something besides syntax can cause this error. no?
>
>

changed the field name to userid and it;s fine. Can't user the word
user for field that references?


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
Reply | Threaded
Open this post in threaded view
|

Re: syntax error foreign key

Michael Fuhr
On Tue, Aug 16, 2005 at 10:09:14PM -0400, Matthew Terenzio wrote:
> >db=# ALTER TABLE ONLY table ADD CONSTRAINT "$1" FOREIGN KEY (user)
> >REFERENCES users(user_id);
> >ERROR:  syntax error at or near "user" at character 56
> >
> >I'm either blind or something besides syntax can cause this error. no?
>
> changed the field name to userid and it;s fine. Can't user the word
> user for field that references?

See "Identifiers and Key Words" in the "SQL Syntax" chapter of the
documentation, in particular the part that talks about quoted
identifiers.  Here's a link for the latest version:

http://www.postgresql.org/docs/8.0/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org
Reply | Threaded
Open this post in threaded view
|

Re: syntax error foreign key

Douglas McNaught
In reply to this post by Matthew Terenzio
Matthew Terenzio <[hidden email]> writes:

> On Aug 16, 2005, at 9:37 PM, Matthew Terenzio wrote:
>
>> db=# ALTER TABLE ONLY table ADD CONSTRAINT "$1" FOREIGN KEY (user)
>> REFERENCES users(user_id);
>> ERROR:  syntax error at or near "user" at character 56
>>
>> I'm either blind or something besides syntax can cause this error. no?
>>
>>
>
> changed the field name to userid and it;s fine. Can't user the word
> user for field that references?

USER is an SQL keyword; you have to put it in double quotes to use it
as an identifier.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org
Reply | Threaded
Open this post in threaded view
|

Re: syntax error foreign key

Joshua D. Drake
In reply to this post by Matthew Terenzio
Matthew Terenzio wrote:

>
> On Aug 16, 2005, at 9:37 PM, Matthew Terenzio wrote:
>
>> db=# ALTER TABLE ONLY table ADD CONSTRAINT "$1" FOREIGN KEY (user)
>> REFERENCES users(user_id);
>> ERROR:  syntax error at or near "user" at character 56
>>
>> I'm either blind or something besides syntax can cause this error. no?
>>
>>
>
> changed the field name to userid and it;s fine. Can't user the word
> user for field that references?

probably if you quote it.

Sincerely,

Joshua D. Drake


>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend