Postgresql

了解 psql 中 d <table> 的輸出

  • February 7, 2014

假設我執行以下命令:

\d mtb.big_table

我得到如下所示的輸出。我的問題是:

  1. 什麼是列修飾符?(什麼default now()意思?)
  2. Indexes,為什麼有些索引會引用多個列?(我認為列只能引用一列)
  3. Foreign-key constraints當它談論的時候REFERENCES和下面那個說的下一組之間是什麼關係"Referenced by"?(為什麼只有兩個Foreign-key constraints這麼多的 TABLE 引用?)。

例如,以下條目:

TABLE "dt.table_segment_hierarchy" CONSTRAINT "dx_segment_hierarchy_ancestor_segment_uid_fkey" FOREIGN KEY (ancestor_segment_uid) REFERENCES dt.table_segment(object_uid)

閱讀:

TABLE &lt;table_1&gt; CONSTRAINT &lt;column_1&gt; FOREIGN_KEY (&lt;column_2&gt;) REFERENCES &lt;table_2&gt;(&lt;column_3&gt;)

這些表和列之間的關係是什麼?


更一般地說,我在哪裡可以找到有關\d命令輸出格式的更多資訊?

                                                  Table "dt.table_segment"
        Column         |            Type             |                              Modifiers                              
------------------------+-----------------------------+---------------------------------------------------------------------
segment_id             | integer                     | not null default nextval('dt.table_segment2_segment_id_seq'::regclass)
segment_type           | character varying(31)       | not null
object_uid             | character varying(255)      | not null
object_version         | timestamp without time zone | default now()
name                   | character varying(255)      | not null
is_active              | boolean                     | not null
expiration             | integer                     | 
expiration_unit        | character varying(255)      | 
frequency_count        | integer                     | 
matching_expression    | character varying(32672)    | 
data_vendor_uid        | character varying(255)      | not null
creation_date          | timestamp without time zone | not null default now()
researcher_uid         | character varying           | 
sharing_enabled        | boolean                     | not null default false
compressed_id          | integer                     | 
Indexes:
   "dx_segment_pkey" PRIMARY KEY, btree (object_uid)
Foreign-key constraints:
   "dx_segment_researcher_fk" FOREIGN KEY (researcher_uid) REFERENCES dt.table_researcher(object_uid)
   "fkeef87e8854520518" FOREIGN KEY (data_vendor_uid) REFERENCES dt.table_data_vendor(object_uid)
Referenced by:
   TABLE "dt.table_segment_hierarchy" CONSTRAINT "dx_segment_hierarchy_ancestor_segment_uid_fkey" FOREIGN KEY (ancestor_segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_segment_hierarchy" CONSTRAINT "dx_segment_hierarchy_descendant_segment_uid_fkey" FOREIGN KEY (descendant_segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_shared_organization_segments" CONSTRAINT "dx_shared_organization_segments_segment_uid_fkey" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_segment_external_id" CONSTRAINT "fk3f8c6d84c87bfc0" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_segment_group_rate" CONSTRAINT "fk710100c4a72a47f" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_segment_group_rate" CONSTRAINT "fk710100c4b8416291" FOREIGN KEY (group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_action" CONSTRAINT "fk7c000342a72a47f" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_action" CONSTRAINT "fk7c000342b7946789" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_segment_edge" CONSTRAINT "fk9c237d147cc05c6a" FOREIGN KEY (parent_segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_segment_edge" CONSTRAINT "fk9c237d14a102ddc" FOREIGN KEY (child_segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "dt.table_flight_group" CONSTRAINT "fkbeae4f48b8416291" FOREIGN KEY (group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_assets_load" CONSTRAINT "ls_assets_load_winning_group_uid_fkey" FOREIGN KEY (winning_group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_attributions_load" CONSTRAINT "ls_attributions_load_winning_group_uid_fkey" FOREIGN KEY (winning_group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_group_converters_load" CONSTRAINT "ls_group_converters_load_group_uid_fkey" FOREIGN KEY (group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_group_unique_users_load" CONSTRAINT "ls_group_unique_users_load_group_uid_fkey" FOREIGN KEY (group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_campaign_segment_load" CONSTRAINT "ls_campaign_segment_load_segment_uid_fkey" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_creative_exchange_hourly_load" CONSTRAINT "ls_creative_exchange_hourly_load_group_uid_fkey" FOREIGN KEY (group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_impressions_load" CONSTRAINT "ls_impressions_load_winning_group_uid_fkey" FOREIGN KEY (winning_group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_related_segment_load" CONSTRAINT "ls_related_segment_load_related_segment_uid_fkey" FOREIGN KEY (related_segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_related_segment_load" CONSTRAINT "ls_related_segment_load_segment_uid_fkey" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_segment_load" CONSTRAINT "ls_segment_load_segment_uid_fkey" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_top_interest_load_cant_modify" CONSTRAINT "ls_top_interest_load_segment_uid_fkey" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_top_interest_load" CONSTRAINT "ls_top_interest_load_segment_uid_fkey1" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_winning_segment_hourly_load" CONSTRAINT "ls_winning_segment_hourly_load_winning_group_uid_fkey" FOREIGN KEY (winning_group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_winning_segment_hourly_load" CONSTRAINT "ls_winning_segment_hourly_load_winning_segment_uid_fkey" FOREIGN KEY (winning_segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_winning_segment_list_segments" CONSTRAINT "ls_winning_segment_list_segments_segment_uid_fkey" FOREIGN KEY (segment_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_winning_segment_aggregate_data" CONSTRAINT "winning_segment_aggregate_group_fk" FOREIGN KEY (winning_group_uid) REFERENCES dt.table_segment(object_uid)
   TABLE "fb.ls_winning_segment_aggregate_data" CONSTRAINT "winning_segment_aggregate_segment_fk" FOREIGN KEY (winning_segment_uid) REFERENCES dt.table_segment(object_uid)

re 1:這是您在創建表時定義的預設值:

create table foo 
(
 id integer default 42,
 last_modified timestamp default now()
)

詳細資訊在手冊中:

re 2:可以在多個列上定義索引:

create table foo
(
 id_1 integer not null, 
 id_2 integer not null
);
create unique index on foo (id_1, id_2);

再次詳細資訊在手冊中:

引用自:https://dba.stackexchange.com/questions/58468