官术网_书友最值得收藏!

Schemas

Object names can be reused in different schemas without conflict. The schema contains all the database-named objects, including tables, views, functions, aggregates, indexes, sequences, triggers, data types, domains, and ranges:

By default, there is a schema called public in the template databases. That means all the newly-created databases also contain this schema. All users, by default, can access this schema implicitly. Again, this is inherited from the template databases. Allowing this access pattern simulates a situation where the server is not schema-aware. This is useful in small companies where there's no need to have complex security. Also, this enables a smooth transition from non-schema-aware databases.

In a multi-user and multi-database environment setup, remember to revoke the ability for all users to create objects in the public schema. This is done with the  REVOKE CREATE ON SCHEMA public FROM PUBLIC;  command in the newly-created database, or in the  template1  database.

When a user wants to access a certain object, they need to specify the schema name and the object name separated by a period (.). If the search_path database setting doesn't contain this name, or if the developer likes to use fully-qualified names (for example, to select all the entries in pg_database in the pg_catalog schema), you need to write the following command:

SELECT * FROM pg_catalog.pg_database;
--Alternatively you can also use the following command:
TABLE pg_catalog.pg_database;

Qualified database-object names are sometimes tedious to write, so most developers prefer to use the unqualified object name, which is composed of the object name without the schema. PostgreSQL provides a search_path setting that's similar to the using directive in the C++ language. search_path is composed of schemas that are used by the server to search for the object. The default search_path, as shown in the following code, is $user, public. If there's a schema with the same name as the user, it will be used first to search for objects or to create new objects. If the object isn't found in the schemas specified in the search_path, an error will be thrown as follows:

postgres=# SHOW search_path;
search_path
-----------------
"$user", public
(1 row)
Generally speaking, you shouldn't rely on implicit conventions and information such as SELECT *, NATURAL JOIN, or  JOIN USING. In this context, it's recommended to use fully-qualified names. 
主站蜘蛛池模板: 汽车| 玛多县| 四平市| 临泽县| 景宁| 南郑县| 英吉沙县| 安福县| 荥阳市| 绿春县| 东山县| 金湖县| 平塘县| 崇左市| 突泉县| 玛曲县| 普定县| 大石桥市| 滨州市| 盐亭县| 新田县| 韩城市| 曲阳县| 汝城县| 马山县| 洛南县| 民勤县| 湘潭县| 淮南市| 洞头县| 郴州市| 安陆市| 临江市| 佛坪县| 利津县| 秦皇岛市| 沐川县| 徐州市| 乌拉特后旗| 通州市| 临湘市|