How to store a year in a database?

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.

+5
source share
2 answers

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.

And the date takes only 4 bytes on disk, no better than this.

integer . 2x 4 .

smallint . . smallint. : PostgreSQL

.

+7

, date_trunc() . date_trunc(), , .

+3

All Articles