Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

#

Json Data

CPS-PATH Syntax

Output

1

Below is the sample data ,
Here  are ways  to use contains keyword : Here  are ways  to use contains keyword :
Code Block
Expand
titleJson data Click here to expand
collapsetrue
{


   "test:bookstore":{


      "bookstore-name": "Chapters",


      "categories": [


         {


            "code": "01",


            "name": "SciFi",


            "books": [


               {


                  "authors": [


                     "Iain M. Banks"


                  ],


                  "lang": "english",


                  "price": "895",


                  "pub_year": "1994",


                  "title": "Feersum Endjinn"


               }


            ]


         },


         {


            "name": "kids",


            "code": "02",


            "books": [


               {


                  "authors": [


                     "Philip Pullman"


                  ],


                  "lang": "Science",


                  "price": "699",


                  "pub_year": "1995",


                  "title": "The Golden Compass"


               }


            ]


         }


    ]


   }


}
<cps-path>(contains'[@leafname,'<string-value>']')

Examples
  • //books[contains(@lang,'en')
  • //books[contains(@pub_year,'99')


Expandcode
titleJson Response Click here to expand
collapsetrue
{


 "lang": "en", 


 "price": 895, 


 "title": "Feersum Endjinn", 


 "authors": [


            "Iain M. Banks"


 ], 


"pub_year":1994


}  


{


 "lang": "en", 


 "price": 699, 


 "title": "The Golden Compass", 


 "authors": [


           "Philip Pullman"


 ], 


"pub_year":1995


}            
 

                                                                                                      
                                                                                       

...

_ : Matches any single character.

#

Query

Output

Decision
1

cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like '%en%';



Expandcode
titleJson Response Click here to expand..
collapsetrue
{


 "lang": "en", 


 "price": 699, 


 "title": "The Golden Compass", 


 "authors": [


           "Philip Pullman"


 ], 


"pub_year":1995


                                                                                               


{


 "lang": "english", 


 "price": 895, 


 "title": "Feersum Endjinn", 


 "authors": [


            "Iain M. Banks"


 ], 


"pub_year":1994


}    
            



2cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' ilike '%En%';


Expandcode
titleJson Response Click here to expand
collapsetrue
{


 "lang": "en", 


 "price": 699, 


 "title": "The Golden Compass", 


 "authors": [


           "Philip Pullman"


 ], 


"pub_year":1995


                                                                                               


{


 "lang": "English", 


 "price": 895, 


 "title": "Feersum Endjinn", 


 "authors": [


            "Iain M. Banks"


 ], 


"pub_year":1994


}              


  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

3cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like 'en';


Expandcode
titleJson Response Click here to expand
collapsetrue
{


 "lang": "en", 


 "price": 699, 


 "title": "The Golden Compass", 


 "authors": [


           "Philip Pullman"


 ], 


"pub_year":1995


          



2.Using SIMILAR TO Regular Expression Keyword :

...

#

Query

Output

1cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 3 and attributes->>'pub_year'similar to '%(94|95)%';


Expandcode
titleJson Response Click here to expand
{


 "lang": "en", 


 "price": 699, 


 "title": "The Golden Compass", 


 "authors": [


           "Philip Pullman"


 ], 


"pub_year":1995


                                                                                              


{


 "lang": "english", 


 "price": 895, 


 "title": "Feersum Endjinn", 


 "authors": [


            "Iain M. Banks"


 ], 


"pub_year":1994


}              


Performance wise : As we are not making much changes for query , the performance is similar to existing query will not effect much

...