我无法想办法将数据库中的三个字段复制到另一个表中并将其与当前日期一起附加到另一个表中。基本上我想做的是: DB-A:ID(N9),姓名(C69),电话(N15){以及我不关心的其他字段列表} DB-B:日期(今天的日期/时间),Nane,地址,电话(如上所述)
在添加或更新DB-A时,这是DB的触发器。
格雷格
答案 0 :(得分:0)
使用postgres_fdw
CREATE EXTENSION IF NOT EXISTS postgres_fdw ;
CREATE SERVER extern_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foreignserver.co.uk', port '5432', dbname 'mydb');
CREATE USER MAPPING FOR myuser SERVER extern_server OPTIONS (user 'anotheruser');
-- Creating a foreign table based on table t1 at the server described above
CREATE FOREIGN TABLE foreign_t1 (
dba INT,
name VARCHAR(9),
phone VARCHAR(15)
)
SERVER extern_server OPTIONS (schema_name 'public', table_name 't1');
--Inserting data to a new table + date
INSERT INTO t2 SELECT dba,name,phone,CURRENT_DATE FROM foreign_t1;
-- Or just retrieving what you need placing the current date as a column
SELECT dba,name,phone,CURRENT_DATE FROM foreign_t1;