pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Import csv to temp table
7+ messages / 6 participants
[nested] [flat]

* Import csv to temp table
@ 2024-01-02 12:02 arun chirappurath <arunsnmimt@gmail.com>
  2024-01-02 13:49 ` Re: Import csv to temp table Ron Johnson <ronljohnsonjr@gmail.com>
  2024-01-02 14:51 ` Re: Import csv to temp table Daniel Verite <daniel@manitou-mail.org>
  0 siblings, 2 replies; 7+ messages in thread

From: arun chirappurath @ 2024-01-02 12:02 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Dear All,

Do we have any scripts that create a temp table with column names from the
first row of csv files?

any functions which we can pass the file name as parameter which loads the
data to csv based on the data

Thanks,
ACDBA

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Import csv to temp table
  2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
@ 2024-01-02 13:49 ` Ron Johnson <ronljohnsonjr@gmail.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Ron Johnson @ 2024-01-02 13:49 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Tue, Jan 2, 2024 at 7:02 AM arun chirappurath <arunsnmimt@gmail.com>
wrote:

> Dear All,
>
> Do we have any scripts that create a temp table with column names from the
> first row of csv files?
>

How would you determine the data type?

If you assume TEXT for all of them, then it's relatively simple to write
bash which does it.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Import csv to temp table
  2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
@ 2024-01-02 14:51 ` Daniel Verite <daniel@manitou-mail.org>
  2024-01-02 16:06   ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Daniel Verite @ 2024-01-02 14:51 UTC (permalink / raw)
  To: arun chirappurath <arunsnmimt@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

	arun chirappurath wrote:

> Do we have any scripts that create a temp table with column names
> from the first row of csv files?

csvkit [1] does that.

[1] https://csvkit.readthedocs.io/en/latest/


Best regards,
-- 
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Import csv to temp table
  2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
  2024-01-02 14:51 ` Re: Import csv to temp table Daniel Verite <daniel@manitou-mail.org>
@ 2024-01-02 16:06   ` Adrian Klaver <adrian.klaver@aklaver.com>
  2024-01-02 20:16     ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2024-01-02 16:06 UTC (permalink / raw)
  To: Daniel Verite <daniel@manitou-mail.org>; arun chirappurath <arunsnmimt@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

On 1/2/24 06:51, Daniel Verite wrote:
> 	arun chirappurath wrote:
> 
>> Do we have any scripts that create a temp table with column names
>> from the first row of csv files?
> 
> csvkit [1] does that.
> 
> [1] https://csvkit.readthedocs.io/en/latest/

In addition to the above which I have used you might want to take a look at:

Polars
https://pola.rs/

and

Duckdb
https://duckdb.org/

They both allow you to query CSV(and other format) files directly. I 
have found them very useful for looking at CSV files and you can 
transfer data elsewhere later.

Then there is:

Pandas
https://pandas.pydata.org/pandas-docs/stable/index.html

