or (@{$order->{by}{elements}} == 1))
) {
push @main_order, [
- $outside->{by}, $order->{by}{elements}[-1], $order->{reverse}
+ $outside->{by}, $order->{by}{elements}[-1], $order->{reverse},
+ $order->{nulls}
];
} else {
last;
my $lhs = $b->[0];
my $rhs = Identifier($count_alias, $b->[1]);
($lhs, $rhs) = ($rhs, $lhs) if $b->[2];
- my $this = Operator($op_or, [
- Operator($op_and, [
- Operator({ 'SQL.Naive' => 'IS NOT NULL' }, [ $lhs ]),
- Operator({ 'SQL.Naive' => 'IS NULL' }, [ $rhs ]),
- ]),
- Operator({ 'SQL.Naive' => '>' }, [ $lhs, $rhs ]),
- ]);
- ($a
- ? Operator($op_or, [
- $this,
- Operator($op_and, [
- Operator($op_or, [
- Operator($op_and, [
- map Operator({ 'SQL.Naive' => 'IS NULL' }, [ $_ ]), $lhs, $rhs
- ]),
- Operator({ 'SQL.Naive' => '=' }, [ $lhs, $rhs ])
+ my $no_nulls = ($b->[3]||'') eq 'none';
+ my ($this) = map {
+ $no_nulls
+ ? $_
+ : Operator($op_or, [
+ Operator($op_and, [
+ Operator({ 'SQL.Naive' => 'IS NOT NULL' }, [ $lhs ]),
+ Operator({ 'SQL.Naive' => 'IS NULL' }, [ $rhs ]),
]),
- $a
+ $_
])
- ])
- : $this)
+ } Operator({ 'SQL.Naive' => '>' }, [ $lhs, $rhs ]);
+ my $final = (
+ $a
+ ? Operator($op_or, [
+ $this,
+ Operator($op_and, [
+ (map {
+ $no_nulls
+ ? $_
+ : Operator($op_or, [
+ Operator($op_and, [
+ map Operator({ 'SQL.Naive' => 'IS NULL' }, [ $_ ]),
+ $lhs, $rhs
+ ]),
+ $_,
+ ])
+ } Operator({ 'SQL.Naive' => '=' }, [ $lhs, $rhs ])),
+ $a
+ ])
+ ])
+ : $this
+ );
+ $final;
} @main_order, undef;
my $count_sel = Select(
[ Operator({ 'SQL.Naive' => 'apply' }, [ Identifier('COUNT'), Identifier('*') ]) ],