Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
18aee796
Commit
18aee796
authored
18 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Allow timezone names in SQL strings,
'2006-05-24 21:11 Americas/New_York'::timestamptz Joachim Wieland
parent
51dfe351
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/utils/adt/datetime.c
+66
-5
66 additions, 5 deletions
src/backend/utils/adt/datetime.c
with
66 additions
and
5 deletions
src/backend/utils/adt/datetime.c
+
66
−
5
View file @
18aee796
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.16
6
2006/0
3
/0
5 15:58:4
1 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.16
7
2006/0
6
/0
7 22:32:3
1 momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -22,6 +22,7 @@
#include
"access/xact.h"
#include
"miscadmin.h"
#include
"utils/builtins.h"
#include
"utils/datetime.h"
#include
"utils/guc.h"
...
...
@@ -36,6 +37,7 @@ static int DecodeTime(char *str, int fmask, int *tmask,
struct
pg_tm
*
tm
,
fsec_t
*
fsec
);
static
int
DecodeTimezone
(
char
*
str
,
int
*
tzp
);
static
int
DecodePosixTimezone
(
char
*
str
,
int
*
tzp
);
static
int
DecodeZicTimezone
(
char
*
str
,
int
*
tzp
,
struct
pg_tm
*
tm
);
static
datetkn
*
datebsearch
(
char
*
key
,
datetkn
*
base
,
unsigned
int
nel
);
static
int
DecodeDate
(
char
*
str
,
int
fmask
,
int
*
tmask
,
struct
pg_tm
*
tm
);
static
void
TrimTrailingZeros
(
char
*
str
);
...
...
@@ -888,8 +890,24 @@ ParseDateTime(const char *timestr, char *workbuf, size_t buflen,
{
char
delim
=
*
cp
;
ftype
[
nf
]
=
DTK_DATE
;
APPEND_CHAR
(
bufp
,
bufend
,
*
cp
++
);
if
(
*
cp
==
'/'
)
{
ftype
[
nf
]
=
DTK_TZ
;
/* set the first character of the region to upper case
* again*/
field
[
nf
][
0
]
=
pg_toupper
((
unsigned
char
)
field
[
nf
][
0
]);
/* we have seen "Region/" of a POSIX timezone, continue to
* read the City part */
do
{
APPEND_CHAR
(
bufp
,
bufend
,
*
cp
++
);
/* there is for example America/New_York */
}
while
(
isalpha
((
unsigned
char
)
*
cp
)
||
*
cp
==
'_'
);
}
else
{
ftype
[
nf
]
=
DTK_DATE
;
APPEND_CHAR
(
bufp
,
bufend
,
*
cp
++
);
}
while
(
isdigit
((
unsigned
char
)
*
cp
)
||
*
cp
==
delim
)
APPEND_CHAR
(
bufp
,
bufend
,
*
cp
++
);
}
...
...
@@ -980,6 +998,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
bool
haveTextMonth
=
FALSE
;
int
is2digits
=
FALSE
;
int
bc
=
FALSE
;
int
zicTzFnum
=
-
1
;
/*
* We'll insist on at least all of the date fields, but initialize the
...
...
@@ -1127,7 +1146,15 @@ DecodeDateTime(char **field, int *ftype, int nf,
if
(
tzp
==
NULL
)
return
DTERR_BAD_FORMAT
;
dterr
=
DecodeTimezone
(
field
[
i
],
&
tz
);
if
(
strchr
(
field
[
i
],
'/'
)
!=
NULL
)
{
/* remember to apply the timezone at the end */
zicTzFnum
=
i
;
tmask
=
DTK_M
(
TZ
);
break
;
}
else
dterr
=
DecodeTimezone
(
field
[
i
],
&
tz
);
if
(
dterr
)
return
dterr
;
...
...
@@ -1605,6 +1632,19 @@ DecodeDateTime(char **field, int *ftype, int nf,
if
(
tm
->
tm_mday
>
day_tab
[
isleap
(
tm
->
tm_year
)][
tm
->
tm_mon
-
1
])
return
DTERR_FIELD_OVERFLOW
;
if
(
zicTzFnum
!=
-
1
)
{
Datum
tsTz
;
Timestamp
timestamp
;
tm2timestamp
(
tm
,
*
fsec
,
NULL
,
&
timestamp
);
tsTz
=
DirectFunctionCall2
(
timestamp_zone
,
DirectFunctionCall1
(
textin
,
CStringGetDatum
(
field
[
zicTzFnum
])),
TimestampGetDatum
(
timestamp
));
timestamp2tm
(
DatumGetTimestampTz
(
tsTz
),
tzp
,
tm
,
fsec
,
NULL
,
NULL
);
fmask
&=
~
DTK_M
(
TZ
);
}
/* timezone not specified? then find local timezone if possible */
if
(
tzp
!=
NULL
&&
!
(
fmask
&
DTK_M
(
TZ
)))
{
...
...
@@ -1874,7 +1914,15 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
if
(
tzp
==
NULL
)
return
DTERR_BAD_FORMAT
;
dterr
=
DecodeTimezone
(
field
[
i
],
&
tz
);
if
(
strchr
(
field
[
i
],
'/'
)
!=
NULL
)
{
/* a date has to be specified */
if
((
fmask
&
DTK_DATE_M
)
!=
DTK_DATE_M
)
return
DTERR_BAD_FORMAT
;
dterr
=
DecodeZicTimezone
(
field
[
i
],
&
tz
,
tm
);
}
else
dterr
=
DecodeTimezone
(
field
[
i
],
&
tz
);
if
(
dterr
)
return
dterr
;
...
...
@@ -2924,6 +2972,19 @@ DecodePosixTimezone(char *str, int *tzp)
return
0
;
}
static
int
DecodeZicTimezone
(
char
*
str
,
int
*
tzp
,
struct
pg_tm
*
tm
)
{
struct
pg_tz
*
tz
;
tz
=
pg_tzset
(
str
);
if
(
!
tz
)
return
DTERR_BAD_FORMAT
;
*
tzp
=
DetermineTimeZoneOffset
(
tm
,
tz
);
return
0
;
}
/* DecodeSpecial()
* Decode text string using lookup table.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment