When I search for the Dünyas word with a LIKE operator I can see the results but when I search Dünyası word with LIKE operator, it returns no results. Problem is not ı or ü letters I tried with i and u letters as well.
This query:
select * from DbDivx where NameTurkish like '%Dünyas%' =>
returns:
Boksörün Dünyası
Geleceğin Dünyası
Su Dünyası
However:
select * from DbDivx where NameTurkish like '%Dünyası%' =>
returns nothing.
Can you help me please?
http://sqlfiddle.com/#!6/8c359/1
create table test (someName nvarchar(300))
insert into test (someName)
select N'Boksörün Dünyası'
union all select N'Geleceğin Dünyası'
union all select N'Su Dünyası'
select * from test where someName like N'%Dünyası%'
Not having any issues with the above fiddle. Note that when i inserted data without the N in front of it, the like query did not return results.
hopefully this helps!
Related
The question is about selection from JSON in PostgreSQL.
For example, application contains translation data in jsonb:
{
"en":{
"locale":"en",
"title":"Title",
"textShort":"Short text",
"textFull":"Full text"
}
"ru":{
"locale":"ru",
"title":"Заголовок",
"textShort":"Короткий текст",
"textFull":"Подробный текст"
}
}
This query works successfully:
select *
from content_records
where translations::json->'en'->>'title' like '%Title.';
But this query requires information about the locale, but the case is that we don't know anything about locales and search must be done for every locale, for example:
select *
from content_records
where translations::json->'any locale'->>'title' like '%Title.';
In MySQL it works as:
select *
from content_records
where LOWER(JSON_EXTRACT(translations, '$.*.title')) LIKE LOWER(:title);
There is the similar function in PostgreSQL:
json_extract_path, but it requires keywords and you can't miss the key as the symbol * does in MySQL.
The question is - how to do the selection of a nested JSON in this situation?
Unfortunately, in Postgres you have to "unnest" the keys first.
Something like this:
select t.*, cr.translations
from content_records cr
cross join lateral jsonb_object_keys(translations) as t(locale)
where lower(cr.translations -> t.locale ->> 'title') like '%title';
Note that if a title matches in more than one locale, you will get one row for each matching locale. If you don't want that, you can do the following:
select cr.*
from content_records cr
where exists (select *
from jsonb_object_keys(cr.translations) as t(locale)
where lower(cr.translations -> t.locale ->> 'title') like '%title')
I'm trying to make a query to search items structured as follows:
IssueCategory --* Issue (one to many)
using the following JPQL
select count(z) from IssueCategory z join z.issues x
where
lower(cast(function('lo_get', cast(x.diagnosis as integer)) as text)) like lower(concat('TEXT TO SEARCH', '%'))
where diagnosis is a Issue's String field with #Lob annotation, mapped as a text field in postgres:
CREATE TABLE issues (
...
diagnosis text,
...
)
this query produces the following query
select count(issuecateg0_.id) as col_0_0_
from issue_categories issuecateg0_
inner join issues issues1_ on issuecateg0_.id=issues1_.category_id
where lower(cast(lo_get(cast(issues1_.diagnosis as int4)) as text)) like lower(('TEXT TO SEARCH'||'%'))
Obviously in origin the "TEXT TO SEARCH" was passed as a parameter to the query.
The problem is: when I execute the JPQL query, it returns 0, but if I execute the generated query directly in postgres, I get 1.
Does anyone know of behaviours like this one?
I finally changed to the following conditions:
lower(function('encode', (function('lo_get', cast(x.diagnosis as integer))), 'escape') like lower(concat('TEXT TO SEARCH', '%'))
I have below query:
select 'my.MYNAME=' + name from hostnames;
my.MYNAME=abc
my.MYNAME=xyz
my.MYNAME=poi
The query is dynamic is gives3 result, it may give more result depending upon data.
I need following output:
my.MYNAME1=abc
my.MYNAME2=xyz
my.MYNAME3=poi
Numbers appending to MYNAME according to result it gives.
I have tried
select 'my.MYNAME={c}' + name from hostnames where (select count(*) as c from name);
but it is not working.
One way to go about it is:
SELECT CONCAT(CONCAT(CONCAT('my.MYNAME',ROWNUM),'='), name) FROM hostnames
DEMO
I have created this query:
SELECT *
FROM arrangement, booker
WHERE arrangement.arrangement_id = booker.arrangement_id
AND arrangement.dato BETWEEN '2017-09-29' AND '2017-14-10'
AND booker.dato > '2017-22-09 18:31:53'
AND arrangement.remind = '0'
Both arrangement and booker has a field called 'dato'. I try to use the 'dato' from booker as parameter.
I select 'arrrangement.dato between' that works fine
then I select 'booker.dato <'
However, the 'booker.dato <' fails and run in arrangement.dato when executing the query. Can anyone explain it to me?
use JOIN keyword with ON clause
Ive tried many queries to find... just one word and I can´t even make that.
Its a DB2 database Im using com.ibm.db2.jcc.DB2Driver
This brings me info:
select *
from JL_ENR
where id_ws = '002'
and dc_dy_bsn = '2014-08-25'
and ai_trn = 2331
the JL_TPE column is the CLOB column where I want to find two strings in that search result ( and dc_dy_bsn = '2014-08-25'
and ai_trn = 2331 ).
So first I tried with one:
select
dbms_lob.substr(clob_column,dbms_lob_instr(JL_TPE,'CEMENTO'),1)
from
JL_ENR
where
dbms_lob.instr(JL_TPE,'CEMENTO')>0;
didnt work
SELECT * FROM JL_ENR WHERE dbms_lob.instr(JL_TPE,'CEMENTO')>0
and ai_trn = 2331
and dc_dy_bsn = '2014-08-25'
didnt work
Select *
From JL_ENR
Where NOT
DBMS_LOB.INSTR(JL_TPE, 'CEMENTO', 1, 1) = 0;
didn´t work
Could someone explain me how to find two strings please?
Or a tutorial link where it is explained how to make it work...
Thanks.
Can you provide some sample data and the version you are using? Your example should work (tested on v10.5.0.1):
db2 "create table test ( x int, y clob(1M) )"
db2 "insert into test (x,y) values (1,cast('The string to find is CEMENTO, how do we do that?')"
db2 "insert into test (x,y) values (2,cast('The string to find is CEMENT, how do we do that?' as clob))"
db2 "select x, DBMS_LOB.INSTR(y, 'CEMENTO', 1) from test where DBMS_LOB.INSTR(y, 'CEMENTO', 1) > 0"
X 2
----------- -----------
1 23
1 record(s) selected.
I had to search for a specific value in the where clause. I used TEXTBLOB LIKE '%Search value%' and it worked! This was for db2 in a CLOB(536870912) column.