$self->clause_renderer('select.setop' => sub {
my ($self, undef, $setop) = @_;
- @{ $self->render_aqt($setop) };
+ $self->render_aqt($setop);
});
$self->renderer($_ => sub {
qw(union intersect except)
);
+ my $expand_alias = sub {
+ my ($self, $to_expand) = @_;
+ [ map $self->expand_expr($_, -ident),
+ ref($to_expand) eq 'ARRAY'
+ ? @$to_expand
+ : $to_expand
+ ]
+ };
$self->clause_expander('select.with' => my $with_expander = sub {
my ($self, $name, $with) = @_;
my (undef, $type) = split '_', $name;
if (ref($with) eq 'HASH') {
return +{
%$with,
- queries => [ map $self->expand_expr($_), @{$with->{queries}} ]
+ queries => [
+ map +[
+ $self->$expand_alias($_->[0]),
+ $self->expand_expr($_->[1]),
+ ], @{$with->{queries}}
+ ]
}
}
my @with = @$with;
my @exp;
- while (my ($name, $query) = splice @with, 0, 2) {
- my @n = map $self->expand_expr($_, -ident),
- ref($name) eq 'ARRAY' ? @$name : $name;
+ while (my ($alias, $query) = splice @with, 0, 2) {
push @exp, [
- \@n,
+ $self->$expand_alias($alias),
$self->expand_expr($query)
];
}
$self->clause_expander('select.with_recursive', $with_expander);
$self->clause_renderer('select.with' => sub {
my ($self, undef, $with) = @_;
- my $q_part = [ $self->join_query_parts(', ',
+ my $q_part = $self->join_query_parts(', ',
map {
my ($alias, $query) = @$_;
- [ $self->join_query_parts(' ',
+ $self->join_query_parts(' ',
$self->_render_alias($alias),
$self->format_keyword('as'),
$query,
- ) ]
+ )
} @{$with->{queries}}
- ) ];
+ );
return $self->join_query_parts(' ',
$self->format_keyword(join '_', 'with', ($with->{type}||'')),
$q_part,
sub _expand_from_list {
my ($self, undef, $args) = @_;
if (ref($args) eq 'HASH') {
+ return $args if $args->{-from_list};
return { -from_list => [ $self->expand_expr($args) ] };
}
my @list;
return (@cols
? $self->join_query_parts('',
$as,
- [ '(' ],
- [ $self->join_query_parts(
- ', ',
- @cols
- ) ],
- [ ')' ],
+ '(',
+ $self->join_query_parts(
+ ', ',
+ @cols
+ ),
+ ')',
)
: $self->render_aqt($as)
);