PGObject::Util::BulkUpload - Bulk Upload records into PostgreSQL
Version 0.02
To insert all rows into a table using COPY:
PGObject::Util::BulkUpload->copy( {table => 'mytable', insert_cols => ['col1', 'col2'], dbh => $dbh}, @objects );
To copy to a temp table and then upsert:
PGObject::Util::BulkUpload->upsert( {table => 'mytable', insert_cols => ['col1', 'col2'], update_cols => ['col1'], key_cols => ['col2'], dbh => $dbh}, @objects );
Or if you prefer to run the statements yourself:
PGObject::Util::BulkUpload->statement( table => 'mytable', type => 'temp', tempname => 'foo_123' ); PGObject::Util::BulkUpload->statement( table => 'mytable', type => 'copy', insert_cols => ['col1', 'col2'] ); PGObject::Util::BulkUpload->statement( type => 'upsert', tempname => 'foo_123', table => 'mytable', insert_cols => ['col1', 'col2'], update_cols => ['col1'], key_cols => ['col2'] );
If you are running repetitive calls, you may be able to trade time for memory using Memoize by unning the following:
PGObject::Util::BulkUpload->memoize_statements;
To unmemoize:
PGObject::Util::BulkUpload->unmemoize;
To flush cache
PGObject::Util::BulkUpload->flush_memoization;
This function exists to memoize statement calls, i.e. generate the exact same statements on the same argument calls. This isn't too likely to be useful in most cases but it may be if you have repeated bulk loader calls in a persistent script (for example real-time importing of csv data from a frequent source).
Unmemoizes the statement calls.
Flushes the cache for statement memoization. Does *not* flush the cache for escaping memoization since that is a bigger win and a pure function accepting simple strings.
This takes the following arguments and returns a suitable SQL statement
Type of statement. Options are:
Create a temporary table
sql COPY statement
Update/Insert CTE pulling temp table
Name of table
Name of temp table
Column names for insert
Column names for update
Names of columns in primary key.
Creates a temporary table named "pg_object.bulkload" and copies the data there
If the first argument is an object, then if there is a function by the name of the object, it will provide the value.
Table to upsert into
Columns to insert (by name)
Columns to update (by name)
Key columns (by name)
Copies data into the specified table. The following arguments are used:
Chris Travers, <chris.travers at gmail.com>
<chris.travers at gmail.com>
<perl at binary.com>
Please report any bugs or feature requests to bug-pgobject-util-bulkupload at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PGObject-Util-BulkUpload. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-pgobject-util-bulkupload at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc PGObject::Util::BulkUpload
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=PGObject-Util-BulkUpload
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/PGObject-Util-BulkUpload
CPAN Ratings
http://cpanratings.perl.org/d/PGObject-Util-BulkUpload
Search CPAN
http://search.cpan.org/dist/PGObject-Util-BulkUpload/
Copyright 2014 Chris Travers.
This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Chris Travers's Organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install PGObject::Util::BulkLoad, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PGObject::Util::BulkLoad
CPAN shell
perl -MCPAN -e shell install PGObject::Util::BulkLoad
For more information on module installation, please visit the detailed CPAN module installation guide.