gpt4 book ai didi

sql - Postgres : schema does not exist when creating a table

转载 作者:行者123 更新时间:2023-11-29 13:19:52 25 4
gpt4 key购买 nike

尝试创建这样的表时,能否请您告知原因:

CREATE TABLE IF NOT EXISTS  doc.bgp_communities (

i SERIAL PRIMARY KEY,
comm_name TEXT NOT NULL,
comm_value TEXT NOT NULL,
label TEXT NOT NULL,
used_as TEXT NOT NULL,
modified_on TIMESTAMPZ DEFAULT NOW(),

UNIQUE ( comm_value ),
CHECK ( (comm_value SIMILAR TO '%:%') OR (comm_value SIMILAR TO '%:%:%') ),
CHECK ( used_as IN ('bgp-customer','destination','dtv-peer','free-peer','generic','infrastructure','origin','private-peer','public-peer','traffic-eng','voip-peer') )

) ;

在此之前,我创建了如下模式:

ip_spotlight-# CREATE SCHEMA doc
ip_spotlight-# CREATE SCHEMA net
ip_spotlight-# ALTER DATABASE ip_spotlight SET search_path TO doc,net

我收到以下错误消息:

ERROR:  schema "doc" does not exist

你能告诉我做错了什么吗?

PS:我的用户“app”配置如下:

app          | Superuser, No inheritance, Create role, Create DB, Replication | {}

编辑

app@[local]:5432 ip_spotlight# CREATE SCHEMA doc ;
CREATE SCHEMA
Time: 1.492 ms
app@[local]:5432* ip_spotlight# CREATE SCHEMA net ;
CREATE SCHEMA
Time: 0.641 ms
app@[local]:5432* ip_spotlight# ALTER DATABASE ip_spotlight SET search_path TO doc,net ;
ALTER DATABASE
Time: 1.036 ms

# CREATE TABLE IF NOT EXISTS doc.bgp_communities (
ip_spotlight(# i SERIAL PRIMARY KEY,
ip_spotlight(# comm_name TEXT NOT NULL,
ip_spotlight(# comm_value TEXT NOT NULL,
ip_spotlight(# label TEXT NOT NULL,
ip_spotlight(# used_as TEXT NOT NULL,
ip_spotlight(# modified_on TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
ip_spotlight(# UNIQUE ( comm_value ),
ip_spotlight(# CHECK ( (comm_value SIMILAR TO '%:%') OR (comm_value SIMILAR TO '%:%:%') ),
ip_spotlight(# CHECK ( used_as IN ('bgp-customer','destination','dtv-peer','free-peer','generic','infrastructure','origin','private-peer','public-peer','traffic-eng','voip-peer') )
ip_spotlight(# ) ;
ERROR: schema "doc" does not exist
Time: 0.686 ms
app@[local]:5432! ip_spotlight# \dn
ERROR: current transaction is aborted, commands ignored until end of transaction block
app@[local]:5432! ip_spotlight#

最佳答案

你在命令末尾漏掉了分号,所以你可能没有创建任何模式:

ip_spotlight-# CREATE SCHEMA doc
ip_spotlight-# CREATE SCHEMA net
ip_spotlight-# ALTER DATABASE ip_spotlight SET search_path TO doc,net

应该看起来:

t=# CREATE SCHEMA doc;
CREATE SCHEMA
t=# CREATE SCHEMA net;
CREATE SCHEMA
t=# ALTER DATABASE ip_spotlight SET search_path TO doc,net;
ALTER DATABASE

关于sql - Postgres : schema does not exist when creating a table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43979392/

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