0

I have two databases and two apps. Initially they had same data. Later on, it has changed. Now I want to import some data from one database to another, but getting constraint restrictions. I thought I will just delete with sql command first from one, but then I get constrain restrictions again with multiple other tables.

Tables that I want to move are like this Manufacturers has many Systems has many Products. So let's say Apple has Iphone10 and Iphone11 systems, and each of them has many parts. And they were used in other parts of application like orders.

Fields of the tables are not exactly the same.

So how could I delete data from those three tables in one database, and then import new data?

*The app is not in production

davidism
  • 121,510
  • 29
  • 395
  • 339
Tomas Am
  • 433
  • 4
  • 13

1 Answers1

0

To delete all data from a table or set of tables, you can use the truncate command.

TRUNCATE othertable CASCADE;

This specific command will cascade the truncate to tables with a foreign key restraint.

https://www.postgresql.org/docs/current/sql-truncate.html

To import data, you can import from a CSV file

COPY zip_codes FROM '/path/to/csv/ZIP_CODES.txt' WITH (FORMAT csv);

How to import CSV file data into a PostgreSQL table?

David Weber
  • 154
  • 6