A bulk insert would look more like:
my $rows = $pg->db->select(...)->arrays;
$pg->db->query('insert into b (first, last, birthday, age, phone) values '
. join(',', ('(?,?,?,?,?)')x@$results), @$results);

Or with postgres you could probably use arrays rather than constructing the
query with join and x but I wouldn't know how off the top of my head.

-Dan

On Fri, Feb 2, 2018 at 11:16 PM, Stefan Adams <s1037...@gmail.com> wrote:

>
>
> On Thu, Feb 1, 2018 at 6:42 AM, Sebastian Riedel <kra...@gmail.com> wrote:
>
>> > I spoke with you about this briefly on Twitter, but just figured I'd
>> put it
>> > out here, too.  What about multiple record inserts on a single call?
>> > Twitter thread.
>>
>> Yes, it's possible, not sure about how useful it would actually be though.
>>
>
> This makes sense!  I'm able to do this below, which is all that I really
> need:
>
>   *my $i = $pg->db->dbh->prepare*('insert into b (first, last, birthday,
> age, phone) values(?, ?, ?, ?, ?)');
>
>   my $results = $pg->db->select('a', [qw/first last birthday age phone/],
> undef, {limit => $limit, offset => 1});
>
>   while ( my $next = $results->array ) {
>
>     *$i->execute*(@$next);
>   }
>
> FWIW, I ran a quick benchmark
> <https://gist.github.com/s1037989/2caa12379b733c7467c634e83f3331a7> on 3
> different algorithms to insert bulk data into a database, and the method
> above was the fastest by far.  Is there a better / faster algorithm still
> to use for inserting bulk data?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to