On Monday, February 4, 2019 at 12:04:17 PM UTC-8, Jason Landry wrote:
>
> If I do a something like this (using postgres):
>
> rows = [
> {name: 'Bob'},
> {name: 'Cathy'},
> {name: 'Steve'}
> ]
>
> results = Users.multi_insert(rows, return: :primary_key)
>
> => [1,2,3]
>
> Can I reliably count on the order of the ids returned being the same as
> the rows array that I've inserted?
>
I believe so, but that's not something that Sequel can guarantee as it
depends on the order postgres returns. I'm guessing it is unlikely
postgres would return values in a different order than the values given in
INSERT query.
If you want to be sure:
Hash[Users.returning(:name, :id).multi_insert([...].map{|x| [x[:name],
x[:id]])]
This does have postgres return all of the big strings, so it may be slower.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.