which has 
read_csv(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) 
and 
to_sql(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html#pandas.DataF...) 
to pull from a CSV into a table.


> 
> 
> Best regards,

-- 
Adrian Klaver
adrian.klaver@aklaver.com






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Import csv to temp table
  2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
  2024-01-02 14:51 ` Re: Import csv to temp table Daniel Verite <daniel@manitou-mail.org>
  2024-01-02 16:06   ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
@ 2024-01-02 20:16     ` Adrian Klaver <adrian.klaver@aklaver.com>
  2024-01-05 05:44       ` Re: Import csv to temp table Paolo Saudin <paolosaudin@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2024-01-02 20:16 UTC (permalink / raw)
  To: arun chirappurath <arunsnmimt@gmail.com>; +Cc: pgsql-general

On 1/2/24 11:47, arun chirappurath wrote:

Reply to list
Ccing list
> Hi Adrian,
> 
> Love this tool..however it doesn't like supporting RDS.

1) This was Daniel Vérité's suggestion not mine.

2) Define "... doesn't like supporting RDS".

a) You can generate an SQL statement without connecting to the database.
Then use that statement directly in the database.

b) If SQLAlchemy can reach the database then csvkit should be able to.

> 
> https://csvkit.readthedocs.io/en/latest/ 
> <https://csvkit.readthedocs.io/en/latest/;
> 
> Regards
> Arun
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Import csv to temp table
  2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
  2024-01-02 14:51 ` Re: Import csv to temp table Daniel Verite <daniel@manitou-mail.org>
  2024-01-02 16:06   ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
  2024-01-02 20:16     ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
@ 2024-01-05 05:44       ` Paolo Saudin <paolosaudin@gmail.com>
  2024-01-05 06:02         ` Re: Import csv to temp table Ryan Kelly <rpkelly22@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Paolo Saudin @ 2024-01-05 05:44 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: arun chirappurath <arunsnmimt@gmail.com>; pgsql-general

Il giorno mar 2 gen 2024 alle ore 21:17 Adrian Klaver <
adrian.klaver@aklaver.com> ha scritto:

> On 1/2/24 11:47, arun chirappurath wrote:
>
> Reply to list
> Ccing list
> > Hi Adrian,
> >
> > Love this tool..however it doesn't like supporting RDS.
>
> 1) This was Daniel Vérité's suggestion not mine.
>
> 2) Define "... doesn't like supporting RDS".
>
> a) You can generate an SQL statement without connecting to the database.
> Then use that statement directly in the database.
>
> b) If SQLAlchemy can reach the database then csvkit should be able to.
>
> >
> > https://csvkit.readthedocs.io/en/latest/
> > <https://csvkit.readthedocs.io/en/latest/;
> >
> > Regards
> > Arun
> >
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
>
>
You can user pgloader (https://pgloader.io/) as well to load data from CSV
to Postgres
Paolo

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Import csv to temp table
  2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
  2024-01-02 14:51 ` Re: Import csv to temp table Daniel Verite <daniel@manitou-mail.org>
  2024-01-02 16:06   ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
  2024-01-02 20:16     ` Re: Import csv to temp table Adrian Klaver <adrian.klaver@aklaver.com>
  2024-01-05 05:44       ` Re: Import csv to temp table Paolo Saudin <paolosaudin@gmail.com>
@ 2024-01-05 06:02         ` Ryan Kelly <rpkelly22@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Ryan Kelly @ 2024-01-05 06:02 UTC (permalink / raw)
  To: Paolo Saudin <paolosaudin@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; arun chirappurath <arunsnmimt@gmail.com>; pgsql-general

I use csv2table almost every day: https://github.com/f0rk/csv2table

to just emit a create table statement: csv2table --file your_csv.csv

pipe output to psql to create.

easily used to import data as: csv2table --file your_csv.csv --copy
--backslash -1 | psql your_database

use arguments like --timestamp to automagically detect types.

On Fri, Jan 5, 2024 at 12:45 AM Paolo Saudin <paolosaudin@gmail.com> wrote:

> Il giorno mar 2 gen 2024 alle ore 21:17 Adrian Klaver <
> adrian.klaver@aklaver.com> ha scritto:
>
>> On 1/2/24 11:47, arun chirappurath wrote:
>>
>> Reply to list
>> Ccing list
>> > Hi Adrian,
>> >
>> > Love this tool..however it doesn't like supporting RDS.
>>
>> 1) This was Daniel Vérité's suggestion not mine.
>>
>> 2) Define "... doesn't like supporting RDS".
>>
>> a) You can generate an SQL statement without connecting to the database.
>> Then use that statement directly in the database.
>>
>> b) If SQLAlchemy can reach the database then csvkit should be able to.
>>
>> >
>> > https://csvkit.readthedocs.io/en/latest/
>> > <https://csvkit.readthedocs.io/en/latest/;
>> >
>> > Regards
>> > Arun
>> >
>>
>>
>> --
>> Adrian Klaver
>> adrian.klaver@aklaver.com
>>
>>
>>
> You can user pgloader (https://pgloader.io/) as well to load data from
> CSV to Postgres
> Paolo
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2024-01-05 06:02 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-01-02 12:02 Import csv to temp table arun chirappurath <arunsnmimt@gmail.com>
2024-01-02 13:49 ` Ron Johnson <ronljohnsonjr@gmail.com>
2024-01-02 14:51 ` Daniel Verite <daniel@manitou-mail.org>
2024-01-02 16:06   ` Adrian Klaver <adrian.klaver@aklaver.com>
2024-01-02 20:16     ` Adrian Klaver <adrian.klaver@aklaver.com>
2024-01-05 05:44       ` Paolo Saudin <paolosaudin@gmail.com>
2024-01-05 06:02         ` Ryan Kelly <rpkelly22@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox