我有一个具有多个模式的postgres数据库。当我用psql从shell连接到数据库并运行\dt时,它使用默认的公共连接模式。是否有可以指定的标志或如何更改模式?
当前回答
关键词:
SET search_path TO
例子:
SET search_path TO your_schema_name;
其他回答
如果你使用PSQL,只需输入
SET schema 'temp';
在此之后,\d显示“temp”中的所有关系
要更改数据库吗?
\l - to display databases
\c - connect to new database
更新。
我又看了一遍你的问题。 显示模式
\dn - list of schemas
要改变模式,您可以尝试
SET search_path TO
在PostgreSQL中,系统通过遵循搜索路径来确定哪个表,该路径是要查找的模式列表。
搜索路径中的第一个匹配表将被视为需要的表,否则,如果没有匹配则引发错误,即使匹配表名称存在于数据库中的其他模式中。
要显示当前搜索路径,您可以使用以下命令:
SHOW search_path;
要把新的模式放到路径中,你可以使用:
SET search_path TO myschema;
或者如果你想要多个模式:
SET search_path TO myschema, public;
参考:https://www.postgresql.org/docs/current/static/ddl-schemas.html
快速解决方案可以是:
SELECT your_db_column_name from "your_db_schema_name"."your_db_tabel_name";
PostgreSQL 14 Debian
postgres@ovhswift:~$ psql
psql (14.0 (Debian 14.0-1.pgdg100+1))
Type "help" for help.
postgres=# create database test;
CREATE DATABASE
postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# create schema tests;
CREATE SCHEMA
test=# \dt
Did not find any relations.
test=# create table pubtable (id integer);
CREATE TABLE
test=# create table tests.schematable (id integer);
CREATE TABLE
test=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------+-------+----------
public | pubtable | table | postgres
(1 row)
test=# \dt tests.
Did not find any relation named "tests.".
test=# \dt tests
Did not find any relation named "tests".
test=# \dt 'tests.'
Did not find any relation named "tests.".
test=# \dt 'tests.*'
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+----------
tests | schematable | table | postgres
(1 row)
test=# \dt 'tests*'
Did not find any relation named "tests*".
test=# \dt 'tests.*'
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+----------
tests | schematable | table | postgres
(1 row)
对于\dv等,同样可以查看模式中的视图
推荐文章
- 将一列的多个结果行连接为一列,按另一列分组
- 使用pgadmin连接到heroku数据库
- 在PostgreSQL中快速发现表的行数
- 更改varchar列的大小为较低的长度
- 如何首次配置postgresql ?
- 数据库性能调优有哪些资源?
- 如何在PostgreSQL中自动更新时间戳
- 当使用JDBC连接到postgres时,是否可以指定模式?
- SQL:从时间戳日期减去1天
- PostgreSQL删除所有内容
- 为什么PostgreSQL要对索引列进行顺序扫描?
- PostgreSQL INSERT ON冲突更新(upsert)使用所有排除的值
- 如何检查一个表是否存在于给定的模式中
- 如何将整数转换为字符串作为PostgreSQL查询的一部分?
- Psycopg2:用一个查询插入多行