.\" This is -*-nroff-*- .\" XXX standard disclaimer belongs here.... .\" $Header: /usr/local/cvsroot/pgsql/src/man/create_rule.l,v 1.6 1998/04/07 18:12:53 momjian Exp $ .\" Translated by Mitsuhiro Maeda (mitsu@cni.co.jp) .TH "CREATE RULE" SQL 11/05/95 日本語PostgreSQL 日本語PostgreSQL .SH 名称 .\" create rule - define a new rule create rule - 新規のルールを定義します .SH 形式 .nf \fBcreate\fR \fBrule\fR rule_name \fBas\fR \fBon\fR event \fBto\fR object [\fBwhere\fR clause] \fBdo\fR [\fBinstead\fR] [action | nothing | \fB[\fPactions...\fB]\fP] .fi .SH 説明 .PP .\" .BR "Create rule" .\" is used to define a new rule. .BR "create rule" は新しいルールを定義するのに使います。 .PP .\" Here, .\" .IR event .\" is one of .\" .IR select , .\" .IR update , .\" .IR delete .\" or .\" .IR insert . ここで、 .IR event は .IR select 、 .IR update 、 .IR delete 、 .IR insert の内のどれかになります。 .\" .IR Object .\" is either: .\" .nf .\" a class name .\" \fIor\fR .\" class.column .\" .fi .IR objectはクラス名もしくは、 クラス.カラム(class.column)になります。 .\" The .\" .BR "from" .\" clause, the .\" .BR "where" .\" clause, and the .\" .IR action .\" are respectively normal SQL .\" .BR "from" .\" clauses, .\" .BR "where" .\" clauses and collections of SQL commands with the following change: .BR "from" 句、 .BR "where" 句と、 .IR action はそれぞれ通常の SQL の .BR "from" 句、 .BR "where" 句、 そして、次のような違いのある SQL コマンド群です。 .\" .IP .\" .BR new .\" or .\" .BR current .\" can appear instead of .\" an instance variable whenever an instance .\" variable is permissible in SQL. .IP SQL の中でインスタンス変数が許される時にはいつでも .BR new もしくは .BR current をその代わりに使うことができます。 .PP .\" The semantics of a rule is that at the time an individual instance is .\" accessed, updated, inserted or deleted, there is a .\" .BR current .\" instance .\" (for retrieves, updates and deletes) and a .\" .BR new .\" instance (for updates and appends). ルールのセマンティックでは、 個々のインスタンスがアクセス、更新、挿入、削除をされた時に、 .BR current インスタンス(検索、更新、削除の時)と .BR new インスタンス(更新と追加の時)が存在します。 .\" If the event specified in the .\" .BR "on" .\" clause and the condition specified in the .\" .BR "where" .\" clause are true for the current instance, then the .\" .IR action .\" part of the rule is executed. もしイベントが .BR "on" 句で指定されて、現在のインスタンスに対して .BR "where" 句で指定された条件が真であれば、 ルールの .IR action のパートが実行されます。 .\" First, however, values from fields in .\" the current instance and/or the new instance are substituted for: しかしながらまず、 現在のインスタンスまたあるいは新しいインスタンスのフィールド値は .nf current.attribute-name new.attribute-name .fi として置き換えられます。 .\" The .\" .IR action .\" part of the rule executes with same command and transaction identifier .\" as the user command that caused activation. ルールの .IR action のパートは、 動作するユーザコマンドと同様のコマンドとトランザクション識別子を使って実行します。 .PP .\" A note of caution about SQL rules is in order. SQL ルールの注意箇所は順番です。 .\" If the same class .\" name or instance variable appears in the event, .\" .BR where .\" clause and the .\" .IR action .\" parts of a rule, they are all considered different tuple variables. もし同じクラス名やインスタンス変数が イベント、 .BR where 句と、ルールの .IR action パートの中に現れると、すべて違うタプルの変数として扱われます。 .\" More accurately, .\" .BR new .\" and .\" .BR current .\" are the only tuple variables that are shared between these clauses. もっと正確に言えば、 .BR new と .BR current はのみがこれらの句の中で共有することのできるタプル変数となります。 .\" For example, the following two rules have the same semantics: 例えば、次の2つのルールは同じセマンティックを持ちます: .nf on update to EMP.salary where EMP.name = "Joe" do update EMP ( ... ) where ... on update to EMP-1.salary where EMP-2.name = "Joe" do update EMP-3 ( ... ) where ... .fi .\" Each rule can have the optional tag .\" .BR "instead" . 各々のルールはオプションのタグとして .BR "instead" を付けることができます。 .\" Without this tag .\" .IR action .\" will be performed in addition to the user command when the event in .\" the condition part of the rule occurs. このタグが無ければ、 ルールの条件パートにイベントが起こった時に、 .IR action はユーザコマンドに追加する形で実行されます。 .\" Alternately, the .\" .IR action .\" part will be done instead of the user command. 他方では、 .IR action パートはユーザコマンドの代わりに実行されます。 .\" In this later case, the action can be the keyword .\" .BR nothing . 後者のケースでは、 アクションはキーワード .BR nothing とすることができます。 .PP .\" When choosing between the rewrite and instance rule systems for a .\" particular rule application, remember that in the rewrite system .\" .BR current .\" refers to a relation and some qualifiers whereas in the instance .\" system it refers to an instance (tuple). あるルールアプリケーションのために リライトとインスタンスルールシステムのどちらかを選ぶ時に、 リライトシステムでは .BR current はリレーションと制限句を参照し、 インスタンスシステムではインスタンス(タプル)を参照することを 覚えておいてください。 .PP .\" It is very important to note that the .\" .BR rewrite .\" rule system will .\" neither detect nor process circular .\" rules. .BR リライト ルールシステムでは循環ルールを発見あるいは処理できまないことに 注意することは重要です。 .\" For example, though each of the following two rule .\" definitions are accepted by Postgres, the .\" .IR retrieve .\" command will cause .\" Postgres to .\" .IR crash : 例えば、次の2つのルール定義はそれぞれ Postgres に受け入れられますが、 .IR 検索 コマンドは Postgres を .IR クラッシュ させます: .nf -- .\" --Example of a circular rewrite rule combination. -- 循環リライトルールの組合せの例 -- create rule bad_rule_combination_1 is on select to EMP do instead select to TOYEMP create rule bad_rule_combination_2 is on select to TOYEMP do instead select to EMP -- .\" --This attempt to retrieve from EMP will cause Postgres to crash. -- この EMP からの検索の試行は Postgres をクラッシュさせます -- select * from EMP .fi .PP .\" You must have .\" .IR "rule definition" .\" access to a class in order to define a rule on it (see .\" .IR "change acl" (l). ルールを定義するには、 .IR "ルール定義" 権限( .IR "rule definition" )を持ってなくてはなりません。 ( .IR "change acl" (l) を参照してください。) .SH 例 .nf -- .\" --Make Sam get the same salary adjustment as Joe -- Sam の給料を Joe と同じに調整します -- create rule example_1 is on update EMP.salary where current.name = "Joe" do update EMP (salary = new.salary) where EMP.name = "Sam" .fi .\" At the time Joe receives a salary adjustment, the event will become .\" true and Joe's current instance and proposed new instance are available .\" to the execution routines. Joe が給料の調整を受け取った時、 イベントが真になり、Joe の現在のインスタンスと提案された新規インスタンスが 実行ルーチンに提供されます。 .\" Hence, his new salary is substituted into the .\" .IR action .\" part of the rule which is subsequently executed. ですから、彼の新しい給料は その後に実行されるルールの .IR action パートに渡されます。 .\" This propagates .\" Joe's salary on to Sam. これは Joe の給料を Sam に伝えます。 .nf -- .\" --Make Bill get Joe's salary when it is accessed -- Joe の給料にアクセスされた時に Bill が受け取るようにします -- create rule example_2 is on select to EMP.salary where current.name = "Bill" do instead select (EMP.salary) from EMP where EMP.name = "Joe" .fi .nf -- .\" --Deny Joe access to the salary of employees in the shoe .\" --department. (pg_username() returns the name of the current user) -- Joe が 靴売場の従業員の給料にアクセスすることを禁止します -- (pg_username() は現在のユーザ名を返します) -- create rule example_3 is on select to EMP.salary where current.dept = "shoe" and pg_username() = "Joe" do instead nothing .fi .nf -- .\" --Create a view of the employees working in the toy department. -- 玩具売場で働く従業員の VIEW表を作ります -- create TOYEMP(name = char16, salary = int4) create rule example_4 is on select to TOYEMP do instead select (EMP.name, EMP.salary) from EMP where EMP.dept = "toy" .fi .nf -- .\" --All new employees must make 5,000 or less -- 新人従業員はすべて 5,000 以下の給料とします -- create rule example_5 is on insert to EMP where new.salary > 5000 do update newset salary = 5000 .fi .SH 参照 drop rule(l), create view(l). .SH バグ .PP .\" .BR "instead" .\" rules do not work properly. .BR "instead" ルールは適切に動きません。 .PP .\" The object in a SQL rule cannot be an array reference and cannot .\" have parameters. SQL ルールのオブジェクトは配列参照にはできません。 またパラメータを持つこともできません。 .PP .\" Aside from the \*(lqoid\*(rq field, system attributes cannot be .\" referenced anywhere in a rule. \*(lqoid\*(rqフィールドは別として、 システム属性はルールから参照することはできません。 .\" Among other things, this means that .\" functions of instances (e.g., \*(lqfoo(emp)\*(rq where \*(lqemp\*(rq .\" is a class) cannot be called anywhere in a rule. 別のところでは、これは関数のインスタンス(例えば \*(lqfoo(emp)\*(rq where \*(lqemp\*(rq はクラスです)はルールの中から呼び出すことができません。 .PP .\" The rule system store the rule text and query plans as text .\" attributes. ルールシステムはルール文と問い合わせプランをテキスト属性として保存します。 .\" This implies that creation of rules may fail if the .\" rule plus its various internal representations exceed some value .\" that is on the order of one page (8KB). これはルールを作るときに ルールとそれに付随する内部表現が 1ページ (8KB) を越えると 失敗することを意味します。