Live data from Hacker News

Select Wat from SQL

scattered-thoughts.net

1–3 of 3 posts

Re: Select Wat from SQL

#2
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)

Re: Select Wat from SQL

#3
post #2

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;