package SQL::Translator::Parser::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.24 2003-08-12 22:00:28 kycl4rk Exp $
+# $Id: PostgreSQL.pm,v 1.28 2003-08-20 18:58:54 kycl4rk Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# Allen Day <allenday@users.sourceforge.net>,
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.24 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.28 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
my @comments = ( @{ $item[1] }, @{ $item[5] } );
$return = {
- type => 'field',
- name => $item{'field_name'},
- data_type => $item{'data_type'}{'type'},
- size => $item{'data_type'}{'size'},
- null => $null,
- default => $default->{'value'},
- constraints => [ @constraints ],
- comments => [ @comments ],
- is_primary_key => $is_pk || 0,
+ type => 'field',
+ name => $item{'field_name'},
+ data_type => $item{'data_type'}{'type'},
+ size => $item{'data_type'}{'size'},
+ null => $null,
+ default => $default->{'value'},
+ constraints => [ @constraints ],
+ comments => [ @comments ],
+ is_primary_key => $is_pk || 0,
+ is_auto_increment => $item{'data_type'}{'is_auto_increment'},
}
}
| <error>
}
pg_data_type :
- /(bigint|int8|bigserial|serial8)/i
+ /(bigint|int8)/i
{
$return = {
- type => 'integer',
- size => [8],
- auto_increment => 1,
+ type => 'integer',
+ size => [8],
};
}
|
};
}
|
- /int(eger)?|int4/i
+ /(integer|int4?)/i # interval must come before this
{
$return = {
type => 'integer',
size => [4],
};
}
+ |
+ /(real|float4)/i
+ {
+ $return = {
+ type => 'real',
+ size => [4],
+ };
+ }
|
/(double precision|float8?)/i
{
};
}
|
- /(real|float4)/i
- {
- $return = {
- type => 'real',
- size => [4],
- };
- }
- |
- /serial4?/i
+ /(bigserial|serial8)/i
{
$return = {
- type => 'integer',
- size => [4],
- auto_increment => 1,
+ type => 'integer',
+ size => [8],
+ is_auto_increment => 1,
};
}
|
- /bigserial/i
+ /serial4?/i
{
$return = {
- type => 'integer',
- size => [8],
- auto_increment => 1,
+ type => 'integer',
+ size => [4],
+ is_auto_increment => 1,
};
}
|
$return = { type => 'bytea' };
}
|
- /timestampz?/i
+ /(timestamptz|timestamp)/i
{
$return = { type => 'timestamp' };
}
|
- /(bit|box|cidr|circle|date|inet|interval|line|lseg|macaddr|money|numeric|decimal|path|point|polygon|text|time|varchar)/i
+ /(bit|box|cidr|circle|date|inet|interval|line|lseg|macaddr|money|numeric|decimal|path|point|polygon|text|timetz|time|varchar)/i
{
$return = { type => $item[1] };
}
create_index : /create/i /index/i
-default_val : /default/i /(\d+|'[^']+'|\w+\(.*?\))/
+default_val : /default/i /(\d+|'[^']*'|\w+\(.*?\))|\w+/
{
my $val = defined $item[2] ? $item[2] : '';
$val =~ s/^'|'$//g;
my $tdata = $result->{ $table_name };
my $table = $schema->add_table(
name => $tdata->{'table_name'},
- ) or die $schema->error;
+ ) or die "Couldn't create table '$table_name': " . $schema->error;
my @fields = sort {
$tdata->{'fields'}->{$a}->{'order'}
data_type => $fdata->{'data_type'},
size => $fdata->{'size'},
default_value => $fdata->{'default'},
- is_auto_increment => $fdata->{'is_auto_inc'},
+ is_auto_increment => $fdata->{'is_auto_increment'},
is_nullable => $fdata->{'null'},
) or die $table->error;