在 PostgreSQL 中,search_path 是一個環境變量,用于指定數據庫中搜索對象的順序。當執行查詢時,PostgreSQL 將按照指定的搜索路徑順序查找表、視圖、函數等對象。search_path 中包含的 schema 名稱用逗號分隔,可以包括系統 schema、用戶 schema 或者公共 schema。
search_path 的語法如下:
SET search_path TO schema1, schema2, ...;
其中,schema1, schema2 等為數據庫中的 schema 名稱。當執行查詢時,PostgreSQL 將按照指定的搜索路徑順序查找對象。如果指定的 schema 中不存在需要的對象,則會返回錯誤。
可以通過以下方式查看當前的 search_path 設置:
SHOW search_path;
可以通過以下方式修改 search_path 設置:
SET search_path TO schema1, schema2, ...;
另外,也可以在連接到數據庫時通過參數 -c search_path=schema1,schema2 來設置 search_path。