I have a table with the following structure:
select * from test_table;
id |load_balancer_name |listener_descriptions |
---|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1 |with_cert_1 |[{"Listener": {"Protocol": "HTTPS", "LoadBalancerPort": 443, "InstanceProtocol": "HTTP", "InstancePort": 9005, "SSLCertificateId": "arn:aws:acm:us-west-2:xxxx:certificate/xxx"}, "PolicyNames": ["xxxx"]}] |
2 |with_cert_1 |[{"Listener": {"Protocol": "HTTPS", "LoadBalancerPort": 443, "InstanceProtocol": "HTTP", "InstancePort": 9005, "SSLCertificateId": "arn:aws:acm:us-west-2:xxxx:certificate/xxx"}, "PolicyNames": ["xxxx"]}] |
3 |with_cert_2 |[{"Listener": {"Protocol": "HTTPS", "LoadBalancerPort": 443, "InstanceProtocol": "HTTP", "InstancePort": 9005, "SSLCertificateId": "arn:aws:acm:us-west-2:xxxx:certificate/yyy"}, "PolicyNames": ["xxxx"]}] |
4 |no_cert | |
What I need is to do some searcches based on the listener_descriptions column. To ensure JSON_* method works, I
did this query, that works fine:
select
id, load_balancer_name,
JSON_EXTRACT(listener_descriptions, "$[*].Listener.SSLCertificateId")
from test_table;
id |load_balancer_name |JSON_EXTRACT(listener_descriptions, "$[*].Listener.SSLCertificateId") |
---|-------------------|----------------------------------------------------------------------|
1 |with_cert_1 |["arn:aws:acm:us-west-2:xxxx:certificate/xxx"] |
2 |with_cert_1 |["arn:aws:acm:us-west-2:xxxx:certificate/xxx"] |
3 |with_cert_2 |["arn:aws:acm:us-west-2:xxxx:certificate/yyy"] |
4 |no_cert | |
Now I want to select all rows with matching SSLCertificateId:
select
*
from test_table
where JSON_CONTAINS(listener_descriptions, '"arn:aws:acm:us-west-2:xxxx:certificate/xxx"', "$[*].Listener.SSLCertificateId")
;
But no results found. I have tried with multiple combinations of single and double quotes in the second parameter of JSON_CONTAINS without success.
version() |
-----------------------------------------|
10.3.8-MariaDB-1:10.3.8+maria~bionic-log |
WHERE SSLCertificateId = '...'listener_descriptionsis a list, it can contain multiple objects, soSSLCertificateIdcan be multiple. There are a lot of approaches, most of them better, but...load_balancertable and alistenertable with one listener per row, each referencing itsload_balancer. If you have multiple policies per listener, then a third tablelistener_policywith one policy per row, each referencing its listener.