gpt4 book ai didi

postgresql - 我们可以使用 "name"作为 PostgreSQL 中的列名吗?

转载 作者:行者123 更新时间:2023-12-02 17:08:55 24 4
gpt4 key购买 nike

我们可以在 PostgreSQL 中使用“name”作为列名吗?

我试过了,表创建成功。当我对表或表数据执行任何操作时会出错吗?

name是保留关键字吗?

更新:试过这个

select * from pg_get_keywords()

发现“name”是未保留的。还是想确认我是否可以使用那个名字?

最佳答案

https://www.postgresql.org/docs/current/static/datatype-character.html#DATATYPE-CHARACTER-SPECIAL-TABLE

"name" is internal type for object names

是的 - 你可以:

t=# create table "b@dPract!c3" ("name" text, "date" timestamptz);
CREATE TABLE
t=# insert into "b@dPract!c3" values('wrong',now());
INSERT 0 1
t=# select * from "b@dPract!c3";
name | date
-------+-------------------------------
wrong | 2018-05-09 08:38:53.612212+01
(1 row)

你应该这样做吗?当然不是! 用数据类型名称命名列很容易,但实际上是不好的做法

关于postgresql - 我们可以使用 "name"作为 PostgreSQL 中的列名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50245875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com