I am trying to use contains in Nuxeo , I want to search in all the metadata and title and content of the asset
Example If I search
ten
then the search result must return
Content22Jan.jpg
tent24.jpg
.
when I use
select * from table where columnName like 'Con*'
I get the expected response
But If I do
select * from table where columnName like '*ten*'
the search does not return any result
Even
select * from table where columnName like '%ten%'
the search does not return any result
Can someone tell me how to use contains .Even if I pass part of string I should get all the results which matches the search string
Try this:
SELECT * FROM table WHERE dc:columnName LIKE '%ten%'
Read this
Related
I am trying to call a function called account.user_available_sel in PostgreSQL 13 which returns a table of data. It is very simple like this:
SELECT * FROM account.user_available_sel(_email => 'email#xxx.xxx');
The SELECT * part returns back the entire table of data which includes the user's email, password, forename, surname. dob etc.
Because this is only supposed to check if an email has not already been registered, I only want to return a simple value like invalid if a record exists. In my mind something like this (obviously does not work):
SELECT 'invalid' FROM account.user_available_sel(_email => 'email#xxx.xxx');
How could I just return that string instead of the entire recordset?
You can use EXISTS to get a Boolean.
SELECT EXISTS (SELECT *
FROM account.user_available_sel(_email => 'email#xxx.xxx'));
And if that isn't satisfying, you can of course slap a CASE around it and get self defined strings.
SELECT CASE
WHEN EXISTS (SELECT *
FROM account.user_available_sel(_email => 'email#xxx.xxx')) THEN
'existent'
ELSE
'non-existent'
END;
Similarly you can do that for numbers or whatever you like.
I'm using Postgres for my db, and I have a column in my Auction model as a jsonb column. I want to create a query that searches the Auction's json column to see whether a user's name OR email exists in any Auction instance's json column.
Right now I have #auctions = Auction.where('invitees #> ?', {current_user.name.downcase => current_user.email.downcase}.to_json), but that only brings back exact key => value matches I want to know whether the name OR the email exists.
You're using the #> operator. The description for it is this:
“Does the left JSON value contain the right JSON path/value entries
at the top level?”
You probably want the ? operator if you want to return a row when the key (name in your case) matches.
There's not a good way to search for values only in a JSON column (see this answer for more details), but you could check if the key exists alone or the key and value match exists.
The same ActiveRecord methods and chaining apply as when using non-JSON columns, namely where and where(…).or(where(…)):
class Auction
def self.by_invitee(user)
name = user.name.downcase
json = { name => user.email } # note: you should be downcasing emails anyways
where('invitee ? :name', name: name).or(
where('invitee #> :json', json: json)
)
end
end
This is just a temporary patch until I add an Invite model, but casting the invitee column to text I can search the columns. Like so
SELECT * FROM auctions
WHERE data::text LIKE "%#{string I'm searching for}%"
So, AR:
Auction.where('data::text LIKE ?', "%#{string I'm searching for}%")
I ran a query like this:
select urlName from User where urlName like 'Nkj-Fm20%';
Which returns one record.
But when I run a query like this:
select * from User where urlName = 'Nkj-Fm20'
No record is found.
Can you help me?
the like operator allow usage of % jolly character, while the = doesn't. So with your second query it returns only the users with the exact urlName Nkj-Fm20.
Ivan
right now I have a keyword array like:
['key1', 'key2', 'key3'.......] , the keyword can be number or character.
If I want to search in my table (postgres database), and find out all record contain any of keyword in that array, how can I do that?
For example:
I got a table which has a column called name and a column called description
I need find all record that either name or description contains any keywords in that array.
thanks
Maybe this example will be useful:
CREATE TABLE TEST(
FIELD_KEY TEXT);
INSERT INTO TEST VALUES('this is hello');
INSERT INTO TEST VALUES('hello');
INSERT INTO TEST VALUES('this');
INSERT INTO TEST VALUES('other message');
SELECT *
FROM TEST
WHERE FIELD_KEY LIKE ANY (array['%this%', '%hel%']);
This will return:
this is hello
hello
this
Here other example:
SELECT *
FROM TEST
WHERE FIELD_KEY ~* 'this|HEL';
~* is case insensitive, ~ is case sensitive
You can try this example here.
select *
from t
where
array[name] <# my_array
or array[description] <# my_array
Couple the like operator with the any subquery expression:
select *
from t
where name like any (values ('%John%'), ('%Mary%'))
Or the array syntax:
where name like any (array['%John%', '%Mary%'])
I created an index for full text search in postgresql.
CREATE INDEX pesquisa_idx
ON chamado
USING
gin(to_tsvector('portuguese', coalesce(titulo,'') || coalesce(descricao,'')));
When I run this query:
SELECT * FROM chamado WHERE to_tsvector('portuguese', titulo) ## 'ura'
It returned to me some rows.
But when my argument is in all uppercase, no rows are returned. For example:
SELECT * FROM chamado WHERE to_tsvector('portuguese', titulo) ## 'URA'
When the argument is 'ura' I get a few lines; when the argument is 'URA' I do not get any rows.
Why does this happen?
You get no matches in the second case since to_tsvector() lowercases all lexemes. Use to_tsquery() to build the query, it will take care of the case issues as well:
SELECT * FROM chamado WHERE to_tsvector('portuguese', titulo) ## to_tsquery('portuguese', 'URA')