From: | "George Weaver" <gweaver(at)shaw(dot)ca> |
---|---|
To: | "pgsql-general" <pgsql-general(at)postgresql(dot)org> |
Subject: | "Ungroup" data for import into PostgreSQL |
Date: | 2015-01-15 15:43:59 |
Message-ID: | 9B2E37F79FAD4A53BF0D51E73E596B82@D420 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi List,
I need to import data from a large Excel spreadsheet into a PostgreSQL
table. I have a program that uses ODBC to connect to Excel and extract data
using SQL queries. The program then inserts the data into a PostgreSQL
table.
The challenge with this particular spreadsheet is that it is arrayed thus:
Model No 1 Product Code 15
Serial No 1 No on Hand
Serial No 2 No on Hand
Serial No 3 No on Hand
Model No 4 Product Code 9
Serial No 12 No on Hand
Model No 5 Product Code 27
Serial No 6 No on Hand
Serial No 14 No on Hand
etc.
I need the data in PostgreSQL arrayed thus
Model No 1 Product Code 15 Serial No 1 No on Hand
Model No 1 Product Code 15 Serial No 2 No on Hand
Model No 1 Product Code 15 Serial No 3 No on Hand
Model No 4 Product Code 9 Serial No 12 No on Hand
Model No 5 Product Code 27 Serial No 6 No on Hand
Model No 5 Product Code 27 Serial No 14 No on Hand
I can import the data procedurely using plpgsql to match the individual rows
to the master for each row (import the raw data into a buffer table in
PostgreSQL and then looping through the rows in the buffer table and
checking to see when the Model No changes).
I'm wondering if there is a more elegant way to do this using straight sql
from Excel?
Thanks for your help/suggestions!
George
From | Date | Subject | |
---|---|---|---|
Next Message | sambsa | 2015-01-15 16:07:38 | pgagent jobs Could not connect to the database ! |
Previous Message | Adrian Klaver | 2015-01-15 15:05:01 | Re: can you have any idea about toast missing chunk issu resolution |