How do I create a Postgres database in Perl?
How do I create a Postgres database with Perl? This is not documented in the Postgres Perl DBI driver DBD::Pg
(or almost elsewhere). I need to create a database from scratch from my program, instead of using psql or pgAdmin to create the database.
+3
Mark leighton fisher
source
to share
1 answer
The trick is using the postgres database, which you are likely to have when installing Postgres (if you don't have a postgres database, you probably know why). If you are connecting as user "postgres" to the postgres database, you can then run the create database SQL command , for example:
my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres");
$dbh->do('create database "Scratch-School"');
(You can also look at creating a postgreSQL database programmatically , which covers this issue at a higher level.)
+4
Mark leighton fisher
source
to share