gpt4 book ai didi

sql - Postgres 架构问题

转载 作者:搜寻专家 更新时间:2023-10-30 20:32:32 27 4
gpt4 key购买 nike

这是 PostgreSQL 的默认行为,搜索路径如下:

SHOW search_path;

search_path
--------------
"$user",public

有没有办法让“$user”不区分大小写?

例如我有一个用户 tp1 和一个模式 TP1...我希望他们都被视为“平等”

这可能吗?

最佳答案

永远不要创建区分大小写的内容,句号。曾经。它最终会令人困惑,并会迫使您在使用它们时将它们放在引号中。您可以通过根本不使用双引号来确保您的内容不区分大小写。这就像 Pg 中的基本规则。

简而言之,你不能,但你可以添加到你的 search_path。

test=# create schema "ECARROLL";
CREATE SCHEMA
test=# create table "ECARROLL".foo ( foobar int );
CREATE TABLE
test=# select * from foo;
ERROR: relation "foo" does not exist

如果您愿意,您可以对其他架构进行硬编码:SET search_path TO "$user","ECARROLL",public;

您可以编写不区分大小写的命名模式的查询脚本,并在脚本环境中设置它们。

test=# SELECT schema_name FROM information_schema.schemata WHERE schema_name ILIKE current_user;
schema_name
-------------
ECARROLL

关于sql - Postgres 架构问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2358771/

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