Let's say I have 2 tables: Students and Groups.
- The Group table has 2 columns: id, GroupName
- The Student table has 3 columns: id, StudentName and GroupID
- The GroupID is a foreign key to a Group field.
I need to import the Students table from a CSV, but in my CSV instead of the Group id appears the name of the group. How can I import it with pgAdmin without modifying the csv?
Your easiest option is to import the file into a temporary table that is defined like the CSV file. Then you can join that table with the "groups" table and use
INSERT INTO ... SELECT ...to populate the "students" table.There is of course also the option to define a view on a join of the two tables and define an
INSTEAD OF INSERTtrigger on the view that inserts values into the underlying tables as appropriate. Then you could load the data directly to the view.