Postgresql: syntax error at or near “user”

前端 未结 1 1823
后悔当初
后悔当初 2021-01-18 07:13

This is probably a simple question, but I\'ve spent an embarrassing amount of time trying to figure out what\'s wrong.

I\'m trying to run a query on a table \"user\"

1条回答
  •  抹茶落季
    2021-01-18 07:42

    In Postgres user is a reserved SQL keyword. You should avoid naming your tables using reserved keywords. As a workaround here, you can place your table name in double quotes when referring to it:

    INSERT INTO "user"
       (username, id) 
    VALUES
       ('user', 2)
    

    I also switched to using single quotes for string literals. This helps to distinguish the use of double quotes from single ones.

    0 讨论(0)
提交回复
热议问题