최종 업데이트일: 2016-10-27


[날짜 처리하기] 유닉스타임을 타임스탬프로 변환

select from_unixtime(1477365132)


결과: 

2016-10-25 12:12:12.0



[날짜 처리하기] 타임스탬프에서 년월일만 나오도록 하기

select date_trunc('day', from_unixtime(1477365132))


결과:

2016-10-25 00:00:00.0


[날짜 처리하기] 두 날짜의 차이 구하기

select date_diff( 

'day', 

from_iso8601_timestamp('2016-10-24'),  

from_iso8601_timestamp('2016-10-25')

)

결과: 1




'Presto' 카테고리의 다른 글

Presto에서 base64 데이터 디코딩하기  (0) 2016.08.17
Presto에서 JSON 다루기  (0) 2016.08.12


base64로 인코딩된 데이터를 디코딩하려면

다음 두 함수가 필요하다.


Binary Functions

from_base64(string) → varbinary

Decodes binary data from the base64 encoded string.


String Functions

to_utf8(string) → varbinary

Encodes string into a UTF-8 varbinary representation.



두 함수의 조합으로 다음과 같이 쿼리를 하면 base64 디코딩한 문자열을 얻을 수 있다.


SELECT from_utf8( from_base64 ( my_column ) )

FROM myTable


'Presto' 카테고리의 다른 글

[Presto] 사용팁 정리  (0) 2016.10.27
Presto에서 JSON 다루기  (0) 2016.08.12

Presto 0.151 Documentation에 보면 JSON함수 이야기가 나온다.

내가 필요한 내용 위주로 다시 정리해 본다.



1. 일부 값 추출하기 

  • json_extract( json, json_path )
  • 예) json_extract( json, '$.root.child')


2. "a"인 경우 "제거한 a만 구하기

  • json_extract_scalar( json, json_path )
  • 예) json_extract_scalar( json, '$.root.child')


3. 사이즈 구하기

  • json_size( json, json_path)
  • 예) json_size( json, '$.root' )


나머지 함수에 대한 자료

https://prestodb.io/docs/current/functions/json.html


'Presto' 카테고리의 다른 글

[Presto] 사용팁 정리  (0) 2016.10.27
Presto에서 base64 데이터 디코딩하기  (0) 2016.08.17

+ Recent posts