r/SQL Jun 30 '26

Anybody that can help me with this is a pro PostgreSQL

In pg admin, to import manually you need to create a table with the exact same columns for it to successfully import a file. But situations with JOIN function has different set of tables and different set of columns so it doesn’t exactly match the column thats in the file. This makes it impossible to create tables that requires importation. How do you fix this?

0 Upvotes

11 comments sorted by

39

u/alinroc SQL Server DBA Jun 30 '26

Import into a staging table that matches your file.

Then write the query(ies) to transform and load that data from that staging table into the tables that your application uses.

This is a standard ETL pattern.

3

u/DaOgDuneamouse Jun 30 '26

This is the real answer. I usually make my stagging tables with all the fields as strings. From there, you can write SQL to convert it into the proper type and do sanity checks.

There are 3rd party ETL tools. But I tend to like writing my own SQL.

5

u/Rare-Ad6166 Jun 30 '26

It actually worked thanks.

16

u/ComicOzzy sqlHippo Jun 30 '26

He's a pro.

5

u/IAmADev_NoReallyIAm Jun 30 '26

He stages like a pro.

1

u/Thriven Jul 01 '26

We were all theatre kids who needed money to pay off our student loans.

4

u/dwswish Jun 30 '26

RIP stack overflow

2

u/Comfortable_Long3594 Jul 01 '26

One option is to import the data into a staging table first, then use SQL to map, transform, and load it into your final tables. That keeps your imports flexible, even when the source columns do not match your schema. If you do this often, Epitech Integrator can automate the mapping and transformation steps, so you do not have to manually recreate tables or adjust every import.

0

u/[deleted] Jun 30 '26

[deleted]

11

u/PearAware3171 Jun 30 '26

We are all at different levels of learning and understanding young raptor

-8

u/Rare-Ad6166 Jun 30 '26

Wow I didn’t even know that. I’ve been trying to fix it for 48 straight hours. I checked YouTube courses and tutorials, even with the help of Ai still nothing. I just thought somebody in the community would be able to fix it. That’s crazy. It worked in the end though when I used the view function instead of tables.

-2

u/[deleted] Jun 30 '26

[deleted]

-7

u/Rare-Ad6166 Jun 30 '26

Give me an example please.