http://qs321.pair.com?node_id=898771

dargis05 has asked for the wisdom of the Perl Monks concerning the following question:

The following code:
#!/usr/bin/perl use SQL::Statement; my $sqla = "update abc set a = 's' where a = 't' and amnt > 100"; my $sqlb = "update abc t set t.a = 's' where t.a = 't' and t.amnt > 1 +00"; my $parser = SQL::Parser->new(); $parser->{RaiseError}=1; $parser->{PrintError}=1; my $stmt = SQL::Statement->new($sqlb,$parser); my $columns = $stmt->column_defs() ; printf "Command %s\n",$stmt->command;
when run for $sqla works fine:
I get
Command UPDATE
When run with $sqlb, does not work
I get
Junk after table name 'abc'! at /usr/local/lib/perl5/site_perl/5.9.1/SQL/Statement.pm line 88
Junk after table name 'abc'! at /usr/local/lib/perl5/site_perl/5.9.1/SQL/Statement.pm line 88
Q: How could I make the SQL::Parser work with table aliases. Thanks,
D. Arg

Replies are listed 'Best First'.
Re: SQL::Parser and table aliases
by JavaFan (Canon) on Apr 11, 2011 at 20:24 UTC
    How could I make the SQL::Parser work with table aliases.
    By writing a patch. A quick browse through the POD of SQL::Statement::Syntax reveals that table aliases aren't supported syntax.
Re: SQL::Parser and table aliases
by mellon85 (Monk) on Apr 11, 2011 at 20:24 UTC
    AFAIK SQL update statements doesn't support table aliases