Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Created April 23, 2016 19:06
Show Gist options
  • Select an option

  • Save sebastianwebber/89d8fa8257c8c41dd5174ba04c3040b9 to your computer and use it in GitHub Desktop.

Select an option

Save sebastianwebber/89d8fa8257c8c41dd5174ba04c3040b9 to your computer and use it in GitHub Desktop.
exemplo de trabalhar com dias da semana
sebastian=# CREATE TABLE notas (id serial primary key, ano smallint, semana smallint, nota numeric(5,2));
CREATE TABLE
sebastian=# INSERT into notas (ano, semana, nota) VALUES(2016, 2, 83.7);
INSERT 0 1
sebastian=# SELECT
sebastian-# (ano || '-01-01')::DATE + (semana ||' weeks')::INTERVAL AS data_inicial,
sebastian-# nota
sebastian-# FROM notas;
data_inicial | nota
---------------------+-------
2016-01-15 00:00:00 | 83.70
(1 row)
sebastian=# INSERT into notas (ano, semana, nota) VALUES(2016, 45, 0.7);
INSERT 0 1
sebastian=# SELECT
(ano || '-01-01')::DATE + (semana ||' weeks')::INTERVAL AS data_inicial,
nota
FROM notas;
data_inicial | nota
---------------------+-------
2016-01-15 00:00:00 | 83.70
2016-11-11 00:00:00 | 0.70
(2 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment