不确定在规则中使用 dblink 的想法(未测试)。但是你有一个关闭)
太多:
CREATE OR REPLACE RULE INSERT_part_name AS
ON INSERT TO partition.part_name
DO INSTEAD SELECT crm.dblink_exec('crm_server'::text,
'insert into partition.part_name(customerid, partition_name, partition, createdate)
values(' || new.customerid || ',' || quote_literal(new.partition_name) || ',false'
|| ',' || quote_literal(new.createdate::timestamp without time zone));
不过,我会使用format()
更简洁的代码(需要 Postgres 9.1+):
CREATE OR REPLACE RULE INSERT_part_name AS
ON INSERT TO partition.part_name
DO INSTEAD SELECT crm.dblink_exec('crm_server'::text, format(
'INSERT INTO partition.part_name(customerid, partition_name, partition, createdate)
VALUES(%s, %L, false, %L)'
,NEW.customerid, NEW.partition_name, NEW.createdate::timestamp));