问题
I used DB Browser for SQLite version 3.6.0; SQLite Version 3.8.9.
This application already supports Regular Expression out of box (sqlitebrowser). I can use regexp
on column brand
but failed on column revision
;
For example
SELECT brand,revision FROM TDevice where TDevice.brand regexp '^ASUS$'
and the result is 114 Rows returned from: SELECT brand,revision FROM TDevice WHERE TDevice.brand regexp '^ASUS$'; (took 51ms)
However, if regexp
is applied on different column, then I get the error
SELECT brand,revision FROM TDevice WHERE TDevice.revision regexp '^ASUS$';
and the error message is invalid operand: SELECT brand,revision FROM TDevice WHERE TDevice.revision regexp '^ASUS$';
Both brand and revision are of TEXT type. The table creation schema is as below:
CREATE TABLE `TDevice` (
`id` INTEGER NOT NULL,
`brand` varchar(128) NOT NULL,
`model` varchar(128) NOT NULL,
`revision` TEXT,
PRIMARY KEY(id)
);
回答1:
Both brand and revision are of TEXT type. The table creation schema is as below:
No They are different see your table description correctly if you change the TEXT
to varchar
it will work fine.
Or I will check and inform you how to use regex
or can we use regex
with TEXT
datatype.
or you can convert(CAST) your TEXT
to varchar and can perform the match operations
See this post for how to CAST TEXT into varchar Need to convert Text field to Varchar temporarily so that I can pass to a stored procedure
回答2:
The difference between brand
and revision
is that brand
cannot accept NULL text. After I fill the revision
with empty string '':
UPDATE TDevice SET revision='' WHERE revision IS NULL
, this invalid operand
error is resolved.
来源:https://stackoverflow.com/questions/30643061/sqlite-db-browser-invalid-operand-for-regexp