SQLite Forum

Column Type
Login

Column Type

(1) By anonymous on 2020-12-23 19:06:20 [link] [source]

SQL-wise, typeof(column) and coding-wise sqlite3_column_type() report the type for every value in a given column.

Is there a simple way of returning the type of a column, perhaps considering just the top n values? If there are more integer values than text (or any other type of) values, I would want the answer to be integer.

I can do this by grouping typeof() on a column with LIMITing to n records and taking the first type with the maximum occurrence but it seems a little unwieldy.

(2) By Larry Brasfield (LarryBrasfield) on 2020-12-23 23:13:00 in reply to 1 [source]

There is a SQL function called typeof(). Writing a query to effect the decision heuristic you prefer should be simple. However, I think your desire to do so signifies the start of a fight with the SQLite type scheme that would be better avoided by putting the type(s) you intend for each column into the table(s) as original data.