Re: BUG #16300: Text line order corruption with COPY command - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #16300: Text line order corruption with COPY command
Date
Msg-id CAKFQuwZnzqUD2MapyvNO-dXknLRFp-o_x0FOTzpz+cEwrYjchg@mail.gmail.com
Whole thread Raw
In response to BUG #16300: Text line order corruption with COPY command  (PG Bug reporting form <noreply@postgresql.org>)
Responses AW: BUG #16300: Text line order corruption with COPY command  (Hans Buschmann <buschmann@nidsa.net>)
List pgsql-bugs
On Thu, Mar 12, 2020 at 1:05 PM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      16300
Logged by:          Hans Buschmann
Email address:      buschmann@nidsa.net
PostgreSQL version: 12.2
Operating system:   Windows Server 2019 64bit
Description:       

A reproducable line order corruption occurs when copying a quite large test
file into Postgres.


IIUC you copied data into PostgreSQL and then immediately read it out using SELECT without an ORDER BY and expected to get the same physical row order as the inserted data.  Nothing promises that things will work this way though often times they do.

If order matters to you you need to add an ORDER BY.  Since there is nothing natural to order by here you have to decide on how you want to change your setup.  I believe that adding a bigserial column to the table will result in the sequence generator applying numbers in strictly ascending order matching the input order and then you can sort on that column.  This is probably the simplest solution.  You can add row numbers to the source file just before importing it.  Or you can import the entire file to a text field and then split_to_array and rely upon that ordering.

David J.

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #16300: Text line order corruption with COPY command
Next
From: Hans Buschmann
Date:
Subject: AW: BUG #16300: Text line order corruption with COPY command