Settings

Theme

Select Wat from SQL

scattered-thoughts.net

3 points by adito 6 years ago · 2 comments

Reader

TekMol 6 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 6 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;

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection