Обсуждение: date_part patch

Поиск
Список
Период
Сортировка

date_part patch

От
Marc Balmer
Дата:
Attached is small patch that extends the date_part function to return the
day of week and day of year respectively.

Two new tokens are introduced, weekday and yearday to allow
for the retrieval of the day number since sunday (0-6) or the day
number since january, 1 from a date value.

I use it to retrieve events on specific weekdays, e.g. all events
that occur on mondays:

SELECT * FROM events WHERE date_part('weekday', eventdate) = 1;

The following files are patched:

src/backend/utils/adt/datetime.c:
Extends "units" table to recognize the new tokens

src/backend/utils/adt/timestamp.c:
Extends timestamp2tm() function to return the fields tm_mday and tm_yday
Extends timestamp_part() function to return the day of week or day of year

src/include/utils/datetime.h:
Defines new tokens DTK_WEEKDAY, DTK_YEARDAY


--
Marc Balmer, Micro Systems, Kannenfeldstrasse 32, CH-4056 Basel
Tel +41 61 383 05 10, Fax +41 61 383 05 12, http://www.msys.ch/
Attached is small patch that extends the date_part function to return the
day of week and day of year respectively.

Two new tokens are introduced, weekday and yearday to allow
for the retrieval of the day number since sunday (0-6) or the day
number since january, 1 from a date value.

I use it to retrieve events on specific weekdays, e.g. all events
that occur on mondays:

SELECT * FROM events WHERE date_part('weekday', eventdate) = 1;

The following files are patched:

src/backend/utils/adt/datetime.c:
Extends "units" table to recognize the new tokens

src/backend/utils/adt/timestamp.c:
Extends timestamp2tm() function to return the fields tm_mday and tm_yday
Extends timestamp_part() function to return the day of week or day of year

src/include/utils/datetime.h:
Defines new tokens DTK_WEEKDAY, DTK_YEARDAY

<Der Anhang fehlt>
--
Marc Balmer, Micro Systems, Kannenfeldstrasse 32, CH-4056 Basel
Tel +41 61 383 05 10, Fax +41 61 383 05 12, http://www.msys.ch/

Вложения

Re: date_part patch

От
Peter Eisentraut
Дата:
Marc Balmer writes:

> Attached is small patch that extends the date_part function to return the
> day of week and day of year respectively.

Already exists (dow and doy).

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: date_part patch

От
Thomas Lockhart
Дата:
> > Attached is small patch that extends the date_part function to return the
> > day of week and day of year respectively.
> Already exists (dow and doy).

Mark, is there any compatibility reason to want these other names
(weekday and yearday)? Otherwise, as Peter points out, these do exist.

                    - Thomas