I am using postgres database for my application.
I have below data
create table contacts (
id int,
contact_data jsonb
);
insert into contacts values
(1, '{
"tags": [
"MOCK_DATA (4)"
],
"Email": "[email protected]",
"reach": false,
"Gender": "Male",
"Interest": [
"Dance"
],
"Last Name": "Kynman",
"First Name": "Nicko"
}'),
(2, '{
"ltv": "6",
"City": "Bengaluru",
"Email": "[email protected]",
"State": "Karnataka",
"Country": "India",
"latitude": 12.9715987,
"Last Name": "World",
"longitude": 77.5945627,
"First Name": "Helo"
}'),
(3, '{
"ltv": "11",
"Email": "[email protected]",
"reach": false,
"Gender": "Female",
"Country": "United States",
"latitude": "37.09024",
"Last Name": "Fortye",
"longitude": "-95.712891",
"First Name": "Sissie"
}');
Select * from contacts;
+====+==================================================================================================================================+
| id | contact_data |
+====+==================================================================================================================================+
| 1 | {"tags": ["MOCK_DATA (4)"], "Email": "[email protected]", "reach": false, "Gender": "Male", "Interest": ["Dance"], "Last... |
+----+----------------------------------------------------------------------------------------------------------------------------------+
| 2 | {"ltv": "6", "City": "Bengaluru", "Email": "[email protected]", "State": "Karnataka", "Country": "India", "latitude": 12.9715987, "L... |
+----+----------------------------------------------------------------------------------------------------------------------------------+
| 3 | {"ltv": "11", "Email": "[email protected]", "reach": false, "Gender": "Female", "Country": "United States", "latitude": "3... |
+----+----------------------------------------------------------------------------------------------------------------------------------+
I am trying to fetch id who has ltv between 2 to 9. and it's giving 1 record. which is correct
SELECT id from contacts where ( contact_data->> 'ltv' > '2' and contact_data->> 'ltv' < '9' );
+====+
| id |
+====+
| 2 |
+----+
Issue:
Now i am trying between 2 to 12, which should give 2 records, but it's giving 0 data.
SELECT id from contacts where ( contact_data->> 'ltv' > '2' and contact_data->> 'ltv' < '12' );
Can anyone tell me what's the issue here. why I am not getting the value? here is sql-fiddle