0

If I have a column in a table of zero and nonzero numbers, how do I get the {0,1} truth value of it?

Data

x, y
0, 111
1, 0
2, 444

(sql query, something like select x, TRUTHOF(y) from Data)

Result

x, y_truth
0, 1
1, 0
2, 1

Using sqlite3 in python.

ehacinom
  • 8,070
  • 7
  • 43
  • 65

2 Answers2

2

In SQLite, boolean expressions return 0 or 1, so you can just compare against zero:

SELECT x, y != 0 AS y_truth FROM MyTable
CL.
  • 173,858
  • 17
  • 217
  • 259
1

Er, what about:

SELECT x, not not y FROM Data

I'm not sure I understand the question, though...