Skip to content

Commit 3f6cd18

Browse files
Merge pull request taozhi8833998#2606 from taozhi8833998/fix-order-index-columns
fix: sqlify index_columns multiple order attributes in pg
2 parents 8158bf1 + b227816 commit 3f6cd18

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/column.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ function columnOption(definition) {
135135
}
136136

137137
function columnOrderToSQL(columnOrder) {
138-
const { column, collate, nulls, opclass, order_by } = columnOrder
139-
const columnExpr = typeof column === 'string' ? { type: 'column_ref', table: columnOrder.table, column } : columnOrder
138+
const { order_by, column, collate, nulls, opclass } = columnOrder
139+
const columnExpr = typeof column === 'string' ? { type: 'column_ref', table: columnOrder.table, column } : ({ ...columnOrder, order_by: null })
140140
columnExpr.collate = null
141141
const result = [
142142
exprToSQL(columnExpr),

src/command.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ function ifToSQL(stmt) {
175175
if (elseifExpr) {
176176
result.push(
177177
elseifExpr.map(
178-
elseif => [toUpper(elseif.type), exprToSQL(elseif.boolean_expr), 'THEN', astToSQL(elseif.then.ast || elseif.then), elseif.semicolon].filter(hasVal).join(' ')
179-
).join(' ')
178+
elseif => [toUpper(elseif.type), exprToSQL(elseif.boolean_expr), 'THEN', astToSQL(elseif.then.ast || elseif.then), elseif.semicolon].filter(hasVal).join(' '),
179+
).join(' '),
180180
)
181181
}
182182
if (elseExpr) result.push('ELSE', `${astToSQL(elseExpr.ast || elseExpr)}${semicolons[1]}`)
@@ -207,7 +207,7 @@ function grantAndRevokeToSQL(stmt) {
207207
case 'priv':
208208
result.push(
209209
literalToSQL(on.object_type),
210-
on.priv_level.map(privLevel => [identifierToSql(privLevel.prefix), identifierToSql(privLevel.name)].filter(hasVal).join('.')).join(', ')
210+
on.priv_level.map(privLevel => [identifierToSql(privLevel.prefix), identifierToSql(privLevel.name)].filter(hasVal).join('.')).join(', '),
211211
)
212212
break
213213
case 'proxy':

src/tables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function unnestToSQL(unnestExpr) {
1313
commonOptionConnector(
1414
toUpper(withOffset && withOffset.keyword),
1515
identifierToSql,
16-
withOffset && withOffset.as
16+
withOffset && withOffset.as,
1717
),
1818
]
1919
return result.filter(hasVal).join(' ')

test/postgres.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,13 @@ describe('Postgres', () => {
23602360
'CREATE TEMP TABLE "test" (id INT, price MONEY)'
23612361
]
23622362
},
2363+
{
2364+
title: 'create index',
2365+
sql: [
2366+
`CREATE INDEX "test" ON "test" USING BTREE ("a" ASC, "b" ASC, "c" DESC);`,
2367+
'CREATE INDEX "test" ON "test" USING BTREE ("a" ASC, "b" ASC, "c" DESC)'
2368+
]
2369+
}
23632370
]
23642371
neatlyNestTestedSQL(SQL_LIST)
23652372
})

0 commit comments

Comments
 (0)