Why is one identifier in a CREATE TABLE double-quoted, but not the others?

蓝咒 提交于 2020-01-06 19:00:13

问题


I set the table

CREATE TABLE author (
  id serial NOT NULL,
  name character varying(255) NOT NULL,
  orcid character varying(128) NOT NULL,
  "position" integer NOT NULL,
  CONSTRAINT author_pkey PRIMARY KEY (id )
);

Why does the "position" name contain ""?
How can I remove "" from position?


回答1:


Actually, position is

non-reserved (cannot be function or type)

I am referring to the list of reserved words in the manual. What you see is most probably the output of pgAdmin (which you should have mentioned). pgAdmin also quotes identifiers that are reserved words according to any SQL standard - which is true for position.

This statement is therefore syntactically correct:

SELECT position FROM author LIMIT 1;

Of course, you can always double-quote identifiers, this would work, too:

SELECT "position" FROM author LIMIT 1;

But with statements like these you would need the double quotes:

SELECT "where" FROM author LIMIT 1;
SELECT "CaMeL" FROM author LIMIT 1;
SELECT "a-b-c" FROM author LIMIT 1;


来源:https://stackoverflow.com/questions/13004537/why-is-one-identifier-in-a-create-table-double-quoted-but-not-the-others

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