#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    NY
    Posts
    26
    Rep Power
    0

    Dumping/Exporting table to a file via Perl DBI


    Hi,

    I want to dump a 'select' result of a "Huge" table in to a file (csv or not) using the perl dbi module.

    I am in the process of moving all my db calls from system to dbi calls to effectively handle errors and such.. I am stuck on figuring out how to use dbi call effectively to do the below statement.

    Currently I am doing it via system call:
    Code:
     system("psql -U timadbo -c 'SELECT * FROM $summary;' timadb > $output  ");
    I dont want to use the
    Code:
     while (@data = $sth->fetchrow_array())
    way bc I believe it will take longer to process than just dumping it directly.

    Does anybody have solution or pointer for me on how to export the results to an output file using dbi on postgres?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Dumping the data to a file sends up a red flag. Presumably, you're going to read/process that file later in the script, which is more work and less efficient.

    But if that's what you want, try this:
    http://search.cpan.org/~timb/DBI-1.6...m#dump_results
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    NY
    Posts
    26
    Rep Power
    0
    Thank you for your answer

IMN logo majestic logo threadwatch logo seochat tools logo