关于邮政总局的8.1(或以后)分门别类表格,如果<代码>,则如何界定<编码>>UPDATE的触发和程序,将记录从一个部分移至另一个部分。 UPDATE系指对界定隔离的有限领域作出改变?
例如,我印发一份表格记录,分为积极和被动的记录,如:
create table RECORDS (RECORD varchar(64) not null, ACTIVE boolean default true);
create table ACTIVE_RECORDS ( check (ACTIVE) ) inherits RECORDS;
create table INACTIVE_RECORDS ( check (not ACTIVE) ) inherits RECORDS;
3. 夸大规格和错误信息:
pg=> CREATE OR REPLACE FUNCTION record_update()
RETURNS TRIGGER AS $$
BEGIN
IF (NEW.active = OLD.active) THEN
RETURN NEW;
ELSIF (NEW.active) THEN
INSERT INTO active_records VALUES (NEW.*);
DELETE FROM inactive_records WHERE record = NEW.record;
ELSE
INSERT INTO inactive_records VALUES (NEW.*);
DELETE FROM active_records WHERE record = NEW.record;
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
pg=> CREATE TRIGGER record_update_trigger
BEFORE UPDATE ON records
FOR EACH ROW EXECUTE PROCEDURE record_update();
pg=> select * from RECORDS;
record | active
--------+--------
foo | t -- foo record actually in table ACTIVE_RECORDS
bar | f -- bar record actually in table INACTIVE_RECORDS
(2 rows)
pg=> update RECORDS set ACTIVE = false where RECORD = foo ;
ERROR: new row for relation "active_records" violates check constraint "active_records_active_check"
采用触发程序(恢复民族解放军,等等)向我建议,在援引我的触发因素之前,必须检查制约因素,并查明错误,这意味着我目前的做法赢得了一定的工作。 这样做能够奏效?
pg s [list partitioning <>/em>] ***
-- untested!
create table RECORDS (..., ACTIVE boolean...)
partition by list(ACTIVE) (
partition ACTIVE_RECORDS values (true),
partition INACTIVE_RECORDS values (false)
)
http://www.ohchr.org。
以下为<编码>UPDATE触发程序。 我最后采用分配给各分区的相同程序。 信贷完全是Bell,其答案使我对触发分部分分配的关键见解:
CREATE OR REPLACE FUNCTION record_update()
RETURNS TRIGGER AS $$
BEGIN
IF ( (TG_TABLE_NAME = active_records AND NOT NEW.active)
OR
(TG_TABLE_NAME = inactive_records AND NEW.active) ) THEN
DELETE FROM records WHERE record = NEW.record;
INSERT INTO records VALUES (NEW.*);
RETURN NULL;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;