일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- array
- Github
- google apps script
- c#
- GIT
- 파이썬
- gas
- list
- SQL
- dataframe
- PySpark
- django
- PostgreSQL
- Excel
- Apache
- Google Spreadsheet
- Kotlin
- PANDAS
- Mac
- hive
- Tkinter
- math
- Python
- matplotlib
- Google Excel
- Java
- Redshift
- numpy
- string
- Today
- Total
목록SQL (71)
달나라 노트
Redshift에서 json_extract_path_text() 함수를 사용하면 JSON 형태로 존재하는 text를 JSON을 다루듯이 사용할 수 있습니다. Syntax json_extract_path_text(json_text, key1, key2, ...) 사용법은 위와 같습니다. 첫 번째 인자로 JSON 형태의 텍스트를 받습니다. 그리고 두번째부터는 JSON에 있는 key값을 적어주면 됩니다. select '{"apple": 20000, "banana": 8000, "peach": 22000}' as json_string , json_extract_path_text(json_string, 'apple') --> 20000 , json_extract_path_text(json_string, 'bana..
Redshift의 last_day 함수는 특정 날짜가 속한 달의 마지막 날짜를 return해줍니다. Syntax last_day(date or timestamp) 사용법은 간단합니다. parameter로써 날짜 type의 데이터나 timestamp type의 데이터를 받습니다. select last_day(to_date('20230216', 'yyyymmdd')) ; -- Result 2023-02-28 위 예시는 last_day 함수에 20230216이라는 날짜를 전달한 것입니다. (날짜를 전달할 땐 to_date 함수를이용해서 날짜 형식으로 바꿔줍니다.) 결과를 보면 2023년 2월의 마지막 날짜인 2023-02-28이 return됩니다. select last_day(to_date('20230908'..
Table의 생성 시점을 보기 위해선 아래 query를 실행하면 됩니다. select nspname as schema_name , relname as table_name , relcreationtime as creation_time from pg_class_info as pci -- left join pg_namespace as pns on pns.oid = pci.relnamespace -- where pci.reltype != 0 and pns.nspname = 'schema_name' and pci.relname = 'table_name' ;
select *from pg_tables; Redshift에서는 pg_table를 이용하면 database에 있는 table의 종류와 각 tabe의 owner를 알 수 있습니다. 위 쿼리의 output column은 아래 링크를 보면 됩니다.https://www.postgresql.org/docs/8.0/view-pg-tables.html pg_tablesThe view pg_tables provides access to useful information about each table in the database. Table 41-37. pg_tables Columns Name Type References Description schemaname name pg_namespace.nspname name ..