In this recipe, we are going to show you how to create tables in the PostgreSQL database using Perl.
We will be the using the qq
operator, and the parameter passed to the operator will contain the CREATE TABLE
SQL statement. The qq
operator is used to return a double-quoted string. Before creating the table, we must first use the connect
function to connect to the PostgreSQL database.
We can use the following code to create a table by the name EMPLOYEES
. This table will be stored in the dvdrental
database because the connection made by the PostgreSQL adapter is to the dvdrental
database. The following code is saved in a file called createtable.pl
, which will be executed later:
#!/usr/bin/perl use DBI; use strict; my $driver = "Pg"; my $database = "dvdrental"; my $dsn = "DBI:$driver:dbname=$database;host=127.0.0.1;port=5432"; my $userid = "postgres"; my $password = "postgres"; my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError...