search_path 如何影响标识符解析和“当前模式"? [英] How does the search_path influence identifier resolution and the "current schema"

查看:25
本文介绍了search_path 如何影响标识符解析和“当前模式"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以定义默认情况下在哪个架构中创建新表?(由非限定表名"引用.)

Is it possible to define in which schema new tables get created by default? (Referred by "unqualified table names".)

我已经看到了一些关于在 Postgres 中使用搜索路径"的细节,但我认为它只在检索数据时有效,而不是在创建时有效.

I've seen some details about using the "search path" in Postgres, but I think it only works while retrieving data, not creating.

我有一堆 SQL 脚本,它们创建了许多表.我不想修改脚本,而是希望在默认情况下在特定模式中设置数据库创建表 - 当它们具有不合格的名称时.

I have a bunch of SQL scripts, which create many tables. Instead of modifying the scripts, I want to set the database create tables in a specific schema by default - when they have unqualified names.

这可能吗?

推荐答案

搜索路径确实是你想要的:

Search path is indeed what you want:

% create schema blarg;
% set search_path to blarg;
% create table foo (id int);
% d
       List of relations
 Schema | Name | Type  | Owner 
--------+------+-------+-------
 blarg  | foo  | table | pgsql

这篇关于search_path 如何影响标识符解析和“当前模式"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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