You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Properly support citext in all string translations #388
In #319 and #384, String.Startswith() and String.Contains() translation was fixed to make it compatible with citext. We still have other method translators which haven't be adapted (EndsWith(), Replace()...).
Do a proper pass over everything and make sure everyone works well, add tests as well.
@roji It seems that String.Startswith() has been fixed in the use case in #319, but only in the case where the database column starts with the supplied string, not the other way around.
Maybe String.Contains also has the same issue? i haven't tried that yet.
Example:
Where the database contains a records with column CompanyName = "some company"
In the output SQL i can see the casts to CITEXT in both the LIKE and LEFT-LENGTH comparisons:
FROM "Companies" AS item
WHERE (item."IsArchived" = FALSE) AND (item."CompanyName" LIKE ($1 || CITEXT '%') AND (CAST(LEFT(item."CompanyName", LENGTH($1)) AS citext) = $1))
ORDER BY LENGTH(item."CompanyName")
LIMIT 1;
(in the output above i have replaced the EF generated parameter with $1 for testing the query)
No results are returned and the generated SQL is missing the required cast on the LEFT-LENGTH part of the query:
FROM "Companies" AS item
WHERE (item."IsArchived" = FALSE) AND ($1 LIKE (item."CompanyName" || CITEXT '%') AND (LEFT($1, LENGTH(item."CompanyName")) = item."CompanyName"))
ORDER BY LENGTH(item."CompanyName") DESC
LIMIT 1;
If i either remove the "AND (LEFT..." comparison or add the required cast it works:
Fixed version:
FROM "Companies" AS item
WHERE (item."IsArchived" = FALSE) AND ($1 LIKE (item."CompanyName" || CITEXT '%') AND (CAST(LEFT($1, LENGTH(item."CompanyName")) AS citext) = item."CompanyName"))
ORDER BY LENGTH(item."CompanyName") DESC
LIMIT 1;
For now i will have to implement some kind of workaround until this is fixed.
I am using Npgsql.EntityFrameworkCore.PostgreSQL version 2.2.0
I appears that in 3.1, #319 seems to have regressed, this worked in 2.1 however testing it in 3.1 shows that CiTextColumn.StartsWith("sometext") is no longer case insensitive, i can see that the generated SQL no longer includes the CAST to citext as shown above.
At least it is now consistent again with CiTextColumn.EndsWith("sometext") which was never fixed.
In 3.1, CiTextColumn.Contains("sometext") still works as it did being case insensitive.
Also there is no change in the behaviour of the reverse scenarios:
"sometext".StartsWith(CiTextColumn) is still case sensitive
"sometext".EndsWith(CiTextColumn) is still case sensitive
However "sometext".Contains(CiTextColumn) works being case insensitive in 3.1, not sure if this worked in 2.1
Here are some example outputs:
In the Examples, Vehicle.Make is a citext column
var test6 = _store.MyEntity.Where(item => item.Vehicle.Make.Contains(testString)).Take(10).ToList(); // works fine
Generated SQL:
WHERE STRPOS(v."Make", @__testString_0) > 0
var test7 = _store.MyEntity.Where(item => item.Vehicle.Make.StartsWith(testString)).Take(10).ToList(); // does perform as case insensitive
Generated SQL:
WHERE (@__testString_0 = '') OR ((v."Make" IS NOT NULL) AND ((v."Make" LIKE v."Make" || '%') AND (LEFT(v."Make", LENGTH(@__testString_0)) = @__testString_0)))
var test8 = _store.MyEntity.Where(item => item.Vehicle.Make.EndsWith(testString)).Take(10).ToList(); // does not perform as case insensitive
Generated SQL:
WHERE (@__testString_0 = '') OR ((v."Make" IS NOT NULL) AND (RIGHT(v."Make", LENGTH(@__testString_0)) = @__testString_0))
// Reverse scenarios:
var test3 = _store.MyEntity.Where(item => testString.Contains(item.Vehicle.Make)).Take(10).ToList(); // works fine
Generated SQL:
WHERE STRPOS(@__testString_0, v."Make") > 0
var test4 = _store.MyEntity.Where(item => testString.StartsWith(item.Vehicle.Make)).Take(10).ToList(); // does not perform as case insensitive
Generated SQL:
WHERE (v."Make" = '') OR ((v."Make" IS NOT NULL) AND ((@__testString_0 LIKE @__testString_0 || '%') AND (LEFT(@__testString_0, LENGTH(v."Make")) = v."Make")))
var test5 = _store.MyEntity.Where(item => testString.EndsWith(item.Vehicle.Make)).Take(10).ToList(); // does not perform as case insensitive
Generated SQL:
WHERE (v."Make" = '') OR ((v."Make" IS NOT NULL) AND (RIGHT(@__testString_0, LENGTH(v."Make")) = v."Make"))
Activity
chrisckc commentedon Mar 30, 2019
@roji It seems that String.Startswith() has been fixed in the use case in #319, but only in the case where the database column starts with the supplied string, not the other way around.
Maybe String.Contains also has the same issue? i haven't tried that yet.
Example:
Where the database contains a records with column CompanyName = "some company"
This works as it was fixed in #319:
In the output SQL i can see the casts to CITEXT in both the LIKE and LEFT-LENGTH comparisons:
(in the output above i have replaced the EF generated parameter with $1 for testing the query)
However this fails:
No results are returned and the generated SQL is missing the required cast on the LEFT-LENGTH part of the query:
If i either remove the "AND (LEFT..." comparison or add the required cast it works:
Fixed version:
For now i will have to implement some kind of workaround until this is fixed.
I am using Npgsql.EntityFrameworkCore.PostgreSQL version 2.2.0
chrisckc commentedon Mar 30, 2019
Using ToLower() on both strings works, but obviously negates the point of using CITEXT
chrisckc commentedon Nov 29, 2019
I appears that in 3.1, #319 seems to have regressed, this worked in 2.1 however testing it in 3.1 shows that CiTextColumn.StartsWith("sometext") is no longer case insensitive, i can see that the generated SQL no longer includes the CAST to citext as shown above.
At least it is now consistent again with CiTextColumn.EndsWith("sometext") which was never fixed.
chrisckc commentedon Nov 29, 2019
In 3.1, CiTextColumn.Contains("sometext") still works as it did being case insensitive.
Also there is no change in the behaviour of the reverse scenarios:
"sometext".StartsWith(CiTextColumn) is still case sensitive
"sometext".EndsWith(CiTextColumn) is still case sensitive
However "sometext".Contains(CiTextColumn) works being case insensitive in 3.1, not sure if this worked in 2.1
chrisckc commentedon Nov 29, 2019
Here are some example outputs:
In the Examples, Vehicle.Make is a citext column
roji commentedon Nov 29, 2019
@chrisckc I'll do my best to look at StartsWith and EndsWith ASAP to make sure that they work as expected in the final 3.1 release.
Fix {Starts,Ends}With and support citext properly
Fix {Starts,Ends}With and support citext properly
Various string method translation fixes
Various string method translation fixes
chrisckc commentedon Dec 2, 2019
My above examples work fine with your commits now, Thanks!
roji commentedon Dec 2, 2019
Thanks for confirming @chrisckc!
Various string method translation fixes