-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sqlite-utils transform/insert --detect-types #179
Comments
SQL query for detecting integers: select
'contains_non_integer' as result
from
mytable
where
cast(cast(mycolumn AS INTEGER) AS TEXT) != mycolumn
limit
1 This will return a single row with a 1 as soon as it comes across a column that contains a non-integer - so it short circuits quickly on TEXT columns with non-integers in them. If everything in the column is an integer it will scan the whole thing before returning no rows. More extensive demo: select
value,
cast(cast(value AS INTEGER) AS TEXT) = value as is_valid_int
from
(
select
'1' as value
union
select
'1.1' as value
union
select
'dog' as value
union
select
null as value
)
|
Posed a question about this on the SQLite forum here: https://sqlite.org/forum/forumpost/ab0dcd66ef |
This recipe looks like it might be the way to detect floats: select
value,
cast(cast(value AS REAL) AS TEXT) in (value, value || '.0') as is_valid_float
from
(
select
'1' as value
union
select
'1.1' as value
union
select
'dog' as value
union
select
null as value
)
|
This work is going to happen in #282. |
Idea from simonw/datasette-edit-schema#13 - provide Python utility methods and accompanying CLI options for detecting the likely types of TEXT columns.
So if you have a text column that actually contained exclusively integer string values, it can let you know and let you run transform against it.
The text was updated successfully, but these errors were encountered: