ident => '_expand_ident',
value => '_expand_value',
func => '_expand_func',
+ values => '_expand_values',
};
$opt{expand_op} = {
return { -bind => $bind };
}
+sub _expand_values {
+ my ($self, undef, $values) = @_;
+ return { -values => [
+ map +(
+ ref($_) eq 'HASH'
+ ? $_
+ : +{ -row => [ map $self->expand_expr($_), @$_ ] }
+ ), @$values
+ ] };
+}
+
sub _recurse_where {
my ($self, $where, $logic) = @_;
.'join'
)
],
- [ $self->render_aqt($args->{to}) ],
+ [ $self->render_aqt(
+ map +($_->{-ident} or $_->{-as} ? $_ : { -row => [ $_ ] }), $args->{to}
+ ) ],
($args->{on} ? (
[ $self->_sqlcase('on') ],
[ $self->render_aqt($args->{on}) ],
my ($thing, $as, @cols) = @$args;
return $self->_join_parts(
' ',
- [ $self->render_aqt($thing) ],
+ [ $self->render_aqt(
+ map +($_->{-ident} ? $_ : { -row => [ $_ ] }), $thing
+ ) ],
[ $self->_sqlcase('as') ],
- [ @cols
- ? $self->render_aqt({ -func => [ $as, @cols ] })
- : $self->render_aqt($as)
- ],
+ (@cols
+ ? [ $self->_join_parts('',
+ [ $self->render_aqt($as) ],
+ [ '(' ],
+ [ $self->_join_parts(
+ ', ',
+ map [ $self->render_aqt($_) ], @cols
+ ) ],
+ [ ')' ],
+ ) ]
+ : [ $self->render_aqt($as) ]
+ ),
);
}
use strict;
use warnings;
use Test::More;
-use SQL::Abstract::Test import => [ qw(is_same_sql_bind) ];
+use SQL::Abstract::Test import => [ qw(is_same_sql_bind is_same_sql) ];
use SQL::Abstract::ExtraClauses;
my $sqlac = SQL::Abstract::ExtraClauses->new;
[ [ 'Rock' ], 3 ]
);
+($sql) = $sqlac->select({
+ select => [ 'a' ],
+ from => [ { -values => [ [ 1, 2 ], [ 3, 4 ] ] }, -as => [ qw(t a b) ] ],
+});
+
+is_same_sql($sql, q{SELECT a FROM (VALUES (1, 2), (3, 4)) AS t(a,b)});
+
done_testing;