Psycopg2 - COPY_FROM does not maintain row order
That is normal and is to be expected. PostgreSQL inserts the rows wherever it finds room in the table, and when you query the table without ORDER BY, you won't necessarily always get the rows in the same order.
If you want your rows ordered, query them with an ORDER BY clause.
I have a CSV file having 100000 rows. COPY_FROM() successfully inserted all the rows into the database table within seconds. But the row order found in database table is not similar to the row order found in the CSV file. Some of the rows in between seems to be shuffled. Did not find any solutions. Please help me out.
CSV file

R1
R2
R3
R4

PG table

R1
R3
R2
R4