3 ms·
jamie=# create table users ("user" text, "password" text); CREATE TABLE jamie=# insert into users values ('bob', 'whatever'); INSERT 0 1 jamie=# select
by X-Istence 6y ago
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)
Is because the name /user/ is a pseudo-function keyword, and is an alias for /current_user/
test=# select "user", "password" from users;
user | password
------+----------
bob | whatever
(1 row)
Newer versions of PostgreSQL make this more clear:
test=# select user, password from users;
current_user | password
--------------+----------
postgres | whatever
(1 row)
Here is a full list of keywords: https://www.postgresql.org/docs/current/sql-keywords-appendix.html https://www.postgresql.org/docs/current/sql-keywords-appendi...
- kyllo 6y agoThis is the reason why ORMs and SQL generators typically quote all column names in statements.
- em500 6y agoAnd here's what the SQLite manual says about keywords: The SQL standard specifies a large number of keywords which may not be used as the names of tables, indices, columns, databases, user-defined functions, collations, virtual table modules, or any other named object. The list of keywords is so long that few people can remember them all. For most SQL code, your safest bet is to never use any English language word as the name of a user-defined object. https://www.sqlite.org/lang_keywords.html https://www.sqlite.org/lang_keywords.html