Subject: | Improper parsing of column names that have aliases |
SQL::Statement seems unable to handle field aliases.
When I run a parse of a simple but valid statement:
SELECT
"field3" AS "my_field3",
"field2" AS "my_field2",
"field1" AS "my_field1"
FROM "sometable"
and get the following structure:
$VAR1 = {
'table_alias' => {},
'original_string' => 'SELECT
"field3" AS "my_field3",
"field2" AS "my_field2",
"field1" AS "my_field1"
FROM "sometable"',
'org_table_names' => [
'"sometable"'
],
'ORG_NAME' => {
'?QI0? AS ?QI1?' => '?QI0? AS ?QI1?',
'?QI4? AS ?QI5?' => '?QI4? AS ?QI5?',
'?QI2? AS ?QI3?' => '?QI2? AS ?QI3?'
},
'column_names' => [
'?QI0? AS ?QI1?',
'?QI2? AS ?QI3?',
'?QI4? AS ?QI5?'
],
'org_col_names' => [
'?QI0? AS ?QI1?',
'?QI2? AS ?QI3?',
'?QI4? AS ?QI5?'
],
'table_names' => [
'"SOMETABLE"'
],
'command' => 'SELECT'
};
use strict;
use SQL::Parser;
use Data::Dumper;
my $sql = qq{
SELECT
"field3" AS "my_field3",
"field2" AS "my_field2",
"field1" AS "my_field1"
FROM "sometable"
};
# print $sql;
my $parser = SQL::Parser->new();
if ($parser->parse($sql)) {
print Dumper $parser->structure;
} else {
print "Parse failed\n";
}