SQLite DB Browser: invalid operand for regexp

*爱你&永不变心* 提交于 2021-02-11 07:53:06

问题


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

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