@@ -3953,6 +3953,26 @@ timestamp_part(PG_FUNCTION_ARGS)
3953
3953
result = date2isoyear (tm -> tm_year , tm -> tm_mon , tm -> tm_mday );
3954
3954
break ;
3955
3955
3956
+ case DTK_DOW :
3957
+ case DTK_ISODOW :
3958
+ if (timestamp2tm (timestamp , NULL , tm , & fsec , NULL , NULL ) != 0 )
3959
+ ereport (ERROR ,
3960
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
3961
+ errmsg ("timestamp out of range" )));
3962
+ result = j2day (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday ));
3963
+ if (val == DTK_ISODOW && result == 0 )
3964
+ result = 7 ;
3965
+ break ;
3966
+
3967
+ case DTK_DOY :
3968
+ if (timestamp2tm (timestamp , NULL , tm , & fsec , NULL , NULL ) != 0 )
3969
+ ereport (ERROR ,
3970
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
3971
+ errmsg ("timestamp out of range" )));
3972
+ result = (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday )
3973
+ - date2j (tm -> tm_year , 1 , 1 ) + 1 );
3974
+ break ;
3975
+
3956
3976
case DTK_TZ :
3957
3977
case DTK_TZ_MINUTE :
3958
3978
case DTK_TZ_HOUR :
@@ -3995,25 +4015,6 @@ timestamp_part(PG_FUNCTION_ARGS)
3995
4015
#endif
3996
4016
break ;
3997
4017
}
3998
- case DTK_DOW :
3999
- case DTK_ISODOW :
4000
- if (timestamp2tm (timestamp , NULL , tm , & fsec , NULL , NULL ) != 0 )
4001
- ereport (ERROR ,
4002
- (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
4003
- errmsg ("timestamp out of range" )));
4004
- result = j2day (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday ));
4005
- if (val == DTK_ISODOW && result == 0 )
4006
- result = 7 ;
4007
- break ;
4008
-
4009
- case DTK_DOY :
4010
- if (timestamp2tm (timestamp , NULL , tm , & fsec , NULL , NULL ) != 0 )
4011
- ereport (ERROR ,
4012
- (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
4013
- errmsg ("timestamp out of range" )));
4014
- result = (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday )
4015
- - date2j (tm -> tm_year , 1 , 1 ) + 1 );
4016
- break ;
4017
4018
4018
4019
default :
4019
4020
ereport (ERROR ,
@@ -4187,6 +4188,26 @@ timestamptz_part(PG_FUNCTION_ARGS)
4187
4188
result = date2isoyear (tm -> tm_year , tm -> tm_mon , tm -> tm_mday );
4188
4189
break ;
4189
4190
4191
+ case DTK_DOW :
4192
+ case DTK_ISODOW :
4193
+ if (timestamp2tm (timestamp , & tz , tm , & fsec , & tzn , NULL ) != 0 )
4194
+ ereport (ERROR ,
4195
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
4196
+ errmsg ("timestamp out of range" )));
4197
+ result = j2day (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday ));
4198
+ if (val == DTK_ISODOW && result == 0 )
4199
+ result = 7 ;
4200
+ break ;
4201
+
4202
+ case DTK_DOY :
4203
+ if (timestamp2tm (timestamp , & tz , tm , & fsec , & tzn , NULL ) != 0 )
4204
+ ereport (ERROR ,
4205
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
4206
+ errmsg ("timestamp out of range" )));
4207
+ result = (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday )
4208
+ - date2j (tm -> tm_year , 1 , 1 ) + 1 );
4209
+ break ;
4210
+
4190
4211
default :
4191
4212
ereport (ERROR ,
4192
4213
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -4208,26 +4229,6 @@ timestamptz_part(PG_FUNCTION_ARGS)
4208
4229
#endif
4209
4230
break ;
4210
4231
4211
- case DTK_DOW :
4212
- case DTK_ISODOW :
4213
- if (timestamp2tm (timestamp , & tz , tm , & fsec , & tzn , NULL ) != 0 )
4214
- ereport (ERROR ,
4215
- (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
4216
- errmsg ("timestamp out of range" )));
4217
- result = j2day (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday ));
4218
- if (val == DTK_ISODOW && result == 0 )
4219
- result = 7 ;
4220
- break ;
4221
-
4222
- case DTK_DOY :
4223
- if (timestamp2tm (timestamp , & tz , tm , & fsec , & tzn , NULL ) != 0 )
4224
- ereport (ERROR ,
4225
- (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
4226
- errmsg ("timestamp out of range" )));
4227
- result = (date2j (tm -> tm_year , tm -> tm_mon , tm -> tm_mday )
4228
- - date2j (tm -> tm_year , 1 , 1 ) + 1 );
4229
- break ;
4230
-
4231
4232
default :
4232
4233
ereport (ERROR ,
4233
4234
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
0 commit comments