Hacker News new | ask | show | jobs
Select Wat from SQL (scattered-thoughts.net)
3 points by adito 2250 days ago
1 comments

Is this one real?

    jamie=# create table users ("user" text, "password" text);
    CREATE TABLE
    jamie=# insert into users values ('bob', 'whatever');
    INSERT 0 1
    jamie=# select user, password from users;
     user  | password
    -------+----------
     jamie | whatever
    (1 row)
Yes, user is a reserved word and `SELECT user` gives you the current database user. Notice how in the create table "user" is quoted, because it would be a syntax error otherwise. If you quote the same way in the select it will give you the user column, not the user reserved word:

    select "user", password from users;