Overwriting text file data in to Postgres table
Consider I have a text file in the location 'D:\Users\test.txt' and I need to update/insert these data into postgres table dbo.Test.
My text file has two column ID and Location with '|' delimiter.
CREATE TEMPORARY TABLE t_test as SELECT * FROM dbo."Test" LIMIT 0;
COPY t_test ("ID","Location") from 'D:\Users\test.txt' WITH DELIMITER '|' CSV HEADER;
SELECT "ID" from t_test;
BEGIN TRANSACTION;
DELETE FROM dbo."Test"
WHERE "ID" IN
(
SELECT "ID"
FROM t_test
);
INSERT INTO dbo."Test"
SELECT "ID", "Location"
FROM t_test;
COMMIT TRANSACTION;
Consider I have a text file in the location 'D:\Users\test.txt' and I need to update/insert these data into postgres table dbo.Test.
My text file has two column ID and Location with '|' delimiter.
CREATE TEMPORARY TABLE t_test as SELECT * FROM dbo."Test" LIMIT 0;
COPY t_test ("ID","Location") from 'D:\Users\test.txt' WITH DELIMITER '|' CSV HEADER;
SELECT "ID" from t_test;
BEGIN TRANSACTION;
DELETE FROM dbo."Test"
WHERE "ID" IN
(
SELECT "ID"
FROM t_test
);
INSERT INTO dbo."Test"
SELECT "ID", "Location"
FROM t_test;
COMMIT TRANSACTION;