use SQL::Abstract; use SQL::Abstract::Plugin::InsertReturning; my $sql = SQL::Abstract->new; my ($query, @bind) = $sql->insert_returning('pets', { name => 'Fluffy Munchkins', type => 'Kitty' }, [qw( name type )]); print $sql; # INSERT INTO pets ( name, type ) VALUES ( ?, ? ) RETURNING name, type;
DEPRECATED. This functionality is now in SQL::Abstract itself. This module just wraps around that. Please, stop using this!
Some databases have support for returning data after an insert query, which can help gain performance when doing common operations such as inserting and then returning the new objects ID.
This plugin exports the insert_returning method into the SQL::Abstract namespace, allowing you to call it much like any other method.
insert_returning
Forms an SQL query with both an INSERT part and a RETURNING part. The INSERT part is generated by SQL::Abstract's insert method, and both the $table and $fieldvals values are passed directly to it. The returning SQL is then altered to have a returning statement.
INSERT
RETURNING
insert
$table
$fieldvals
\@returning is an array reference of column names that should be returned.
\@returning
This method will return an array of the SQL generated, and then all bind parameters.
To install SQL::Abstract::Plugin::InsertReturning, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::Abstract::Plugin::InsertReturning
CPAN shell
perl -MCPAN -e shell install SQL::Abstract::Plugin::InsertReturning
For more information on module installation, please visit the detailed CPAN module installation guide.