์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[TIL] Postgresql์—์„œ ํ˜„์žฌ ๋‚ ์งœ ์ถ”์ถœํ•˜๊ธฐ 220922

DATA/SQL

by ์—์Šคํ”„๋ฆฌํ„ฐ 2022. 9. 22. 10:38

๋ณธ๋ฌธ

728x90
๐Ÿ’ก Today I Learned ์š”์•ฝ (10ํšŒ์ฐจ)
- Postgresql์—์„œ ํ˜„์žฌ ๋‚ ์งœ๋ฅผ ์ถ”์ถœํ•˜๊ณ  ์‘์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Postgresql์—์„œ ํ˜„์žฌ ๋‚ ์งœ ์ถ”์ถœํ•˜๊ธฐ

Postgresql์—์„œ๋Š” now()๋ฅผ ํ†ตํ•ด ์‹œ์Šคํ…œ ๋‚ ์งœ๋ฅผ ์ถ”์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

select now();

๊ฐ„ํ˜น Timezone ๋ฌธ์ œ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ํƒ€์ž„์กด๊ณผ ์‹œ๊ฐ„ ํฌ๋งท์„ ์ง€์ •ํ•ด์„œ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.

select (to_char(now() at time zone 'Asia/Seoul', 'YYYY-MM-DD'));

์ด๋ฅผ ๊ฐ€์ง€๊ณ  ์ง์ˆ˜์ผ ํ™€์ˆ˜์ผ์„ ๊ตฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์‘์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

select CASE WHEN cast(to_char(now() at time zone 'Asia/Seoul', 'DD') as int) %2=0 THEN '์ง์ˆ˜์ผ' ELSE 'ํ™€์ˆ˜์ผ' END AS EvenOdd;

 


#SQL ๊ด€๋ จ ์ž‘์„ฑ ๋ฐ ๋ฆฌ์„œ์น˜ ๋‚ด์—ญ:

ํƒœ๊ทธ

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ

๋Œ“๊ธ€ ์˜์—ญ