Re: Special table names

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marcin Krol <mrkafk(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Special table names
Date: 2010-02-26 18:02:17
Message-ID: 813.1267207337@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Marcin Krol <mrkafk(at)gmail(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message JORGE MALDONADO 2010-02-27 23:43:00 SERIAL FIELD SEQUENCE MAXIMUM VALUE
Previous Message Marcin Krol 2010-02-26 16:26:51 Re: Special table names