#!/usr/bin/perl -w

use strict;
use DBI;

sub dbh {
    DBI->connect(
        'dbi:Pg:dbname=postgres;host=localhost', 'neilc', 'neilc',
        {
            RaiseError     => 1,
            PrintError     => 0,
#            pg_server_prepare => 0,
        }
    );
}

my $dbh = dbh;

END {
    $dbh->disconnect;
    $dbh = dbh;
    $dbh->do('DROP TABLE try');
    $dbh->do('DROP DOMAIN state');
    $dbh->disconnect;
}

$dbh->do('CREATE DOMAIN state AS SMALLINT NOT NULL DEFAULT 1
CONSTRAINT ck_state CHECK (
   VALUE BETWEEN -1 AND 2
)');


$dbh->do('CREATE TABLE try (a STATE)');

my $sth = $dbh->prepare('INSERT INTO try (a) VALUES (?)');
$sth->execute(12);
