we would like to bring support for contains operator in cps-path.
...
Issues & decisions
Native query for Contains Operator using Like Keyword :
# | Issue | Notes | Decisions | |||||||
---|---|---|---|---|---|---|---|---|---|---|
1 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' ilike '%En%'; | Query Response :
| As per discussion , with Toine Siebelink Prefers Contains Xpath is case sensitive , So ilike keyword would be suitable to implement the contains query which support case sensitive attribute values. Need to discuss with stakeholders. |
# | Json Data | CPS-PATH Syntax | Output | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Below is the sample data , Here are ways to use contains keyword :
| <cps-path>(contains'[@leafname,'<string-value>']')
|
| ||||||||||||||
...
_ : Matches any single character.
# | Query | Output | Decision|||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
1 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like '%en%'; |
| |||||||||
2 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' ilike '%En%'; |
| As per discussion , with Toine Siebelink Contains Xpath is case sensitive , So ilike keyword would be suitable to implement the contains query which support case sensitive attribute values|||||||||
3 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like 'en'; |
|
2.Using SIMILAR TO Regular Expression Keyword :
The only difference between like
and similar to
is to pattern matches the given string. It is similar to LIKE
, except that it interprets the pattern using the SQL standard's definition of a regular expression
SIMILAR TO
supports these pattern-matching metacharacters borrowed from POSIX regular expressions:
|
denotes alternation (either of two alternatives).*
denotes repetition of the previous item zero or more times.+
denotes repetition of the previous item one or more times.?
denotes repetition of the previous item zero or one time.{
m
}
denotes repetition of the previous item exactlym
times.{
m
,}
denotes repetition of the previous itemm
or more times.{
m
,
n
}
denotes repetition of the previous item at leastm
and not more thann
times.Parentheses
()
can be used to group items into a single logical item.A bracket expression
[...]
specifies a character class, just as in POSIX regular expressions.
...