为什么CREATE TABLE中的一个标识符被双引号引起来,而其他标识符却不被双引号引起来? [英] Why is one identifier in a CREATE TABLE double-quoted, but not the others?

查看:185
本文介绍了为什么CREATE 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 )
);

为什么"position"名称包含""?
如何从position中删除""?

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

推荐答案

根据手册position

非保留(不能为函数或类型)

non-reserved (cannot be function or type)

这是标准SQL中的保留字.您所看到的可能是pgAdmin或某些其他客户端的输出,该输出在用作标识符时将SQL标准中的所有保留字都用双引号引起来.

It's a reserved word in standard SQL. What you see is probably the output of pgAdmin or some other client that double-quoting all reserved words in SQL standard when used as identifiers.

此语句在语法上是正确的:

This statement is syntactically correct:

SELECT position FROM author LIMIT 1;

可以始终用双引号引起来(从而保留混合大小写的拼写).这也可行:

You can always double-quote identifiers (thereby preserving mixed-case spelling). This works, too:

SELECT "position" FROM author LIMIT 1;

但是这里需要双引号:

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

这篇关于为什么CREATE TABLE中的一个标识符被双引号引起来,而其他标识符却不被双引号引起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