stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.7k stars 1.56k forks source link

DISTINCT Result Error on Column Names #1049

Closed akaraca closed 3 years ago

akaraca commented 3 years ago

Hi there,

I have a basic DISTINCT query to get the distinct column results. But reading the query results give this error:

SQLite/Query.swift:1113: Fatal error: 'try!' expression unexpectedly raised an error: No such column"Town"in columns ["DISTINCT \"Town\""]

Here is my code:

let townV = Expression<String>("Town")
for item in try! db.prepare(table.select(townV.distinct))  {
      townList.append(item[townV])
  }

Also having another column expression like below didn't work.

let townD = Expression<String>("DISTINCT Town")

Can you point me to right direction? Is there way to read columns by their index number like item[0]?

Thanks a lot.

nathanfallet commented 3 years ago

@akaraca Can you show me where your created your table? There may be a typo or case mistake in column name for example...

nathanfallet commented 3 years ago

Please ask on StackOverflow for this kind of questions (we are tracking bugs on GitHub)