Search code examples
postgresqlpostgresql-9.6

Convert integer to week interval


How one can convert integer to week interval?

CREATE TABLE integers( i integer);

INSERT INTO integers VALUES ('10');

Output would be table with one column indicating 10 weeks interval.

http://sqlfiddle.com/#!17/4b404/5/0


Solution

  • One take would be to create constant interval of 1 week and multiply it by integer. I would prefer function to do it directly, but I am not aware of it.

    SELECT interval '1 week' * i AS weeks_interval FROM integers;