如果資料庫中沒有定義特定的模式,那么資料庫物件將存盤在哪里?這是好事還是壞事?為什么?
uj5u.com熱心網友回復:
從手冊中參考
在前面的部分中,我們創建了表而不指定任何模式名稱。默認情況下,此類表(和其他物件)會自動放入名為“public”的模式中。每個新資料庫都包含這樣的模式
如果在創建表時未定義模式,則在模式搜索路徑中找到的第一個(現有)模式將用于存盤表。
uj5u.com熱心網友回復:
在psql
create database sch_test;
CREATE DATABASE
\c sch_test
You are now connected to database "sch_test" as user "postgres".
--Show available schemas
\dn
List of schemas
Name | Owner
-------- ----------
public | postgres
drop schema public ;
DROP SCHEMA
\dn
List of schemas
Name | Owner
------ -------
(0 rows)
show search_path ;
search_path
-----------------
"$user", public
create table tbl(id integer);
ERROR: no schema has been selected to create in
LINE 1: create table tbl(id integer);
create table test.tbl(id integer);
ERROR: schema "test" does not exist
LINE 1: create table test.tbl(id integer);
只是為了表明如果模式不存在,則可能不會創建物件。底線是需要在模式中創建物件(表、函式等)。如果沒有可供search_path查找的物件,或者您專門指向一個不存在的物件,則物件創建將失敗。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/463030.html
標籤:sql PostgreSQL 图式
上一篇:視窗功能需要分組嗎?
下一篇:更改列以使其成為派生列
