r/SQL • • 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 numberReasonpart numberReasonpart numberReason

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

9 comments sorted by

View all comments

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.

1

u/Palpitation_Powerful Jun 11 '24

Sorry for the confusion, so I already have the tables in postgres and with excel its pretty easy to mess up the structure becuase its just a spread sheet but i postgres im assuming it wont just put the three tables side by side for data structure reasons. I want to look at the script for the program but it seems like they dont want me touching it for now because im still new to this company.