https://stackoverflow.com/questions/5266758/dynamic-column-based-interval
Dynamic (Column Based) Interval
How do I add a dynamic (column based) number of days to NOW? SELECT NOW() + INTERVAL a.number_of_days "DAYS" AS "The Future Date" FROM a; Where a.number_of_days is an integer?
stackoverflow.com
I know this is a year old, but if you need to use a column to specify the actual interval (e.g. 'days', 'months', then it is worth knowing that you can also CAST your string to an Interval, giving:
SELECT now()+ CAST(the_duration||' '||the_interval AS Interval)
SELECT now() + CAST(a.number_of_days||" DAYS" AS Interval) as "The Future Date" FROM a;
'DB > Postgresql' 카테고리의 다른 글
내부조인 외부조인 말고.. (0) | 2020.10.24 |
---|---|
배열형 컬럼 다루기 (0) | 2020.10.06 |
postgres의 문자열 컬럼을 json으로 파싱 후 이용하는 형태 (0) | 2020.06.17 |
PostgreSQL 테이블 용량 확인하기 (0) | 2020.06.15 |
쉘스크립트로 sql파일들 여러개 실행하기 (0) | 2020.04.28 |
댓글