top | item 22895094

Select Wat from SQL

3 points| adito | 5 years ago |scattered-thoughts.net

2 comments

order

TekMol|5 years ago

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)

subleq|5 years ago

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;