Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the use of "RETURNING" #133

Open
Tux opened this issue Nov 7, 2024 · 1 comment
Open

Document the use of "RETURNING" #133

Tux opened this issue Nov 7, 2024 · 1 comment

Comments

@Tux
Copy link
Contributor

Tux commented Nov 7, 2024

I needed help on IRC, and I consider myself a seasoned DBI user.

I'd add this:

diff --git a/Pg.pm b/Pg.pm
index 408d227..cc2e3f4 100644
--- a/Pg.pm
+++ b/Pg.pm
@@ -2664,6 +2664,19 @@ If you did not want to worry about the sequence name:
     print "Last insert id was $newid\n";
   }

+or, using C<RETURNING>:
+
+  $dbh->do('CREATE TABLE lii2 (
+    foobar SERIAL UNIQUE,
+    baz VARCHAR)');
+  $SQL = 'INSERT INTO lii2(baz) VALUES (?) RETURNING foobar';
+  $sth = $dbh->prepare($SQL);
+  for (qw(uno dos tres cuatro)) {
+    $sth->execute($_);
+    my ($newid) = $sth->fetchrow_array;
+    print "Last insert id was $newid\n";
+  }
+
 =head3 B<commit>

   $rv = $dbh->commit;

Does that make sense? Want a PR

@esabol
Copy link
Contributor

esabol commented Nov 7, 2024

@Tux wrote:

Does that make sense? Want a PR

Sure! I suggest changing "or, using" to "Alternatively, using".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants