Requirement
we would like to bring support for contains operator in cps-path.
contains() is a method in XPath expression. It is used when the value of any attribute changes dynamically, below are the examples,
Reference
Issues & decisions
# | Json Data | CPS-PATH Syntax | Decisionoutput |
---|---|---|---|
1 | Below is the sample data , Here are ways to use contains keyword : ]1. | <cps-path> ( contains '[@leafname,' <string-value> ']' )
| english
|
Query format for contains keyword
# | Query | Output | ||||
---|---|---|---|---|---|---|
1 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like '%en%'; | 155 | /bookstore/categories[@code='01']/books[@title='Feersum Endjinn'] | {"lang": "en", "price": 895, "title": "Feersum Endjinn", "authors": ["Iain M. Banks"],
| | | 4 | | 154 | | 5 |
Native Query for contains keyword
1.Using LIKE Keyword :
Like operator is used to match specified matching pattern. It has two signs :
% : Matches any sequence of character, the character size may be 0 or more.
_ : Matches any single character.
# | Query | Output |
---|---|---|
1 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like '%en%'; | { |
699, |
The Golden Compass", |
|
1994 |
|
2 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>' |
---|
lang' |
ilike ' |
%En%'; |
{ |
|
"Iain M. Banks" |
155 | /bookstore/categories[@code='01']/books[@title='Feersum Endjinn'] | {
3 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like 'en'; | { "lang": "en", "price": |
---|
699, "title": " |
The Golden Compass", "authors": [ |
"Philip Pullman" ], "pub_year": |
1995 } |
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.
# | Query | Output |
---|---|---|
1 | cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 3 and attributes->>'pub_year'similar to '%(94|95)%'; | { |
156 | /bookstore/categories[@code='01']/books[@title='Far Horizons'] | {
"lang": "en", |
699, |
The Golden Compass", |
|
1994 |
|