Re: Special table names - Mailing list pgsql-novice

From Tom Lane
Subject Re: Special table names
Date
Msg-id 813.1267207337@sss.pgh.pa.us
Whole thread Raw
In response to Re: Special table names  (Marcin Krol <mrkafk@gmail.com>)
List pgsql-novice
Marcin Krol <mrkafk@gmail.com> writes:
> Michael Wood wrote:
>> It seems SQLAlchemy lied to you about creating the table, or perhaps
>> you did not check an error code or something.
>>
>> blah=> create table user (id int);
>> ERROR:  syntax error at or near "user"
>> LINE 1: create table user (id int);

> Apparently it did lie, bc I was able to write objects to that table
> without problems IIRC.

It's fairly likely that what SQLAlchemy actually did was to double-quote
"user" in the commands it issued for you.  Observe:

regression=# create table user (id int);
ERROR:  syntax error at or near "user"
LINE 1: create table user (id int);
                     ^
regression=# create table "user" (id int);
CREATE TABLE
regression=# select * from user;
 current_user
--------------
 postgres
(1 row)

regression=# select * from "user";
 id
----
(0 rows)

Without quotes, user is a reserved word that selects a SQL-standard
function.  With quotes, it's just an identifier that you can use to
name a table if you choose.

            regards, tom lane

pgsql-novice by date:

Previous
From: Marcin Krol
Date:
Subject: Re: Special table names
Next
From: JORGE MALDONADO
Date:
Subject: SERIAL FIELD SEQUENCE MAXIMUM VALUE