0

I am having trouble thinking of a way to copy three fields out of a database into and append them to another table along with the current date. Basically what I want to do is: DB-A: ID (N9), Name (C69), Phone (N15) {and a list of other fields I dont care about} DB-B: Date (Todays date/time), Nane, Address, Phone (as above)

Would be great is this was a trigger in the DB on add or update of DB-A.

Greg

3

1 Answer 1

0

Quick and dirty using 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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.