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

Commit45f64f1

Browse files
committed
Remove CTimeZone/HasCTZSet, root and branch.
These variables no longer have any useful purpose, since there's no reasonto special-case brute force timezones now that we have a validsession_timezone setting for them. Remove the variables, and remove theSET/SHOW TIME ZONE code that deals with them.The user-visible impact of this is that SHOW TIME ZONE will now show aPOSIX-style zone specification, in the form "<+-offset>-+offset", ratherthan an interval value when a brute-force zone has been set. While perhapsless intuitive, this is a better definition than before because it'sactually possible to give that string back to SET TIME ZONE and get thesame behavior, unlike what used to happen.We did not previously mention the angle-bracket syntax when describingPOSIX timezone specifications; add some documentation so that peoplecan figure out what these strings do. (There's still quite a lot ofundocumented functionality there, but anybody who really cares cango read the POSIX spec to find out about it. In practice most peopleseem to prefer Olsen-style city names anyway.)
1 parent1c8a7f6 commit45f64f1

File tree

6 files changed

+31
-98
lines changed

6 files changed

+31
-98
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,11 @@ January 8 04:05:06 1999 PST
24192419
optional daylight-savings zone abbreviation, assumed to stand for one
24202420
hour ahead of the given offset. For example, if <literal>EST5EDT</>
24212421
were not already a recognized zone name, it would be accepted and would
2422-
be functionally equivalent to United States East Coast time. When a
2423-
daylight-savings zone name is present, it is assumed to be used
2422+
be functionally equivalent to United States East Coast time. In this
2423+
syntax, a zone abbreviation can be a string of letters, or an
2424+
arbitrary string surrounded by angle brackets (<literal>&lt;&gt;</>).
2425+
When a daylight-savings zone abbreviation is present,
2426+
it is assumed to be used
24242427
according to the same daylight-savings transition rules used in the
24252428
<literal>zoneinfo</> time zone database's <filename>posixrules</> entry.
24262429
In a standard <productname>PostgreSQL</productname> installation,

‎doc/src/sgml/ref/set.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,16 @@ SELECT setseed(<replaceable>value</replaceable>);
243243
</listitem>
244244
</varlistentry>
245245
</variablelist>
246+
</para>
246247

248+
<para>
249+
Timezone settings given as numbers or intervals are internally
250+
translated to POSIX timezone syntax. For example, after
251+
<literal>SET TIME ZONE -7</>, <command>SHOW TIME ZONE</> would
252+
report <literal>&lt;-07&gt;+07</>.
253+
</para>
254+
255+
<para>
247256
See <xref linkend="datatype-timezones"> for more information
248257
about time zones.
249258
</para>

‎src/backend/commands/variable.c

Lines changed: 14 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -243,34 +243,17 @@ assign_datestyle(const char *newval, void *extra)
243243
* TIMEZONE
244244
*/
245245

246-
typedefstruct
247-
{
248-
pg_tz*session_timezone;
249-
intCTimeZone;
250-
boolHasCTZSet;
251-
}timezone_extra;
252-
253246
/*
254247
* check_timezone: GUC check_hook for timezone
255248
*/
256249
bool
257250
check_timezone(char**newval,void**extra,GucSourcesource)
258251
{
259-
timezone_extramyextra;
252+
pg_tz*new_tz;
253+
longgmtoffset;
260254
char*endptr;
261255
doublehours;
262256

263-
/*
264-
* Initialize the "extra" struct that will be passed to assign_timezone.
265-
* We don't want to change any of the three global variables except as
266-
* specified by logic below. To avoid leaking memory during failure
267-
* returns, we set up the struct contents in a local variable, and only
268-
* copy it to *extra at the end.
269-
*/
270-
myextra.session_timezone=session_timezone;
271-
myextra.CTimeZone=CTimeZone;
272-
myextra.HasCTZSet=HasCTZSet;
273-
274257
if (pg_strncasecmp(*newval,"interval",8)==0)
275258
{
276259
/*
@@ -323,12 +306,11 @@ check_timezone(char **newval, void **extra, GucSource source)
323306

324307
/* Here we change from SQL to Unix sign convention */
325308
#ifdefHAVE_INT64_TIMESTAMP
326-
myextra.CTimeZone=-(interval->time /USECS_PER_SEC);
309+
gmtoffset=-(interval->time /USECS_PER_SEC);
327310
#else
328-
myextra.CTimeZone=-interval->time;
311+
gmtoffset=-interval->time;
329312
#endif
330-
myextra.session_timezone=pg_tzset_offset(myextra.CTimeZone);
331-
myextra.HasCTZSet= true;
313+
new_tz=pg_tzset_offset(gmtoffset);
332314

333315
pfree(interval);
334316
}
@@ -341,17 +323,14 @@ check_timezone(char **newval, void **extra, GucSource source)
341323
if (endptr!=*newval&&*endptr=='\0')
342324
{
343325
/* Here we change from SQL to Unix sign convention */
344-
myextra.CTimeZone=-hours*SECS_PER_HOUR;
345-
myextra.session_timezone=pg_tzset_offset(myextra.CTimeZone);
346-
myextra.HasCTZSet= true;
326+
gmtoffset=-hours*SECS_PER_HOUR;
327+
new_tz=pg_tzset_offset(gmtoffset);
347328
}
348329
else
349330
{
350331
/*
351332
* Otherwise assume it is a timezone name, and try to load it.
352333
*/
353-
pg_tz*new_tz;
354-
355334
new_tz=pg_tzset(*newval);
356335

357336
if (!new_tz)
@@ -367,40 +346,16 @@ check_timezone(char **newval, void **extra, GucSource source)
367346
GUC_check_errdetail("PostgreSQL does not support leap seconds.");
368347
return false;
369348
}
370-
371-
myextra.session_timezone=new_tz;
372-
myextra.HasCTZSet= false;
373349
}
374350
}
375351

