From fee28293e2a1abe139e31347ca2fb865ead46008 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Tue, 3 Sep 2024 14:44:39 -0230 Subject: [PATCH] Chore/empty table errors (#29062) * Fix errors on empty tables * Unnecessary check --- apps/studio/components/grid/query/Query.utils.ts | 1 + apps/studio/data/table-rows/table-rows-query.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/studio/components/grid/query/Query.utils.ts b/apps/studio/components/grid/query/Query.utils.ts index 0fc94056bf9..aeb1cb50de2 100644 --- a/apps/studio/components/grid/query/Query.utils.ts +++ b/apps/studio/components/grid/query/Query.utils.ts @@ -221,6 +221,7 @@ function applySorts(query: string, sorts: Sort[]) { if (sorts.length === 0) return query query += ` order by ${sorts .map((x) => { + if (!x.column) return null const order = x.ascending ? 'asc' : 'desc' const nullOrder = x.nullsFirst ? 'nulls first' : 'nulls last' return `${ident(x.table)}.${ident(x.column)} ${order} ${nullOrder}` diff --git a/apps/studio/data/table-rows/table-rows-query.ts b/apps/studio/data/table-rows/table-rows-query.ts index 7ee33db81d4..58071ebd318 100644 --- a/apps/studio/data/table-rows/table-rows-query.ts +++ b/apps/studio/data/table-rows/table-rows-query.ts @@ -151,7 +151,7 @@ export const getTableRowsSqlQuery = ({ }) // If sorts is empty and table row count is within threshold, use the primary key as the default sort - if (sorts.length === 0 && table.estimateRowCount <= THRESHOLD_COUNT) { + if (sorts.length === 0 && table.estimateRowCount <= THRESHOLD_COUNT && table.columns.length > 0) { const defaultOrderByColumns = getDefaultOrderByColumns(table) if (defaultOrderByColumns.length > 0) { defaultOrderByColumns.forEach((col) => {