Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ddeffb

Browse files
committed
Fix AT TIME ZONE for timestamps without time zones:
test=> select (CURRENT_DATE + '05:00'::time)::timestamp at time zone'Canada/Pacific'; timezone------------------------ 2005-07-22 08:00:00-04(1 row)
1 parent2610265 commit5ddeffb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

‎src/backend/utils/adt/timestamp.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.142 2005/07/22 21:16:15 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.143 2005/07/23 02:02:27 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3922,10 +3922,14 @@ interval_part(PG_FUNCTION_ARGS)
39223922
}
39233923

39243924

3925-
/* timestamp_zone()
3926-
* Encode timestamp type with specified time zone.
3927-
* Returns timestamp with time zone, with the input
3925+
/*timestamp_zone()
3926+
*Encode timestamp type with specified time zone.
3927+
*Returns timestamp with time zone, with the input
39283928
*rotated from local time to the specified zone.
3929+
*This function is tricky because instead of shifting
3930+
*the time _to_ a new time zone, it sets the time to _be_
3931+
*the specified timezone. This requires trickery
3932+
*of double-subtracting the requested timezone offset.
39293933
*/
39303934
Datum
39313935
timestamp_zone(PG_FUNCTION_ARGS)
@@ -3960,14 +3964,17 @@ timestamp_zone(PG_FUNCTION_ARGS)
39603964

39613965
/* Apply the timezone change */
39623966
if (timestamp2tm(timestamp,&tz,&tm,&fsec,NULL,tzp)!=0||
3963-
tm2timestamp(&tm,fsec,NULL,&result)!=0)
3967+
tm2timestamp(&tm,fsec,&tz,&result)!=0)
39643968
{
39653969
ereport(ERROR,
39663970
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
39673971
errmsg("could not convert to time zone \"%s\"",
39683972
tzname)));
39693973
PG_RETURN_NULL();
39703974
}
3975+
/* Must double-adjust for timezone */
3976+
result=dt2local(result,-tz);
3977+
39713978
PG_RETURN_TIMESTAMPTZ(result);
39723979
}
39733980

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp