package SQL::Translator::Producer::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.29 2007-06-04 04:01:14 mwz444 Exp $
-# -------------------------------------------------------------------
-# Copyright (C) 2002-4 SQLFairy Authors
+# Copyright (C) 2002-2009 SQLFairy Authors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use warnings;
use vars qw[ $DEBUG $WARN $VERSION %used_names ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.29 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
$DEBUG = 0 unless defined $DEBUG;
+use base qw(SQL::Translator::Producer);
use SQL::Translator::Schema::Constants;
use SQL::Translator::Utils qw(debug header_comment);
use Data::Dumper;
push @fks, @$fks;
}
+
+ my $temporary = "";
+
+ if(exists $table->{extra}{temporary}) {
+ $temporary = $table->{extra}{temporary} ? "TEMPORARY " : "";
+ }
+
my $create_statement;
$create_statement = join("\n", @comments);
if ($add_drop_table) {
if ($postgres_version >= 8.2) {
$create_statement .= qq[DROP TABLE IF EXISTS $qt$table_name_ur$qt CASCADE;\n];
- $create_statement .= join ("\n", @type_drops) . "\n"
- if $postgres_version >= 8.3;
+ $create_statement .= join (";\n", @type_drops) . ";\n"
+ if $postgres_version >= 8.3 && scalar @type_drops;
} else {
$create_statement .= qq[DROP TABLE $qt$table_name_ur$qt CASCADE;\n];
}
}
- $create_statement .= join("\n", @type_defs) . "\n"
- if $postgres_version >= 8.3;
- $create_statement .= qq[CREATE TABLE $qt$table_name_ur$qt (\n].
+ $create_statement .= join(";\n", @type_defs) . ";\n"
+ if $postgres_version >= 8.3 && scalar @type_defs;
+ $create_statement .= qq[CREATE ${temporary}TABLE $qt$table_name_ur$qt (\n].
join( ",\n", map { " $_" } @field_defs, @constraint_defs ).
"\n)"
;