Skip to content

Commit 00bc37d

Browse files
committed
fix(engine/sqlite): fix table_alias rules
changed rules to conform to fallback directive behavior fix #2271
1 parent d12db53 commit 00bc37d

File tree

6 files changed

+2835
-2426
lines changed

6 files changed

+2835
-2426
lines changed

internal/engine/sqlite/convert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,10 @@ func (c *cc) convertTablesOrSubquery(n []parser.ITable_or_subqueryContext) []ast
769769
alias := from.Table_alias().GetText()
770770
rv.Alias = &ast.Alias{Aliasname: &alias}
771771
}
772+
if from.Table_alias_fallback() != nil {
773+
alias := identifier(from.Table_alias_fallback().GetText())
774+
rv.Alias = &ast.Alias{Aliasname: &alias}
775+
}
772776

773777
tables = append(tables, rv)
774778
} else if from.Table_function_name() != nil {

internal/engine/sqlite/parser/SQLiteParser.g4

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,15 @@ compound_select_stmt:
425425
)+ order_by_stmt? limit_stmt?
426426
;
427427

428-
table_or_subquery: (
429-
(schema_name DOT)? table_name (AS_? table_alias)? (
430-
INDEXED_ BY_ index_name
431-
| NOT_ INDEXED_
432-
)?
433-
)
434-
| (schema_name DOT)? table_function_name OPEN_PAR expr (COMMA expr)* CLOSE_PAR (
435-
AS_? table_alias
436-
)?
428+
table_or_subquery:
429+
(schema_name DOT)? table_name (AS_? table_alias)? (INDEXED_ BY_ index_name | NOT_ INDEXED_)?
430+
| (schema_name DOT)? table_function_name OPEN_PAR expr (COMMA expr)* CLOSE_PAR (AS_? table_alias)?
437431
| OPEN_PAR (table_or_subquery (COMMA table_or_subquery)* | join_clause) CLOSE_PAR
438432
| OPEN_PAR select_stmt CLOSE_PAR (AS_? table_alias)?
433+
| (schema_name DOT)? table_name (AS_? table_alias_fallback)? (INDEXED_ BY_ index_name | NOT_ INDEXED_)?
434+
| (schema_name DOT)? table_function_name OPEN_PAR expr (COMMA expr)* CLOSE_PAR (AS_? table_alias_fallback)?
435+
| OPEN_PAR (table_or_subquery (COMMA table_or_subquery)* | join_clause) CLOSE_PAR
436+
| OPEN_PAR select_stmt CLOSE_PAR (AS_? table_alias_fallback)?
439437
;
440438

441439
result_column:
@@ -875,9 +873,9 @@ savepoint_name:
875873
any_name
876874
;
877875

878-
table_alias:
879-
any_name
880-
;
876+
table_alias: IDENTIFIER | STRING_LITERAL;
877+
878+
table_alias_fallback: any_name;
881879

882880
transaction_name:
883881
any_name

internal/engine/sqlite/parser/SQLiteParser.interp

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)