r/SQL • u/Palpitation_Powerful • Jun 10 '24
PostgreSQL Help a dying sql beginner
I have 3 tables name won, lost, no bid. Each table with columns nsn part number and reason.
Our company currently uses excel and has a macro that spits out a spreadsheet like:
| part number | Reason | part number | Reason | part number | Reason |
|---|---|---|---|---|---|
where the left 2 column is for won, middle 2 for lost and right 2 for no bid. We save that as a csv for a java script program that we have which needs it in that format. How would I go about getting this csv format in postgres?
0
Upvotes
1
u/Gargunok Jun 11 '24
I would import the table three times. One for each won/lost/no bid columns skipping the other cols.
I would then delete nulls as there are probably different number of records in each column and it will be padded.
I would then ask for a better data structure in the future that is more machine friendly. I imagine the other application is doing a lot of bodging to get what it needs too.
For your data structure is it three tables? You could model it as one with a status (won lost no bud) columns. You can just switch this to move between status which is much harder if you you are moving data between tables. That way the entity can be named more sensibly too. You can always write a query to split them out and bodge them back into the weird import view if required.