How can I create a Postgres database in Perl? How can I create a Postgres database in Perl? postgresql postgresql

How can I create a Postgres database in Perl?


The trick is using the 'postgres' database that you will likely have with your installation of Postgres (if you don't have a 'postgres' database, you probably know why). If you connect as user 'postgres' to the 'postgres' database, you can then issue then create database SQL command, like so:

my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres");$dbh->do('create database "Scratch-School"');

(You might also look at create a postgreSQL database programmatically, which covers this issue at a higher level.)