18

I ran sqlite3 on my command prompt and ran some basic SQL commands.

user@comp:~$ sqlite3  
SQLite version 3.8.2 2013-12-06 14:53:30  
Enter ".help" for instructions  
Enter SQL statements terminated with a ";"  
sqlite> CREATE TABLE A (a int, b text, c float);  
sqlite> INSERT INTO A(a,b,c) VALUES (1, '2', 3);  
sqlite> SELECT b::int+2 FROM A;  

All of the lines work except for the last one, which gives the error: `

Error: unrecognized token: ":"`

I was reading from this question (Double colon (::) notation in SQL) that the double colon notation is a type-cast for SQL. Am I doing the operation wrong?

Community
  • 1
  • 1
Abundance
  • 1,963
  • 3
  • 24
  • 46

1 Answers1

39

The :: syntax is PostgreSQL specific. You could use ANSI standard instead:

SELECT CAST(b AS INT) + 2 AS alias
FROM A

SqlFiddleDemo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275