0

I'm tring to get the right wildcard (trying [0-9]%) using:

JSON_SEARCH(packages, 'one', 'openstack-neutron-[0-9]%', null, '$.packages[*]')

I just need to get "openstack-neutron-12.1.0-2-el7ost.noarch" but not all the "openstack-neutron-blabla1-14.5.5-el7ost.noarch" "openstack-neutron-blabla2-12.1.0-2-el7ost.noarch" ...

What I'm I doing wrong?

Thanks

davser
  • 85
  • 1
  • 1
  • 9
  • the search patter works like String LIKE and not like regular expassion – nbk Aug 20 '20 at 12:42
  • yes, you are right. But I think [] it's also a like operator or I'm wrong? I saw this link https://www.w3schools.com/sql/sql_wildcards.asp – davser Aug 20 '20 at 14:43
  • it is as i sad wildcars are for strings and how to search them, as it is expalined in the link you provided a search pattern that shows that you want regular expressions )the numbers part), this is possible, but you provioded not enough data examples, so that we can build one for you – nbk Aug 20 '20 at 14:48

1 Answers1

1

So your seachstring must start with openstack-neutron- and end with -12.1.0-2-el7ost.noarch

USE

WHERE JSON_SEARCH(packages, 'one', 'openstack-neutron-%', null, '$.packages[*]') IS NOT NULL 
    AND JSON_SEARCH(packages, 'one', '%-12.1.0-2-el7ost.noarch', null, '$.packages[*]') IS NOT NULL
nbk
  • 45,398
  • 8
  • 30
  • 47
  • thanks for your answer. That way JSON_SEARCH will catch just the "12.1.0-2". I need one that catches just openstack-neutron-. I just need to force that the first character after "neutron-" is a number, but can't find a way. – davser Aug 20 '20 at 14:03
  • please give an example of your json JSON is a string so you can use reguzlar expressions with it, it is onyl more complicated – nbk Aug 20 '20 at 14:26
  • I did try with regex and that worked partially. I'm trying to make a JSON_SEARCH with the 'one' parameter. What that does is he finds the first match and go to next record. Because of that I have to include a regex on the JSON_SEARCH and not after JSON_SEARCH. I don't know how to include regex on JSON_SEARCH. – davser Aug 20 '20 at 14:47
  • as long as you are search especially for numbers there you have lost. so show us the pattern that you used and show us also the json data – nbk Aug 20 '20 at 14:50
  • openstack-neutron-1-el7ost.noarch openstack-neutron-12.1.0-2-el7ost.noarch openstack-neutron-blablabla-el7ost.noarch openstack-neutron-blablabla1-el7ost.noarch openstack-neutron-blablabla2-el7ost.noarch openstack-neutron-blablabla3-el7ost.noarch First two must pass, if I have a number after "neutron-" that's fine. – davser Aug 20 '20 at 15:03
  • i need the **exact** json to find patterns – nbk Aug 20 '20 at 15:08
  • It's huge, I cannot send... I just can send this json example, it's an array by the way {openstack-neutron-1-el7ost.noarch, openstack-neutron-12.1.0-2-el7ost.noarch, openstack-neutron-blablabla-el7ost.noarch, openstack-neutron-blablabla1-el7ost.noarch, openstack-neutron-blablabla2-el7ost.noarch, openstack-neutron-blablabla3-el7ost.noarch} – davser Aug 20 '20 at 15:27