ERROR: column of relation does not exist PostgreSQL ,Unable to run insert query

不羁岁月 提交于 2020-01-10 03:44:12

问题


Hi I am trying to insert into a table tester3 it fails when i use the syntax

insert into tester3 (UN0, UN1) values ( 1, 'jishnu1');

but

insert into tester3 values ( 1, 'jishnu1');

is working fine.

mydb=# CREATE TABLE tester3
mydb-#    (
mydb(#     "UN0" integer,
mydb(#     "UN1" VARCHAR(40)
mydb(#    );
CREATE TABLE
mydb=# insert into tester3 (UN0, UN1) values ( 1, 'jishnu1');
ERROR:  column "un0" of relation "tester3" does not exist
mydb=# \d tester3
           Table "public.tester3"
 Column |         Type          | Modifiers
--------+-----------------------+-----------
 UN0    | integer               |
 UN1    | character varying(40) |

I think i am missing something very trivial, I tried someother column names some of them works fine and some are not working. I am confused. Does PostgreSQL have restriction in column names for which works the 1st syntax of insert query works?


Edit : As suggested by Gordon Linoff using double quotes solved the problem.

insert into tester3 ("UN0", "UN1") values ( 1, 'jishnu1'); works fine

And as Frank Heikens pointed out the other column names which was working without quotes where lower case.

Lower case column is the standard within PostgreSQL and also works without quotes


回答1:


If you define the columns with double quotes, then you need to use them when you refer to the column:

insert into tester3 ("UN0", "UN1")
     values ( 1, 'jishnu1');

I would suggest you remove the double quotes from the column names in the CREATE TABLE statement.




回答2:


try this using double quotes to your column names

insert into tester3 ("UN0", "UN1") values ( 1, 'jishnu1');


来源:https://stackoverflow.com/questions/31072143/error-column-of-relation-does-not-exist-postgresql-unable-to-run-insert-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!