INSERT INTO t1 (t0) VALUES ('2'); identifier t1 will be parsed as Function
|- 0 Newline ' '
|- 1 DML 'INSERT'
|- 2 Whitespace ' '
|- 3 Keyword 'INTO'
|- 4 Whitespace ' '
|- 5 Function 't1 (t0)'
| |- 0 Identifier 't1'
| | - 0 Name 't1' | |- 1 Whitespace ' ' | - 2 Parenthesis '(t0)'
| |- 0 Punctuation '('
| |- 1 Identifier 't0'
| | - 0 Name 't0' | - 2 Punctuation ')'
|- 6 Newline ' '
|- 7 Values 'VALUES...'
| |- 0 Keyword 'VALUES'
| |- 1 Whitespace ' '
| - 2 Parenthesis '('2000...' | |- 0 Punctuation '(' | |- 1 Single ''2000-...' | - 2 Punctuation ')'
`- 8 Punctuation ';'
None
t1
Tables:
INSERT INTO t1 (t0) VALUES ('2');
I came across the same situation too, and I'm trying to extract table name based on whether t1 in the example is of type Identifier. Since this issue has been open for a few months. Would you kindly confirm is this a bug or not? or what we can do when parsing this kinds of insert statement. thx @andialbrecht
This is a bug. The Parenthesis within an Insert shouldn't be treated as a Function, it's more like a function definition, as you are defining the column names that you will be inserting into and the order that they will be specified.
I don't think it's ever going to be valid to have a function call after INSERT and before a SELECT or VALUES. Checking Oracle and BigQuery SQL references this is true. The same would be true for the INSERT clause of MERGE.
EDIT: I forgot to suggest a fix.
I get Name Punctuation Function (with a schema.table (col1, col2, col3.....) then under Function get Name Whitespace Parenthesis.
What should be returned is probably Name Punctuation Name Whitespace Parenthesis all at the same level. So just don't add the Function while you are within an INSERT clause
I have the same issue, how to solve
Try:
INSERT INTO "t1" (t0) VALUES ('2');
And you will get something like this:
<Identifier '"t1"' at 0x7F6D9AD7CD50>
This solution is not very clean, but it may help
Still an issue @andialbrecht :
INSERT INTO TAB1
(SELECT COL1
, COL2
FROM TAB2
WHERE COL1 = 185
)
TAB1 will be recognized as Function.