Is there a standard way to store year and month in a database? I need to make several reports by month and year.
I cannot use dates and functions to retrieve months in real time because the tables are huge, so I need preprocessing.
I would go with what Michael offers.
Retrieving the month and year from the date is super fast with EXTRACTor to_char()probably no preprocessing needed.
EXTRACT
to_char()
And the date takes only 4 bytes on disk, no better than this.
integer . 2x 4 .
integer
smallint . . smallint. : PostgreSQL
smallint
.
, date_trunc() . date_trunc(), , .
date_trunc()