in reply to Re: Select DB data into CSV file
in thread Select DB data into CSV file

Sorry, sloppy writing. I meant this:

# using the csv function, all in memory csv (out => "foo.csv", in => $dbh->selectall_arrayref ($sql));


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^3: Select DB data into CSV file
by Tux (Canon) on Dec 20, 2018 at 13:14 UTC

    This is fine until your table outgrows your memory: selectall_arrayref will read all rows into memory and then pass it to csv (), whereas using a fetch handle has virtually no memory overhead.

    my $sth = $dbh->prepare ("select * from foo"); $sth->execute; csv (out => "foo.csv", in => sub { $sth->fetch }, undef_str => "\\N");

    Enjoy, Have FUN! H.Merijn

      Yes, understood. That's standard DBI practises ... I'm dealing with a small table, so no memory concerns. Mostly wondering if there was a sugary interface, and more especially, in the context of DBIx::Class.


      The way forward always starts with a minimal test.