Skip to content

Commit e6412e1

Browse files
committed
feat: support table-valued function in tsql
1 parent ba42f51 commit e6412e1

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

pegjs/transactsql.pegjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,9 @@ table_base
18141814
type: 'dual'
18151815
};
18161816
}
1817+
/ e:func_call __ alias:alias_clause? {
1818+
return { type: 'expr', expr: e, as: alias };
1819+
}
18171820
/ t:table_name __ tt:temporal_table? __ alias:alias_clause? __ th:table_hint? {
18181821
t.as = alias
18191822
t.table_hint = th

src/column.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function columnRefToSQL(expr) {
6666
function columnDataType(definition) {
6767
if (!definition) return
6868
const { dataType, length, suffix, scale, expr } = definition
69-
let result = dataTypeToSQL({ dataType, length, suffix, scale, parentheses: length != null ? true : false })
69+
const parentheses = length != null && true || false
70+
let result = dataTypeToSQL({ dataType, length, suffix, scale, parentheses })
7071
if (expr) result += exprToSQL(expr)
7172
if (definition.array) {
7273
const arrayExpr = arrayDimensionToSymbol(definition)

test/transactsql.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ describe('transactsql', () => {
436436
'CREATE TABLE [visits] ([url] VARBINARY(max))'
437437
]
438438
},
439+
{
440+
title: 'table-valued function in from clause',
441+
sql: [
442+
"select * from dbo.fn_name(N'000')",
443+
"SELECT * FROM dbo.fn_name(N'000')"
444+
]
445+
},
439446
]
440447
SQL_LIST.forEach(sqlInfo => {
441448
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)