Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Text to Numbers in SQLite

Tags:

sqlite

I have a sqlite DB with a table with the following structure LocationName Latitude Longitude all defined as varchar. How i can construct a sql statement to get all the locations with a specific lat range given latitude in decimal. is there a way to do that convert from varchar to decimal value on the fly ? or i have to step through the return statements and do the conversion manually

like image 510
user519274 Avatar asked Jan 13 '13 21:01

user519274


People also ask

What is cast in SQLite?

SQLite CAST operator: The CAST operator is used to convert a value from a data type to another data type. For example, if you have a numeric value stored as a string value like this ” '12.5' ” and you want to convert it to be a numeric value you can use the CAST operator to do this like this “CAST( '12.5' AS REAL)“.

What is numeric data type in SQLite?

All "values" in SQLite3 (that is, at the intersection of any row and column) may contain data of any of the following datatypes: INTEGER , a 64-bit signed integer. REAL , a 64-bit IEEE-754 floating point number. TEXT , a bag-o-bytes that conforms to C String semantics containing UTF-8 or UTF-16 encoded data.

What is varchar in SQLite?

You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact. Your content is never truncated. SQLite understands the column type of "VARCHAR(N)" to be the same as "TEXT", regardless of the value of N.

Does SQLite have Boolean?

SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true). SQLite recognizes the keywords "TRUE" and "FALSE", as of version 3.23.


1 Answers

See "CAST expressions" at http://www.sqlite.org/lang_expr.html.

SELECT CAST('3.02' as decimal) -- they aren't real decimals in sqlite, though. beware floats. 
like image 133
Anton Kovalenko Avatar answered Oct 23 '22 03:10

Anton Kovalenko