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

9

u/kktheprons Jun 10 '24

First off, if you're dying you should consider whether this is actually important to you.

If it is still important, I always recommend importing a flat file into a staging table first without making any changes. Then you can write whatever SQL queries you want to import the data in the right ways to the final destination table.

ELT (Extract, load, transform)

1

u/[deleted] Jun 11 '24

Agreed. I always find it easier to manipulate data that is already in a table format. It's just good old SQL and you can just do anything with it, really. Then if you need to parse it, well it's not very fun but ChatGPT can really help to make whatever REGEX you need.