Question:
Create table SQL statement?
DavidG
2009-08-31 02:20:56 UTC
hey guys,

I was just wondering what the restrictions are on column names when creating a table using PostGresSQL
The following wouldn't work for me,

Create Table ABUNDANCE ( Words varchar(24) , ABUNDANCE numeric(4) , LOTS numeric(4) , PLENTY numeric(4) , MANY numeric(4) , MONEY numeric(4) , FOOD numeric(4) , MUCH numeric(4) , LACK numeric(4) , SCARCITY numeric(4) , FULL numeric(4) , FAMINE numeric(4) , LARGE numeric(4) , LITTLE numeric(4) , MORE numeric(4) , PEOPLE numeric(4) , TREES numeric(4) , VARIETY numeric(4) , WATER numeric(4) , primary key (ABUNDANCE) ) ;

With the error message -
ERROR: syntax error at or near "FULL"
LINE 135: ...c(4) , LACK numeric(4) , SCARCITY numeric(4) , FULL numer...

For which I have absolutely no idea why it is happening?

Any ideas?

Cheers,

David
Three answers:
Anton
2009-08-31 02:31:13 UTC
FULL is a reserved keyword, used to identify the type of a JOIN, for example:



SELECT column_name(s)

FROM table_name1

FULL JOIN table_name2

ON table_name1.column_name=table_name2.column_name



The list of reserved keywords depends on the SQL implementation. For example in MySQL 5.1 FULL is not a reserved keyword, while in Postgres SQL and MS SQL it is a reserved keyword.



It's a good idea to prefix your table names
popek
2016-10-18 14:34:56 UTC
EDIT: i'm sorry, I made a mistake This you would be able to paintings mysql_query(' CREATE table `watchlist`( `username` VARCHAR(sixteen) no longer NULL, `offence` text fabric no longer NULL, `punishment` text fabric no longer NULL, time-honored KEY (`username`) ) ') or die (mysql_error());
david e
2009-08-31 02:28:56 UTC
FULL is a reserved word for most SQL variants example, for the clause "FULL OUTER JOIN". try another column name.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...