Is it possible to ignore column when using "Match"? - sqlite

According to SQLite documentation I can write:
SELECT * FROM docs WHERE docs MATCH 'title:linux problems';
Where title is a column name. Is it possible to create something like:
SELECT * FROM docs WHERE docs MATCH 'ignore:linux problems';
To search in all table excluding the linux column?

You can search only in one column or in all columns.
You could try to list all columns except the one you want to ignore:
SELECT * FROM docs WHERE docs MATCH 'col1:linux OR col2:linux OR ...'

You can use a NOT to exclude a column, for example:
SELECT * FROM docs WHERE docs MATCH 'linux problems' NOT ignorecolumnname:'linux problems';
This will match everything but the ignored (NOT) column.
EDIT: apparently this is driver dependent, it works on some but not all.

Related

SQLite FTS search if there's a word that contains string

I want to select all rows that contains an string (for example abc)
example:
abc
abcd
0abc
0abcd
I want all the above to be returned.
My first approach was:
SELECT * FROM notes WHERE notes MATCH '^abc*'
but it returns 0 results.
Second was:
SELECT * FROM notes WHERE notes MATCH '*abc*'
but it returns an error (I belive that asterix can't be used as the first character).
How can I do this?
Thanks in advance
The issue is your usage of ^: your string does not start with abc, so it's not a match. According to SQLite documentation:
MATCH '^one' -- first token in any column must be "one"

Is it possible to select rows if a string column contains any number value?

A particular column in my table is marked as a String type, however, more than likely, it will have an integer value mixed in with the string.
Here are some example rows:
"hello1"
"keys"
"Thom27"
"3for5"
I would like to be able to select the rows that have numbers in the string. Thank you.
You can use GLOB for that:
SELECT *
FROM tblNames
WHERE Name GLOB '*[0-9]*'
GLOB is the best answer (as mentioned above). GLOB supports REGEX like matching, which is more efficient than individual matches with LIKE.

SQLITE: select rows where a certian column is contained in a given string

I have a table which has a column named "directory" which contains strings like:
c:\mydir1\mysubdir1\
c:\mydir2
j:\myotherdir
...
I would like to do something like
SELECT FROM mytable WHERE directory is contained within 'c:\mydir2\something\'
This query should give me as a result:
c:\mydir2
Ok, I've just found that sqlite has a function instr that seems to work for my purpose.
Not sure about the performance, though.

How to use MariaDB's REGEXP_REPLACE?

I have read the docs for MariaDB's REGEX_REPLACE but cannot get my query to work. I am storing links in a column, link and want to change the end of the link:
From www.example.com/<code> to www.example.com/#/results/<code> where <code> is some hexidecimal hash, e.g. 55770abb384c06ee00e0c579. What I am trying is:
SELECT REGEX_REPLACE("link", "www\\.example\\.com\\/(.*)", "www\\.example\\.com\\/#\\/results\\/\\1");
The result is:
Showing rows 0 - 0.
I wasn't able to figure out what the first argument was--the documentation says "subject". Turns out it's just the column name. So this works:
UPDATE my_table
SET my_link = REGEXP_REPLACE(
my_link,
"http:\\/\\/www\\.example\\.com\\/(.*)",
"http:\\/\\/www\\.example\\.com\\/#\\/results\\/\\1")
WHERE my_link IS NOT NULL

Like operation selecting only one row in SQLite

I'm working on SQLite and I want use the LIKE operation in my query and i've used following query
SELECT * from TBL_words where words Like "%ab"
I've more than 10 words which are ends with ab but I'm getting only one word. Am I doing anything wrong? please any one suggest the solution for this, Thanks
LIKE '%ab' will match columns that end exactly in the chars ab. Based on comments you have additional trailing whitespace in some of your words. You can use TRIM(words) in SQL to remove it.

Resources