[pgsql-jp: 30756] Re: テーブルの継承について

sugita @ sra.co.jp sugita @ sra.co.jp
2003年 8月 12日 (火) 12:47:05 JST


  杉田です。

From: "Han yp" <Hanyp @ dhc.com.cn>
Subject: [pgsql-jp: 30754] Re: テーブルの継承について
Date: Tue, 12 Aug 2003 11:25:46 +0900

;;; 皆さん、こんにちは。
;;; 韓です。

  こんにちは。

;;; 「Triggers: srvc0_trg」とは私がせっかくDDLで作成したものではないから、
;;; このトリガーがどのように作るか、その詳細が何ですかという疑問が出来ることにな
;;; りました。
;;;
;;; また、先回にPostgreSQLのバージョンを言ったことはないで、
;;; すみません。
;;; 私が使用するPostgreSQLのバージョンが7.3.3です。
;;; 
;;; 下記のDDL文もご参照してください。
;;; 
;;; (1)service テーブルを作成するもの:
;;; create table service (
;;;  type  text  not null,
;;;  id   bigint,  -- service_id
;;;  name  text  not null,
;;;  apply_date date,
;;;  end_date date,
;;;  last_update timestamp,
;;;  constraint service_pk primary key (id, apply_date)
;;;  );
;;; (2)service テーブルを承継してservice_0 テーブルを作成するもの:
;;; create table service_0 (
;;;  target_service bigint
;;;  ) inherits (service);

  同じ PostgreSQL 7.3.3 で、上記の DDL を試すと以下のようになり、トリガーが出
ませんでした。

$ cat inherit.sql
select version();

-- (1)service テーブルを作成するもの:

drop table service_0;
drop table service;

create table service (
 type  text  not null,
 id   bigint,  -- service_id
 name  text  not null,
 apply_date date,
 end_date date,
 last_update timestamp,
 constraint service_pk primary key (id, apply_date)
 );

-- (2)service テーブルを承継してservice_0 テーブルを作成するもの:
create table service_0 (
 target_service bigint
 ) inherits (service);

\d service
\d service_0
$ psql -e -f inherit.sql
select version();
                            version                            
---------------------------------------------------------------
 PostgreSQL 7.3.3 on i686-pc-linux-gnu, compiled by GCC 2.95.3
(1 row)

drop table service_0;
DROP TABLE
drop table service;
DROP TABLE
create table service (
 type  text  not null,
 id   bigint,  
 name  text  not null,
 apply_date date,
 end_date date,
 last_update timestamp,
 constraint service_pk primary key (id, apply_date)
 );
psql:inherit.sql:16: NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'service_pk' for table 'service'
CREATE TABLE
create table service_0 (
 target_service bigint
 ) inherits (service);
CREATE TABLE
                Table "public.service"
   Column    |            Type             | Modifiers 
-------------+-----------------------------+-----------
 type        | text                        | not null
 id          | bigint                      | not null
 name        | text                        | not null
 apply_date  | date                        | not null
 end_date    | date                        | 
 last_update | timestamp without time zone | 
Indexes: service_pk primary key btree (id, apply_date)

                 Table "public.service_0"
     Column     |            Type             | Modifiers 
----------------+-----------------------------+-----------
 type           | text                        | not null
 id             | bigint                      | not null
 name           | text                        | not null
 apply_date     | date                        | not null
 end_date       | date                        | 
 last_update    | timestamp without time zone | 
 target_service | bigint                      | 

$ 


Kenji Sugita                                      



pgsql-jp メーリングリストの案内