如何在此表中将SQL写入子串数据?

时间:2016-09-26 20:27:04

标签: sql postgresql

以下是数据库中1个字段中的数据:

{"image": null, "endDate": "2016-08-26", 
"features": {"Attendee List": true, "Event Feedback": true, "Session Feedback": true}, 
"startDate": "2016-08-25", 
"description": null, "selectedTimeZone": "America/Chicago", "popularityThreshold": 45, "twentyFourHourClockOn": false}

我需要提取“endDate”和“startDate”的值,如下所示:

Select t.somefield, t.startdate(substring()), t.enddate(substring)) from tablename

这样的事情:

value,2016-08-25,2016-08-26

数据库是PostgreSQL。 here's a sample select query

需要一些帮助来编写子字符串(已经有一段时间了),而我只是在编写报告需求的查询。

1 个答案:

答案 0 :(得分:0)

使用Postgres' JSON functions

select (content::json ->> 'startDate')::date as start_date,
       (content::json ->> 'endDate')::date as end_date, 
       e.some_column
from events e