1 package # Hide from PAUSE
2 DBIx::Class::SQLMaker::Pg;
4 use base qw( DBIx::Class::SQLMaker );
5 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
7 sub _datetime_now_sql { 'NOW()' }
13 day_of_month => 'DAY',
16 seconds_since_epoch => 'EPOCH',
18 iso_day_of_week => 'ISODOW',
19 iso_year => 'ISOYEAR',
20 microsecond => 'MICROSECONDS',
21 millenium => 'MILLENIUM',
22 millisecond => 'MILLISECONDS',
27 timezone => 'TIMEZONE',
28 timezone_hour => 'TIMEZONE_HOUR',
29 timezone_minute => 'TIMEZONE_MINUTE',
34 my %diff_part_map = %part_map;
35 $diff_part_map{day} = delete $diff_part_map{day_of_month};
38 die $_[0]->_unsupported_date_extraction($_[1], 'PostgreSQL')
39 unless exists $part_map{$_[1]};
40 "EXTRACT($part_map{$_[1]} FROM $_[2])"
42 sub _datetime_diff_sql {
43 die $_[0]->_unsupported_date_diff($_[1], 'PostgreSQL')
44 unless exists $diff_part_map{$_[1]};
46 if ( $diff_part_map{$_[1]} eq 'SECOND' ) {
47 $field_to_extract = "EPOCH" ;
49 $field_to_extract = $diff_part_map{$_[1]};
51 ## adjusting this HERE as second will be needed elsewhere
52 "EXTRACT($field_to_extract FROM ($_[2]::timestamp with time zone - $_[3]::timestamp with time zone))"
55 sub _reorder_add_datetime_vars {
56 my ($self, $amount, $date) = @_;
58 return ($date, $amount);
61 sub _datetime_add_sql {
62 my ($self, $part, $date, $amount) = @_;
64 die $self->_unsupported_date_adding($part, 'PostgreSQL')
65 unless exists $diff_part_map{$part};
67 return "($date + $amount || ' $part_map{$part}'))"
71 =head1 DATE FUNCTION IMPLEMENTATION
73 The function used to extract date information is C<EXTRACT>, which supports
97 The function used to diff dates is subtraction and C<EXTRACT>, which supports