2016-06-13 3 views
1

로 문자열을 변환 I가 다음 쿼리 :포스트 그레스 시간

id | start_date |   ?column?    
------+------------+--------------------------------- 
1573 | 18:00:00 | Mon, 29 Jun 2015 18:00:00 +0000 
1592 | 10:00:00 | Wed, 24 Jun 2015 10:00:00 +0000 
1605 | 18:00:00 | Thu, 25 Jun 2015 18:00:00 +0000 
1571 | 10:00:00 | Mon, 29 Jun 2015 10:00:00 +0000 
1591 | 20:15:00 | Tue, 30 Jun 2015 20:15:00 +0000 
1578 | 18:00:00 | Mon, 29 Jun 2015 20:00:00 +0000 
1620 | 12:00:00 | Sat, 27 Jun 2015 12:00:00 +0000 
(7 rows) 

은 내가 뭘하려고 오전 시간에 occurrence->0->>'startsOn' 변환이기 때문에 예상 된 결과가 있어야한다 : 반환

SELECT id, start_date::TIME, occurrence->0->>'startsOn' FROM service WHERE name='A.F'; 

:

:
id | start_date |   ?column?    
------+------------+--------------------------------- 
1573 | 18:00:00 | 18:00:00 
1592 | 10:00:00 | 10:00:00 
1605 | 18:00:00 | 18:00:00 
1571 | 10:00:00 | 10:00:00 
1591 | 20:15:00 | 20:15:00 
1578 | 18:00:00 | 20:00:00 
1620 | 12:00:00 | 12:00:00 

나는 다음과 같은 시도
SELECT id, start_date::TIME, occurrence->0->>'startsOn'::TIME FROM service WHERE name='A.F'; 

But it is not working as it gives me the following syntax error: 
ERROR: invalid input syntax for type time: "startsOn" 
+2

브래킷을 조롱 ..'(occurrence-> 0 - >> 'startsOn')? :: TIME' –

답변

1
select ('[{"startsOn":"Mon, 29 Jun 2015 18:00:00 +0000"}]'::json->0->>'startsOn')::timestamp::time 

내가 열이 없었는 "발생"내가 당신의 출력에서 ​​