#43 about the parseResult

closed
nobody
None
5
2012-06-16
2011-04-28
dolphin
No

Hi,

I parsed a very long SQL:
-----------------------------------------------------------------------------------------------------
SELECT employee.*, department.*
FROM employee
LEFT JOIN department
ON employee.DepartmentID = department.DepartmentID
UNION ALL
SELECT employee.*, department.*
FROM department
LEFT JOIN employee
ON employee.DepartmentID = department.DepartmentID
WHERE employee.DepartmentID IS NULL;
-----------------------------------------------------------------------------------------------------------
and got the result as follows using dump():

['SELECT', ['employee', '.', '*', 'department', '.', '*'], 'FROM', ['employee', 'LEFT', 'JOIN', 'department', 'ON', ['employee', '.', 'DepartmentID', '=', 'department', '.', 'DepartmentID']], 'UNION', 'ALL', 'SELECT', ['employee', '.', '*', 'department', '.', '*'], 'FROM', ['department', 'LEFT', 'JOIN', 'employee', 'ON', ['employee', '.', 'DepartmentID', '=', 'department', '.', 'DepartmentID']], 'WHERE', ['employee', '.', 'DepartmentID', 'IS', 'NULL']]

- FROM: ['department', 'LEFT', 'JOIN', 'employee', 'ON', ['employee', '.', 'DepartmentID', '=', 'department', '.', 'DepartmentID']]
- JOIN: ['LEFT', 'JOIN', 'employee', 'ON', ['employee', '.', 'DepartmentID', '=', 'department', '.', 'DepartmentID']]
- join_constraint: ['employee', '.', 'DepartmentID', '=', 'department', '.', 'DepartmentID']
- join_operator: ['LEFT', 'JOIN']
- join_constraint: ['employee', '.', 'DepartmentID', '=', 'department', '.', 'DepartmentID']
- join_operator: ['LEFT', 'JOIN']
- WHERE: ['employee', '.', 'DepartmentID', 'IS', 'NULL']
- compound_op: UNION
- SELECT: ['employee', '.', '*', 'department', '.', '*']

actually, it only output the statement after UNION. I also try to retrieve all the items in parseResult by myself, but the result is the same.
I am not sure if this is a bug of pyparsing or my program.

Discussion

  • Paul McGuire
    Paul McGuire
    2012-06-16

    I don't see anything wrong in your output from a pyparsing standpoint. I suspect you are mixing results names from the different SELECT statements in your input - you probably need to handle UNION'ed SELECT statements by using pyparsing Group to wrap them, so that the different parse results names are kept separate from each other.

     
  • Paul McGuire
    Paul McGuire
    2012-06-16

    • status: open --> closed