473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Column name 'user' not allowed?

Hi,

I tried to install phpopenchat but I can't create this table:

poc=> CREATE TABLE poc_user_account (
poc(> USER varchar(255) NOT NULL,
poc(> PASSWORD varchar(255),
poc(> CONFIRM_CODE char(32),
poc(> DISABLED int NOT NULL DEFAULT '0',
poc(> KICKED int NOT NULL DEFAULT '0',
poc(> PASSWORD_NEW varchar(255),
poc(> PRIMARY KEY (USER)
poc(> );
ERROR: syntax error at or near "USER" at character 35

After searching a while what's wrong I renamed column USER to USER2 and
now I can create the table! I don't see a reason why column name USER
isn't allowed?!

I am running Postgres 7.4.2 on Linux.

Thanks!
Thomas
--
http://www.tmueller.com for pgp key (95702B3B)
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
6 12057
Thomas Mueller <ne************@tmueller.com> wrote:
Hi,

I tried to install phpopenchat but I can't create this table:

poc=> CREATE TABLE poc_user_account (
poc(> USER varchar(255) NOT NULL,
poc(> PASSWORD varchar(255),
poc(> CONFIRM_CODE char(32),
poc(> DISABLED int NOT NULL DEFAULT '0',
poc(> KICKED int NOT NULL DEFAULT '0',
poc(> PASSWORD_NEW varchar(255),
poc(> PRIMARY KEY (USER)
poc(> );
ERROR: syntax error at or near "USER" at character 35

After searching a while what's wrong I renamed column USER to USER2 and
now I can create the table! I don't see a reason why column name USER
isn't allowed?!


Because it's a reserved word in PostgreSQL's SQL syntax.

You can also work around this by enclosing the name in quotes. This also
makes the column name case-sensitive though, so you need to be sure that
_all_ processes/code/whatever that accesses this table can properly address
the column with the proper case. i.e. if you use "USER" and later try to
SELECT user FROM poc_user_account, you'll get an error that the column
doesn't exist. In fact, even if you do SELECT USER FROM poc_user_account,
you'll still get an error, as Postgres will fold the name to lower case.
Once you've got a case-sensitive name, you must do SELECT "USER" FROM ...

--
Bill Moran
Potential Technologies
http://www.potentialtech.com

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
Hi,

I tried to install phpopenchat but I can't create this table:

poc=> CREATE TABLE poc_user_account (
poc(> USER varchar(255) NOT NULL,
poc(> PASSWORD varchar(255),
poc(> CONFIRM_CODE char(32),
poc(> DISABLED int NOT NULL DEFAULT '0',
poc(> KICKED int NOT NULL DEFAULT '0',
poc(> PASSWORD_NEW varchar(255),
poc(> PRIMARY KEY (USER)
poc(> );
ERROR: syntax error at or near "USER" at character 35

After searching a while what's wrong I renamed column USER to USER2 and
now I can create the table! I don't see a reason why column name USER
isn't allowed?!


USER is a reserved word in SQL (at least in 92, and I think they only
added to the list in later versions) which technically makes it
unavailable as a non-quoted identifier. If you were careful about
quoting, you could use "USER" (note the double quotes) for creating it and
all references to it.
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3
On Wed, Jul 07, 2004 at 05:17:08PM -0400, Bill Moran wrote:
Thomas Mueller <ne************@tmueller.com> wrote:
now I can create the table! I don't see a reason why column name USER
isn't allowed?!


Because it's a reserved word in PostgreSQL's SQL syntax.

You can also work around this by enclosing the name in quotes. This also
makes the column name case-sensitive though, so you need to be sure that
_all_ processes/code/whatever that accesses this table can properly address
the column with the proper case. i.e. if you use "USER" and later try to
SELECT user FROM poc_user_account, you'll get an error that the column
doesn't exist.


Even worse, you don't get an error at all, but you get your current connection
username:

alberto=# select user from pg_database;
current_user
--------------
alberto
alberto
alberto
(3 rows)

--
-----------------------
Alberto Cabello Sánchez
al*****@unex.es
Servicio de Informática
924 289 351
-----------------------

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

Nov 23 '05 #4
On Thu, 8 Jul 2004, Alberto Cabello Sanchez wrote:
On Wed, Jul 07, 2004 at 05:17:08PM -0400, Bill Moran wrote:
Thomas Mueller <ne************@tmueller.com> wrote:
now I can create the table! I don't see a reason why column name USER
isn't allowed?!


Because it's a reserved word in PostgreSQL's SQL syntax.

You can also work around this by enclosing the name in quotes. This also
makes the column name case-sensitive though, so you need to be sure that
_all_ processes/code/whatever that accesses this table can properly address
the column with the proper case. i.e. if you use "USER" and later try to
SELECT user FROM poc_user_account, you'll get an error that the column
doesn't exist.


Even worse, you don't get an error at all, but you get your current connection
username:

alberto=# select user from pg_database;
current_user
--------------
alberto
alberto
alberto
(3 rows)


Right, because USER effectively means CURRENT_USER (as per the rules in
SQL92 6.2/SQL99 6.3). The choice of having USER be a reserved word which
basically means the same thing as CURRENT_USER by the committee doing the
SQL spec was unfortunate.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #5
On Thu, 2004-07-08 at 09:35, Stephan Szabo wrote:
On Thu, 8 Jul 2004, Alberto Cabello Sanchez wrote:
On Wed, Jul 07, 2004 at 05:17:08PM -0400, Bill Moran wrote:
Thomas Mueller <ne************@tmueller.com> wrote:
> now I can create the table! I don't see a reason why column name USER
> isn't allowed?!

Because it's a reserved word in PostgreSQL's SQL syntax.

You can also work around this by enclosing the name in quotes. This also
makes the column name case-sensitive though, so you need to be sure that
_all_ processes/code/whatever that accesses this table can properly address
the column with the proper case. i.e. if you use "USER" and later try to
SELECT user FROM poc_user_account, you'll get an error that the column
doesn't exist.


Even worse, you don't get an error at all, but you get your current connection
username:

alberto=# select user from pg_database;
current_user
--------------
alberto
alberto
alberto
(3 rows)


Right, because USER effectively means CURRENT_USER (as per the rules in
SQL92 6.2/SQL99 6.3). The choice of having USER be a reserved word which
basically means the same thing as CURRENT_USER by the committee doing the
SQL spec was unfortunate.


That said, the choice of USER as a column name in phpopenchat is even
more unfortunate. Someone should open a bug report with them and site
the sql spec so that they change the column to a friendlier (and more
compliant) name.

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #6
> I tried to install phpopenchat but I can't create this table:

poc=> CREATE TABLE poc_user_account (
poc(> USER varchar(255) NOT NULL,


Thanks everyone!
Creating the database with quoted USER column worked fine, now I have to
resolve the other problems.

I'd like to see one application developed for MySQL that works with any
other database out of the box ...
Thomas
--
http://www.tmueller.com for pgp key (95702B3B)
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wiebke Pätzold | last post by:
Hi all! I create a database that contains a table. 'Nachname' is one of 13 column names. This program can search for a special letter. In my example it is 'ra'. and the search takes place in...
3
by: uw_badgers | last post by:
Is it possible to create a unique constraint to a column from another table? For example: tb_current: current_names -------------- aaa bbb tb_new:
1
by: Will | last post by:
I have a combo box on a form which is based on table tblMachine. On that combo box I have four columns visible MachineNumber, description, location and type. The bound column is the MachineNumber...
1
by: benfly08 | last post by:
Hi, guys. I just wonder whether a space within column name is allowed in SQL Server 2000(i.e. "Item Number" as column name). In a stored procedure i saw: Create table #temp (ExpiryDate...
1
by: imauser | last post by:
I have a database(PostgreSQL) table(about 70k rows).I am developing an ASP webpage and there is a list-box on it which contains the name of the columns of that table. User selects the column name...
3
by: rn5a | last post by:
A MS-Access DB table has the following 6 columns - TeacherID, ClassID, VenueID, AvailDate, StartTime & EndTime. The data type of the 1st 3 columns is int whereas the data type of the last 3 columns...
1
by: Chalkie | last post by:
Hello, I've hit what appears to be a serious problem with an unbound datagridview control that Ive added to a VB.Net program. Inadvertently I named one column 'Name' and a second 'Size'. The...
0
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi all, I have a column that the user is only allowed to edit if s/he added the row. I set read-only = true for this column when I load the grid. I allow the user to add a row by clicking a...
3
by: Csaba Gabor | last post by:
I have a table with 3 rows, and two pieces of data to display in each row. However, the first element of the last two rows and the 2nd element of the 1st row are very short. This would seem to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.