Re: Load data from a csv file without using COPY

From: Tim Cross <theophilusx(at)gmail(dot)com>
To: Ravi Krishna <srkrishna(at)yahoo(dot)com>
Cc: PG mailing List <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Load data from a csv file without using COPY
Date: 2018-06-19 21:59:10
Message-ID: 87602esaj5.fsf@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Ravi Krishna <srkrishna(at)yahoo(dot)com> writes:

> In order to test a real life scenario (and use it for benchmarking) I want to load large number of data from csv files.
> The requirement is that the load should happen like an application writing to the database ( that is, no COPY command).
> Is there a tool which can do the job. Basically parse the csv file and insert it to the database row by row.
>

Not clear what you mean by 'real world scenario', but you could possibly
use PG's foreign table support and define a csv file as a foreign table
and then have scripts which read from there and do whatever
insert/update etc you need. However, this has a high level of 'fakery'
going on and probably not testing what you really want.

There are lots of ways that applications write to the database -
different drivers (e.g. jdbc, odbc, pg etc), different commit
and transaction strategies and even different ways to handle things like
an update or insert process. You can even use streams and copy from an
application.

To get 'real world' equivalence, you really need to use the same
interface as the application you are comparing. Most languages have
support for processing CSV files, so you may be better off writing a
small 'wrapper' app which uses the same drivers and assuming your
database connectivity has been abstracted into some sort of
module/library/class, use the same interface to write to the database
that the application uses.

Tim
--
Tim Cross

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Asif Ali 2018-06-19 22:06:35 Re: Load data from a csv file without using COPY
Previous Message David G. Johnston 2018-06-19 21:32:10 Re: Load data from a csv file without using COPY