How are you doing?
I’m currently using PostgreSQL and want to create a 'where'
with just a specif date but the value returns me a kind of timestamp.
Example of the json:
What the json looks like:
{"key1": {"key2": "2023-02-13T13:28:49.087000Z"}}
What I’m doing:
select *
from table
where json(column) -> 'key1' ->> 'key2' = '2023-02-14'
Ps: the json column ‘details’ is in text format so I converted i into json
I want to get the results where the key2 value is ‘2023-02-14’.
2
Answers
You can use the LIKE operator:
Or a bit shorter:
There are 2 steps required to what you you want.
Step 1. Cast string column to json using PostgreSQL json operator and fetch the needed column.
Step 2: use PostgreSQL substring() function to fetch the date part of the string, full query example as below: