January 2nd, 2010 by depesz | Tags: , , , , | No comments »
Did it help? If yes - maybe you can help me?

Just recently I wrote about DO command in PostgreSQL 8.5, and now (since 29th of November) we have DO with PL/Perl support.

Written by Joshua Tolley and committed by Tom Lane, the patch:

Log Message:
Add support for anonymous code blocks (DO blocks) to PL/Perl.
Joshua Tolley, reviewed by Brendan Jurd and Tim Bunce

DO command basically runs code in any PL/ language, but it requires some kind of support from the language itself. And now this support has been added to PL/Perl.

So, now we can do stuff like this:

DO $$
for (1..10) {
my $table_name = sprintf "p_%02u", $_;
spi_exec_query("CREATE TABLE $table_name (i int4)");
warn "table $table_name created.";
$$ language plperl;

This isn't of course the only thing possible – it's just a hint, and what you will use it for is up to you 🙂

Leave a comment