Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
6e26c002
Commit
6e26c002
authored
Mar 25, 2005
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix to_date to behave reasonably when CC and YY fields are both used.
Karel Zak
parent
c90578a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
11 deletions
+41
-11
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+12
-1
src/backend/utils/adt/formatting.c
src/backend/utils/adt/formatting.c
+29
-10
No files found.
doc/src/sgml/func.sgml
View file @
6e26c002
<!--
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.24
1 2005/03/14 18:31:19 momjian
Exp $
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.24
2 2005/03/25 16:08:39 tgl
Exp $
PostgreSQL documentation
-->
...
...
@@ -4470,6 +4470,17 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
</para>
</listitem>
<listitem>
<para>
In conversions from string to <type>timestamp</type> or
<type>date</type>, the <literal>CC</literal> field is ignored if there
is a <literal>YYY</literal>, <literal>YYYY</literal> or
<literal>Y,YYY</literal> field. If <literal>CC</literal> is used with
<literal>YY</literal> or <literal>Y</literal> then the year is computed
as <literal>(CC-1)*100+YY</literal>.
</para>
</listitem>
<listitem>
<para>
Millisecond (<literal>MS</literal>) and microsecond (<literal>US</literal>)
...
...
src/backend/utils/adt/formatting.c
View file @
6e26c002
/* -----------------------------------------------------------------------
* formatting.c
*
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.8
4 2005/01/13 01:40:13
tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.8
5 2005/03/25 16:08:40
tgl Exp $
*
*
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
...
...
@@ -379,7 +379,8 @@ typedef struct
cc
,
q
,
j
,
us
;
us
,
yysz
;
/* is it YY or YYYY ? */
}
TmFromChar
;
#define ZERO_tmfc( _X ) memset(_X, 0, sizeof(TmFromChar))
...
...
@@ -390,11 +391,11 @@ typedef struct
*/
#ifdef DEBUG_TO_FROM_CHAR
#define DEBUG_TMFC( _X ) \
elog(DEBUG_elog_output, "TMFC:\nhh %d\nam %d\npm %d\nmi %d\nss %d\nssss %d\nd %d\ndd %d\nddd %d\nmm %d\nms: %d\nyear %d\nbc %d\niw %d\nww %d\nw %d\ncc %d\nq %d\nj %d\nus: %d", \
elog(DEBUG_elog_output, "TMFC:\nhh %d\nam %d\npm %d\nmi %d\nss %d\nssss %d\nd %d\ndd %d\nddd %d\nmm %d\nms: %d\nyear %d\nbc %d\niw %d\nww %d\nw %d\ncc %d\nq %d\nj %d\nus: %d
\nyysz: %d
", \
(_X)->hh, (_X)->am, (_X)->pm, (_X)->mi, (_X)->ss, \
(_X)->ssss, (_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, \
(_X)->year, (_X)->bc, (_X)->iw, (_X)->ww, (_X)->w, \
(_X)->cc, (_X)->q, (_X)->j, (_X)->us);
(_X)->cc, (_X)->q, (_X)->j, (_X)->us
, (_X)->yysz
);
#define DEBUG_TM( _X ) \
elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
(_X)->tm_sec, (_X)->tm_year,\
...
...
@@ -2463,7 +2464,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
sscanf
(
inout
,
"%d,%03d"
,
&
cc
,
&
tmfc
->
year
);
tmfc
->
year
+=
(
cc
*
1000
);
tmfc
->
yysz
=
4
;
return
strdigits_len
(
inout
)
+
3
+
SKIP_THth
(
suf
);
}
break
;
...
...
@@ -2497,11 +2498,13 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
if
(
S_FM
(
suf
)
||
is_next_separator
(
node
))
{
sscanf
(
inout
,
"%d"
,
&
tmfc
->
year
);
tmfc
->
yysz
=
4
;
return
strdigits_len
(
inout
)
-
1
+
SKIP_THth
(
suf
);
}
else
{
sscanf
(
inout
,
"%04d"
,
&
tmfc
->
year
);
tmfc
->
yysz
=
4
;
return
3
+
SKIP_THth
(
suf
);
}
}
...
...
@@ -2537,7 +2540,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
tmfc
->
year
+=
1000
;
else
tmfc
->
year
+=
2000
;
tmfc
->
yysz
=
3
;
return
2
+
SKIP_THth
(
suf
);
}
break
;
...
...
@@ -2572,7 +2575,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
tmfc
->
year
+=
2000
;
else
tmfc
->
year
+=
1900
;
tmfc
->
yysz
=
2
;
return
1
+
SKIP_THth
(
suf
);
}
break
;
...
...
@@ -2603,7 +2606,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
* 1-digit year: always +2000
*/
tmfc
->
year
+=
2000
;
tmfc
->
yysz
=
1
;
return
0
+
SKIP_THth
(
suf
);
}
break
;
...
...
@@ -3171,8 +3174,24 @@ do_to_timestamp(text *date_txt, text *fmt,
}
if
(
tmfc
.
year
)
tm
->
tm_year
=
tmfc
.
year
;
{
if
(
tmfc
.
yysz
==
2
&&
tmfc
.
cc
)
{
/* CC and YY defined
* why -[2000|1900]? See dch_date() DCH_YY code.
*/
tm
->
tm_year
=
(
tmfc
.
cc
-
1
)
*
100
+
(
tmfc
.
year
>=
2000
?
tmfc
.
year
-
2000
:
tmfc
.
year
-
1900
);
}
else
if
(
tmfc
.
yysz
==
1
&&
tmfc
.
cc
)
{
/* CC and Y defined
*/
tm
->
tm_year
=
(
tmfc
.
cc
-
1
)
*
100
+
tmfc
.
year
-
2000
;
}
else
/* set year (and ignore CC if defined) */
tm
->
tm_year
=
tmfc
.
year
;
}
if
(
tmfc
.
bc
)
{
if
(
tm
->
tm_year
>
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment