Skip to content

Commit 66792e4

Browse files
committed
🐛 Fix issue with SELECT count(*) for column-based database
When you do a SELECT count(*), SQLite does not request any column, resulting in an empty SELECT for the remote database, which isn't supported by most SQL query engines. To work around this, we arbitrarily add the first column to the SELECT
1 parent eef0cbd commit 66792e4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

module/db_helper.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ func efficientConstructSQLQuery(
144144
cols = append(cols, col.Realname)
145145
}
146146

147+
// If no columns are used, we add the first one
148+
//
149+
// When SQLite does a SELECT count(*), it doesn't use any column, so we need to add at least one column
150+
// because most SQL engines require at least one column in the SELECT clause.
151+
if len(cols) == 0 {
152+
cols = append(cols, columns[0].Realname)
153+
}
154+
147155
query.Select(cols...).From(table)
148156

149157
// Add the constraints (where, limit, offset)

0 commit comments

Comments
 (0)