-
+
Functions and Operators
dow
- The day of the week (0 - 6; Sunday is 0) (for
- timestamp values only)
+ The day of the week as Sunday(0>) to
+ Saturday(6>)
Result: 5
- Note that extract's day of the week numbering is
+ Note that extract's day of the week numbering is
different from that of the to_char function.
doy
- The day of the year (1 - 365/366) (for timestamp values only)
+ The day of the year (1 - 365/366)
+
+ isodow
+
+ The day of the week as Monday(1>) to
+ Sunday(7>)
+
+
+
+SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
+Result: 7
+
+ This is identical to dow> except for Sunday. This
+ matches the
ISO> 8601 day of the week numbering.
+
+
+
+
+
isoyear
quarter
- The quarter of the year (1 - 4) that the day is in (for
- timestamp values only)
+ The quarter of the year (1 - 4) that the day is in
(
ISO 8601), the first week of a year
contains January 4 of that year. (The
ISO-8601
week starts on Monday.) In other words, the first Thursday of
- a year is in week 1 of that year. (for timestamp values only)
+ a year is in week 1 of that year.
Because of this, it is possible for early January dates to be part of the
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.176 2007/02/16 03:39:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.177 2007/02/19 17:41:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{"h", UNITS, DTK_HOUR}, /* "hour" */
{LATE, RESERV, DTK_LATE}, /* "infinity" reserved for "late time" */
{INVALID, RESERV, DTK_INVALID}, /* "invalid" reserved for bad time */
+ {"isodow", RESERV, DTK_ISODOW}, /* ISO day of week, Sunday == 7 */
{"isoyear", UNITS, DTK_ISOYEAR}, /* year in terms of the ISO week date */
{"j", UNITS, DTK_JULIAN},
{"jan", MONTH, 1},
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.172 2007/02/16 03:39:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.173 2007/02/19 17:41:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
break;
}
case DTK_DOW:
+ case DTK_ISODOW:
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
+ if (val == DTK_ISODOW && result == 0)
+ result = 7;
break;
case DTK_DOY:
break;
case DTK_DOW:
+ case DTK_ISODOW:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
+ if (val == DTK_ISODOW && result == 0)
+ result = 7;
break;
case DTK_DOY:
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/datetime.h,v 1.64 2007/02/16 03:39:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/datetime.h,v 1.65 2007/02/19 17:41:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#define DTK_TZ_HOUR 34
#define DTK_TZ_MINUTE 35
#define DTK_ISOYEAR 36
+#define DTK_ISODOW 37
/*
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.35 2007/02/16 03:39:45 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.36 2007/02/19 17:41:39 momjian Exp $ */
#ifndef DT_H
#define DT_H
#define DTK_TZ_HOUR 34
#define DTK_TZ_MINUTE 35
#define DTK_ISOYEAR 36
+#define DTK_ISODOW 37
/*
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.36 2006/09/26 07:56:56 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.37 2007/02/19 17:41:39 momjian Exp $ */
#include "postgres_fe.h"
{"irkst", DTZ, POS(36)}, /* Irkutsk Summer Time */
{"irkt", TZ, POS(32)}, /* Irkutsk Time */
{"irt", TZ, POS(14)}, /* Iran Time */
+ {"isodow", RESERV, DTK_ISODOW}, /* ISO day of week, Sunday == 7 */
#if 0
isst
#endif