To convert from double to integer, use CAST
:
INSERT INTO MyTable(a, b, c) SELECT a, CAST(b AS INTEGER), c FROM MyTableBackup
CAST
also supports other data types, like TEXT
and REAL
.
Pergunta
I asked a similar question before but I did not get the answer I am looking for. I need some help with implementing rename columns (including datatypes) in Sqlite.
I am aware of the overall steps but need help to deal with various datatype conversions. 1) ALTER TABLE table to table_backup 2) CREATE the required table "table" with renamed columns (datatype) 3) INSERT INTO table using select from table_backup 4) DROP table_backup
Say if I am converting from double to integer, how do I truncate data? Converting double to integer is just one scenario. How to implement other datatype conversions? I am programming in C# if that helps.
Please help!
Solução
To convert from double to integer, use CAST
:
INSERT INTO MyTable(a, b, c) SELECT a, CAST(b AS INTEGER), c FROM MyTableBackup
CAST
also supports other data types, like TEXT
and REAL
.