I am inserting records into a Postgresql table using the bulk insertion capability of SOCI C++ library. The data is passed to SOCI in std::vectors and the table contains an automatic counter of SERIAL type. I expected that the records will be inserted in the same order that they take in the vectors, but the counter is telling me that they seem to be inserted in the opposite order. Can anyone confirm this? Can I rely on this behavior or no order preservation is guaranteed? Is this up to SOCI or Postgresql?
Asked
Active
Viewed 120 times
0
-
Basically, you should not rely on order if there is no order. Typically all the records are inserted in a single transaction, and have the same "Date of Birth". Why do you want the sequences to be ordered? Don't you have a natural key? – wildplasser Oct 23 '20 at 10:23
-
The rows represent a time series. The order in which the records are stored in std::vectors must be preserved in the database, and the primary key of the table is the counter. If I cannot rely of the order being preserved, then I guess I'll have to insert into a temporary table which would also include a sequence number, sort by the sequence number, and finally insert into the main table. But that's allot of CPU time so it would be great if the preservation of order would be guaranteed in some way. – Dragan Vidovic Oct 23 '20 at 12:44
-
A time series without a timestamp or sequence-number is a bag of records. I repeat: there is no implicit order. – wildplasser Oct 23 '20 at 12:53