问题
I have a table with a column of data type bit
.
> CREATE MEMORY TABLE Dummy (name varchar(10), flag bit)
> INSERT INTO Dummy VALUES ('foo', 1)
> INSERT INTO Dummy VALUES ('bar', 0)
> INSERT INTO Dummy VALUES ('foo2', true)
> INSERT INTO Dummy VALUES ('bar2', false)
> select name from Dummy where flag=1
foo2
> select name from Dummy where flag=true
foo2
Why don't I get foo
? How are the 0
and 1
bits converted to booleans? It seems that both are false and I can't differentiate between them.
(By the way, this table is based on one I have in Sybase. The bits 1 and 0 are translated to true and false correctly.)
回答1:
This works as you would expect with HSQLDB 2.2.5, returning two rows.
HSQLDB 2.x supports the BIT type directly and stores bit values. Values B'0' and B'1' can be stored. It translates TRUE and FALSE into 1 and 0 respectively. Integer values 0 and 1 are also translated into bits.
HSQLDB 1.8 translates BIT into BOOLEAN as soon as the column is defined. Conversion from integer may not always work.
来源:https://stackoverflow.com/questions/7581985/selecting-from-a-hsqldb-table-with-a-bit-column