Author image Oliver Charles
and 1 contributors


    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($table, \@values || \%fieldvals, \@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.

\@returning is an array reference of column names that should be returned.

This method will return an array of the SQL generated, and then all bind parameters.