by wiredfool · 3y ago · 0 comments
wiredfool=> select * from user;
user
-----------
wiredfool
(1 row)
Rule 0, Don't name tables with reserved words. test=# create table test (
id serial,
"user" text,
date text,
timestamp text,
name text,
version text);
CREATE TABLE
Then again, lots of things are actually valid column identifiers, if they're quoted. test=# alter table test add column "select" text;
ALTER TABLE
test=# alter table test add column "*" text;
ALTER TABLE
test=# alter table test add column "from" text;
ALTER TABLE
test=# select "select", "*", "from" from test;
select | * | from
--------+---+------
(0 rows)
test=# \d test
Table "public.test"
Column | Type | Collation | Nullable | Default
-----------+---------+-----------+----------+----------------------------------
id | integer | | not null | nextval('test_id_seq'::regclass)
user | text | | |
date | text | | |
timestamp | text | | |
name | text | | |
version | text | | |
select | text | | |
* | text | | |
from | text | | |Or maybe get into the habit of wrapping your table/column names with backticks to tell the query language of choice that you're not referring about the keyword.