Re: Regarding Copy in postgresql

From: Daniel Staal <DStaal(at)usa(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Regarding Copy in postgresql
Date: 2012-03-22 05:20:40
Message-ID: F3C83582DA2551E2A6A094A0@mac-pro.magehandbook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

--As of March 22, 2012 9:56:37 AM +0530, sreeaurovindh viswanathan is
alleged to have said:

> I have a text file which has about 140 million records spaced by tab.I
> am trying it to read and put it into database.I have used Copy to do
> it.For the delimiter i tried with \t but it did not work.Hence i
> copied the tab space and pasted it in copy command and then it
> executed.Does the copy command read the file sequentially.Atleast from
> the ordering that i got it doesn't seem so.. If that is the case how
> is the orderering of read..

--As for the rest, it is mine.

The copy itself should read the file sequentially, I think. (I can't think
of a single good reason not to do so from a programming standpoint.)
However a 'select' to pull the data back out of the database is inherently
unordered; it's order will have no relation (except by chance) to the order
the data was put into the database.

If you need to know if all of the data in the text file were loaded, it
would be best to either count the records inserted, or select the last
record and see if it was loaded. If you need a more predictable way to
find which was the last record read, you will either need to use the count
(again), or to find some ordering in the text file that you can use in an
'order by' clause. (If you are are on a Unix-like platform, it may be
worth feeding your text file through `sort` just for this purpose.)

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message VARTAK, SATISH CTR DFAS 2012-03-22 13:54:09 SQL odbc driver for Windows 7 (64 bit) - database Postgres version 8.3
Previous Message sreeaurovindh viswanathan 2012-03-22 04:26:37 Regarding Copy in postgresql