line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alzabo::SQLMaker::PostgreSQL; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
781
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $AUTOLOAD @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Alzabo::Exceptions; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Alzabo::SQLMaker; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
9
|
1
|
|
|
1
|
|
7
|
use base qw(Alzabo::SQLMaker); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1399
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = 2.0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $MADE_FUNCTIONS; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub import |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
50
|
|
1
|
|
11
|
_make_functions() unless $MADE_FUNCTIONS; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# used to export function functions |
20
|
1
|
|
|
|
|
12
|
require Exporter; |
21
|
1
|
|
|
|
|
6
|
*_import = \&Exporter::import; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
79
|
goto &_import; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _make_functions |
27
|
|
|
|
|
|
|
{ |
28
|
1
|
|
|
1
|
|
4
|
local *make_function = \&Alzabo::SQLMaker::make_function; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
13
|
foreach ( [ NOW => [ 'datetime', 'common' ] ], |
31
|
|
|
|
|
|
|
[ CURRENT_DATE => [ 'datetime' ], { no_parens => 1 } ], |
32
|
|
|
|
|
|
|
[ CURRENT_TIME => [ 'datetime' ], { no_parens => 1 } ], |
33
|
|
|
|
|
|
|
[ CURRENT_TIMESTAMP => [ 'datetime' ], { no_parens => 1 } ], |
34
|
|
|
|
|
|
|
[ TIMEOFDAY => [ 'datetime' ] ], |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
[ PI => [ 'math' ] ], |
37
|
|
|
|
|
|
|
[ RANDOM => [ 'math' ] ], |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
[ CURRENT_USER => [ 'system' ] ], |
40
|
|
|
|
|
|
|
[ SYSTEM_USER => [ 'system' ] ], |
41
|
|
|
|
|
|
|
[ USER => [ 'system' ] ], |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
{ |
44
|
3
|
|
|
|
|
13
|
make_function( function => $_->[0], |
45
|
|
|
|
|
|
|
min => 0, |
46
|
|
|
|
|
|
|
max => 0, |
47
|
|
|
|
|
|
|
groups => $_->[1], |
48
|
10
|
100
|
|
|
|
40
|
$_->[2] ? %{ $_->[2] } : (), |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
49
|
foreach ( [ LENGTH => [1], [ 'string' ] ], |
53
|
|
|
|
|
|
|
[ CHAR_LENGTH => [1], [ 'string' ] ], |
54
|
|
|
|
|
|
|
[ CHARACTER_LENGTH => [1], [ 'string' ] ], |
55
|
|
|
|
|
|
|
[ OCTET_LENGTH => [1], [ 'string' ] ], |
56
|
|
|
|
|
|
|
[ TRIM => [1], [ 'string' ] ], |
57
|
|
|
|
|
|
|
[ UPPER => [1], [ 'string' ] ], |
58
|
|
|
|
|
|
|
[ LOWER => [1], [ 'string' ] ], |
59
|
|
|
|
|
|
|
[ INITCAP => [1], [ 'string' ] ], |
60
|
|
|
|
|
|
|
[ ASCII => [1], [ 'string' ] ], |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
[ ABS => [0], [ 'math' ] ], |
63
|
|
|
|
|
|
|
[ CEIL => [0], [ 'math' ] ], |
64
|
|
|
|
|
|
|
[ DEGREES => [0], [ 'math' ] ], |
65
|
|
|
|
|
|
|
[ FLOOR => [0], [ 'math' ] ], |
66
|
|
|
|
|
|
|
[ FACTORIAL => [0], [ 'math' ] ], |
67
|
|
|
|
|
|
|
[ SQRT => [0], [ 'math' ] ], |
68
|
|
|
|
|
|
|
[ CBRT => [0], [ 'math' ] ], |
69
|
|
|
|
|
|
|
[ EXP => [0], [ 'math' ] ], |
70
|
|
|
|
|
|
|
[ LN => [0], [ 'math' ] ], |
71
|
|
|
|
|
|
|
[ RADIANS => [0], [ 'math' ] ], |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
[ ACOS => [0], [ 'math' ] ], |
74
|
|
|
|
|
|
|
[ ASIN => [0], [ 'math' ] ], |
75
|
|
|
|
|
|
|
[ ATAN => [0], [ 'math' ] ], |
76
|
|
|
|
|
|
|
[ COS => [0], [ 'math' ] ], |
77
|
|
|
|
|
|
|
[ COT => [0], [ 'math' ] ], |
78
|
|
|
|
|
|
|
[ SIN => [0], [ 'math' ] ], |
79
|
|
|
|
|
|
|
[ TAN => [0], [ 'math' ] ], |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
[ ISFINITE => [1], [ 'datetime' ] ], |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
[ BROADCAST => [1], [ 'network' ] ], |
84
|
|
|
|
|
|
|
[ HOST => [1], [ 'network' ] ], |
85
|
|
|
|
|
|
|
[ NETMASK => [1], [ 'network' ] ], |
86
|
|
|
|
|
|
|
[ MASKLEN => [1], [ 'network' ] ], |
87
|
|
|
|
|
|
|
[ NETWORK => [1], [ 'network' ] ], |
88
|
|
|
|
|
|
|
[ TEXT => [1], [ 'network' ] ], |
89
|
|
|
|
|
|
|
[ ABBREV => [1], [ 'network' ] ], |
90
|
|
|
|
|
|
|
) |
91
|
|
|
|
|
|
|
{ |
92
|
34
|
|
|
|
|
109
|
make_function( function => $_->[0], |
93
|
|
|
|
|
|
|
min => 1, |
94
|
|
|
|
|
|
|
max => 1, |
95
|
|
|
|
|
|
|
quote => $_->[1], |
96
|
|
|
|
|
|
|
groups => $_->[2], |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
34
|
foreach ( [ TO_ASCII => [1,0], [ 'string' ] ], |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
[ ROUND => [0,0], [ 'math' ] ], |
103
|
|
|
|
|
|
|
[ TRUNC => [0,0], [ 'math' ] ], |
104
|
|
|
|
|
|
|
[ LOG => [0,0], [ 'math' ] ], |
105
|
|
|
|
|
|
|
[ POW => [0,0], [ 'math' ] ], |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
[ TIMESTAMP => [1,1], [ 'datetime' ] ], |
108
|
|
|
|
|
|
|
) |
109
|
|
|
|
|
|
|
{ |
110
|
6
|
|
|
|
|
22
|
make_function( function => $_->[0], |
111
|
|
|
|
|
|
|
min => 1, |
112
|
|
|
|
|
|
|
max => 2, |
113
|
|
|
|
|
|
|
quote => $_->[1], |
114
|
|
|
|
|
|
|
groups => $_->[2], |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
27
|
foreach ( [ STRPOS => [1,1], [ 'string' ] ], |
119
|
|
|
|
|
|
|
[ POSITION => [1,1], [ 'string' ], '%s IN %s' ], |
120
|
|
|
|
|
|
|
[ TO_NUMBER => [1,1], [ 'string' ] ], |
121
|
|
|
|
|
|
|
[ TO_DATE => [1,1], [ 'string' ] ], |
122
|
|
|
|
|
|
|
[ TO_TIMESTAMP => [1,1], [ 'string' ] ], |
123
|
|
|
|
|
|
|
[ REPEAT => [1,0], [ 'string' ] ], |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
[ MOD => [0,0], [ 'math' ] ], |
126
|
|
|
|
|
|
|
[ ATAN2 => [0,0], [ 'math' ] ], |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
[ TO_CHAR => [0,1], [ 'math', 'datetime' ] ], |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
[ DATE_PART => [1,1], [ 'datetime' ] ], |
131
|
|
|
|
|
|
|
[ EXTRACT => [0,1], [ 'datetime' ], '%s FROM %s' ], |
132
|
|
|
|
|
|
|
[ DATE_TRUNC => [1,1], [ 'datetime' ] ], |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
[ NULLIF => [0,0], [ 'control' ] ], |
135
|
|
|
|
|
|
|
) |
136
|
|
|
|
|
|
|
{ |
137
|
13
|
100
|
|
|
|
66
|
make_function( function => $_->[0], |
138
|
|
|
|
|
|
|
min => 2, |
139
|
|
|
|
|
|
|
max => 2, |
140
|
|
|
|
|
|
|
quote => $_->[1], |
141
|
|
|
|
|
|
|
groups => $_->[2], |
142
|
|
|
|
|
|
|
$_->[3] ? ( format => $_->[3] ) : (), |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
1
|
|
|
|
|
19
|
foreach ( [ RPAD => [0,0,1], [ 'string' ] ], |
147
|
|
|
|
|
|
|
[ LPAD => [0,0,1], [ 'string' ] ], |
148
|
|
|
|
|
|
|
[ SUBSTR => [0,0,0], [ 'string' ] ], |
149
|
|
|
|
|
|
|
) |
150
|
|
|
|
|
|
|
{ |
151
|
3
|
|
|
|
|
13
|
make_function( function => $_->[0], |
152
|
|
|
|
|
|
|
min => 2, |
153
|
|
|
|
|
|
|
max => 3, |
154
|
|
|
|
|
|
|
quote => $_->[1], |
155
|
|
|
|
|
|
|
groups => $_->[2], |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
1
|
|
|
|
|
10
|
make_function( function => 'COALESCE', |
160
|
|
|
|
|
|
|
min => 2, |
161
|
|
|
|
|
|
|
max => undef, |
162
|
|
|
|
|
|
|
quote => [0,0,0], |
163
|
|
|
|
|
|
|
groups => [ 'control' ], |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
9
|
make_function( function => 'OVERLAPS', |
167
|
|
|
|
|
|
|
min => 4, |
168
|
|
|
|
|
|
|
max => 4, |
169
|
|
|
|
|
|
|
quote => [1,1,1,1], |
170
|
|
|
|
|
|
|
groups => [ 'datetime' ], |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
|
|
16
|
foreach ( [ COUNT => [0], [ 'aggregate', 'common' ] ], |
174
|
|
|
|
|
|
|
[ AVG => [0], [ 'aggregate', 'common' ] ], |
175
|
|
|
|
|
|
|
[ MIN => [0], [ 'aggregate', 'common' ] ], |
176
|
|
|
|
|
|
|
[ MAX => [0], [ 'aggregate', 'common' ] ], |
177
|
|
|
|
|
|
|
[ SUM => [0], [ 'aggregate', 'common' ] ], |
178
|
|
|
|
|
|
|
[ STDDEV => [0], [ 'aggregate' ] ], |
179
|
|
|
|
|
|
|
[ VARIANCE => [0], [ 'aggregate' ] ], |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
[ DISTINCT => [0], [ 'common' ] ], |
182
|
|
|
|
|
|
|
) |
183
|
|
|
|
|
|
|
{ |
184
|
8
|
|
|
|
|
31
|
make_function( function => $_->[0], |
185
|
|
|
|
|
|
|
min => 1, |
186
|
|
|
|
|
|
|
max => 1, |
187
|
|
|
|
|
|
|
quote => $_->[1], |
188
|
|
|
|
|
|
|
groups => $_->[2], |
189
|
|
|
|
|
|
|
); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
1
|
|
|
|
|
8
|
$MADE_FUNCTIONS = 1; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub init |
196
|
|
|
|
|
|
|
{ |
197
|
0
|
|
|
0
|
0
|
|
1; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub new |
201
|
|
|
|
|
|
|
{ |
202
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(@_); |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
$self->{alias_in_having} = 0; |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
return $self; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub limit |
210
|
|
|
|
|
|
|
{ |
211
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
212
|
0
|
|
|
|
|
|
my ($max, $offset) = @_; |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
$self->_assert_last_op( qw( from function where and or condition order_by group_by ) ); |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
$self->{sql} .= " LIMIT $max"; |
217
|
0
|
0
|
|
|
|
|
$self->{sql} .= " OFFSET $offset" if $offset; |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
$self->{last_op} = 'limit'; |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
return $self; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub get_limit |
225
|
|
|
|
|
|
|
{ |
226
|
0
|
|
|
0
|
1
|
|
return undef; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
0
|
0
|
|
sub distinct_requires_order_by_in_select { 1 } |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub sqlmaker_id |
232
|
|
|
|
|
|
|
{ |
233
|
0
|
|
|
0
|
1
|
|
return 'PostgreSQL'; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__ |