376-
/*
377-
* Prepare the canonical string to return.GUC wants it malloc'd.
378-
*
379-
* Note: the result string should be something that we'd accept as input.
380-
* We use the numeric format for interval cases, because it's simpler to
381-
* reload.In the named-timezone case, *newval is already OK and need not
382-
* be changed; it might not have the canonical casing, but that's taken
383-
* care of by show_timezone.
384-
*/
385-
if (myextra.HasCTZSet)
386-
{
387-
char*result= (char*)malloc(64);
388-
389-
if (!result)
390-
return false;
391-
snprintf(result,64,"%.5f",
392-
(double) (-myextra.CTimeZone) / (double)SECS_PER_HOUR);
393-
free(*newval);
394-
*newval=result;
395-
}
396-
397352
/*
398353
* Pass back data for assign_timezone to use
399354
*/
400-
*extra=malloc(sizeof(timezone_extra));
355+
*extra=malloc(sizeof(pg_tz*));
401356
if (!*extra)
402357
return false;
403-
memcpy(*extra,&myextra,sizeof(timezone_extra));
358+
*((pg_tz**)*extra)=new_tz;
404359

405360
return true;
406361
}
@@ -411,43 +366,19 @@ check_timezone(char **newval, void **extra, GucSource source)
411366
void
412367
assign_timezone(constchar*newval,void*extra)
413368
{
414-
timezone_extra*myextra= (timezone_extra*)extra;
415-
416-
session_timezone=myextra->session_timezone;
417-
CTimeZone=myextra->CTimeZone;
418-
HasCTZSet=myextra->HasCTZSet;
369+
session_timezone=*((pg_tz**)extra);
419370
}
420371

421372
/*
422373
* show_timezone: GUC show_hook for timezone
423-
*
424-
* We wouldn't need this, except that historically interval values have been
425-
* shown without an INTERVAL prefix, so the display format isn't what would
426-
* be accepted as input. Otherwise we could have check_timezone return the
427-
* preferred string to begin with.
428374
*/
429375
constchar*
430376
show_timezone(void)
431377
{
432378
constchar*tzn;
433379

434-
if (HasCTZSet)
435-
{
436-
Intervalinterval;
437-
438-
interval.month=0;
439-
interval.day=0;
440-
#ifdefHAVE_INT64_TIMESTAMP
441-
interval.time=-(CTimeZone*USECS_PER_SEC);
442-
#else
443-
interval.time=-CTimeZone;
444-
#endif
445-
446-
tzn=DatumGetCString(DirectFunctionCall1(interval_out,
447-
IntervalPGetDatum(&interval)));
448-
}
449-
else
450-
tzn=pg_get_timezone_name(session_timezone);
380+
/* Always show the zone's canonical name */
381+
tzn=pg_get_timezone_name(session_timezone);
451382

452383
if (tzn!=NULL)
453384
returntzn;
@@ -497,7 +428,7 @@ check_log_timezone(char **newval, void **extra, GucSource source)
497428
*extra=malloc(sizeof(pg_tz*));
498429
if (!*extra)
499430
return false;
500-
memcpy(*extra,&new_tz,sizeof(pg_tz*));
431+
*((pg_tz**)*extra)=new_tz;
501432

502433
return true;
503434
}
@@ -519,6 +450,7 @@ show_log_timezone(void)
519450
{
520451
constchar*tzn;
521452

453+
/* Always show the zone's canonical name */
522454
tzn=pg_get_timezone_name(log_timezone);
523455

524456
if (tzn!=NULL)

‎src/backend/utils/init/globals.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ boolExitOnAnyError = false;
9393
intDateStyle=USE_ISO_DATES;
9494
intDateOrder=DATEORDER_MDY;
9595
intIntervalStyle=INTSTYLE_POSTGRES;
96-
boolHasCTZSet= false;
97-
intCTimeZone=0;
9896

9997
boolenableFsync= true;
10098
boolallowSystemTableMods= false;

‎src/include/miscadmin.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,6 @@ extern intDateOrder;
219219

220220
externintIntervalStyle;
221221

222-
/*
223-
* HasCTZSet is true if user has set timezone as a numeric offset from UTC.
224-
* If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
225-
* sign convention, ie, positive offset is west of UTC, rather than the
226-
* SQL-ish convention that positive is east of UTC).
227-
*/
228-
externboolHasCTZSet;
229-
externintCTimeZone;
230-
231222
#defineMAXTZLEN10/* max TZ name len, not counting tr. null */
232223

233224
externboolenableFsync;

‎src/test/regress/expected/horology.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,9 +2941,9 @@ DETAIL: Value must be in the range -2147483648 to 2147483647.
29412941
SET TIME ZONE 'America/New_York';
29422942
SET TIME ZONE '-1.5';
29432943
SHOW TIME ZONE;
2944-
TimeZone
2945-
----------------------
2946-
@ 1 hour 30 mins ago
2944+
TimeZone
2945+
----------------
2946+
<-01:30>+01:30
29472947
(1 row)
29482948

29492949
SELECT '2012-12-12 12:00'::timestamptz;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp