Can I have a negative tinyint in SQLite?

I need to create a table (in SQLite) with a column that contains either "-1" or "+1". To save memory, it is best not to use "int" as the column type. So, I thought of "small" and "tinyint". But smallint is not so small (from -32,768 to 32,767), and tinyint can only be positive (from 0 to 255). Are there any other options or do I have a choice between the two?

Thanks in advance.

+3
source share
4 answers

Boolean would do a tiny bit of processing in the application to map boolean to -1 or +1.

+5
source

SQLite 3 INTEGER, ...

[...] , 1, 2, 3, 4, 6 8 .

: http://www.sqlite.org/datatype3.html

+6

If your field can only contain two values, why not use the / boolean bit?

+3
source

I recommend that you do what the other answers suggest and use 0/1 or a bit instead, but if you really need to do this, can you distinguish the value from the unsigned byte to char in your code, and then to the signed byte? If you can, then 1 (00000001) discards 1, and 255 (11111111) discards -1

0
source

Source: https://habr.com/ru/post/1719098/


All Articles