sql - Postgresql: syntax error at or near "user" -


this simple question, i've spent embarrassing amount of time trying figure out what's wrong.

i'm trying run query on table "user" containing 2 columns username , id.

insert user    (username, id)  values    ("user", 2) 

i end getting error.

error:  syntax error @ or near "user" line 1: insert user                     ^ ********** error **********  error: syntax error @ or near "user" sql state: 42601 character: 13 

here table creation reference

-- table: public."user"  -- drop table public."user";  create table public."user" (     id integer not null,     username text collate pg_catalog."default",     constraint user_pkey primary key (id) ) (     oids = false ) tablespace pg_default;  alter table public."user"     owner postgres; 

in postgres user reserved sql keyword. should avoid naming tables using reserved keywords. workaround here, can place table name in double quotes when referring it:

insert "user"    (username, id)  values    ('user', 2) 

i switched using single quotes string literals. helps distinguish use of double quotes single ones.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -