postgresql - Building a CSV file to import into sql, how to handle relationships? -
i have large set of data each row in table point lot of rows in table b. in generating csv file, need somehow show relation, don't have integer based pkey. each of items in have unique username, , same goes table b (that is, table b has own unique set of names).
i working python , postgres if matters. note, both tables 50-100m+ rows long, 8 columns each.
is there strategy building out csv file?
you each row has unique name. if unique can use them keys tables. don't need integer-based keys.
for example, path file can considered unique identifier (for files in same directory/repository.) file's key.
- advantages: easier import. references file human readable.
- disadvantages: each reference file uses more database space integer key. if file renamed looks new file; name can't change without changing key. (although, there workarounds.)
the import easier without assigning unique integer keys. suggest import first, optionally add integer keys afterwards.
import: put data in csv files, 1 file per table. import them destination database in correct order. (if understand structure correctly first 1 repository table, commits , changes both refer it.)
adding integer keys existing tables: add autonumbering column each table needs integer key. each parent row has it's original unique name , integer id. can use sql commands replace each parent name in child table it's respective internal key, drop name columns once no longer needed.
Comments
Post a Comment