Selecting from a HSQLDB table with a BIT column

孤街醉人 提交于 2019-12-13 18:10:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!