Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
7218aab7
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7218aab7
编写于
10月 20, 2005
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adjust not-too-sane calculation of DDD value for to_char(interval).
Per gripe from Chris Matheson.
上级
8130cbce
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
28 deletion
+34
-28
src/backend/utils/adt/formatting.c
src/backend/utils/adt/formatting.c
+34
-28
未找到文件。
src/backend/utils/adt/formatting.c
浏览文件 @
7218aab7
/* -----------------------------------------------------------------------
* formatting.c
*
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.10
0 2005/10/15 02:49:28 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.10
1 2005/10/20 15:59:46 tgl
Exp $
*
*
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
...
...
@@ -2724,15 +2724,12 @@ static text *
datetime_to_char_body
(
TmToChar
*
tmtc
,
text
*
fmt
,
bool
is_interval
)
{
FormatNode
*
format
;
struct
pg_tm
*
tm
=
NULL
;
char
*
fmt_str
,
*
result
;
bool
incache
;
int
fmt_len
=
VARSIZE
(
fmt
)
-
VARHDRSZ
;
tm
=
tmtcTm
(
tmtc
);
tm
->
tm_wday
=
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
+
1
)
%
7
;
tm
->
tm_yday
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
date2j
(
tm
->
tm_year
,
1
,
1
)
+
1
;
int
reslen
;
text
*
res
;
/*
* Convert fmt to C string
...
...
@@ -2742,9 +2739,10 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
*
(
fmt_str
+
fmt_len
)
=
'\0'
;
/*
* Allocate
result
* Allocate
workspace for result as C string
*/
result
=
palloc
((
fmt_len
*
DCH_MAX_ITEM_SIZ
)
+
1
);
*
result
=
'\0'
;
/*
* Allocate new memory if format picture is bigger than static cache and
...
...
@@ -2790,6 +2788,7 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
format
=
ent
->
format
;
}
/* The real work is here */
DCH_processor
(
format
,
result
,
true
,
is_interval
,
(
void
*
)
tmtc
);
if
(
!
incache
)
...
...
@@ -2797,26 +2796,14 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
pfree
(
fmt_str
);
/*
* for result is allocated max memory, which current format-picture needs,
* now it allocate result with real size
*/
if
(
result
&&
*
result
)
{
int
len
=
strlen
(
result
);
if
(
len
)
{
text
*
res
=
(
text
*
)
palloc
(
len
+
1
+
VARHDRSZ
);
/* convert C-string result to TEXT format */
reslen
=
strlen
(
result
);
res
=
(
text
*
)
palloc
(
reslen
+
VARHDRSZ
);
memcpy
(
VARDATA
(
res
),
result
,
reslen
);
VARATT_SIZEP
(
res
)
=
reslen
+
VARHDRSZ
;
memcpy
(
VARDATA
(
res
),
result
,
len
);
VARATT_SIZEP
(
res
)
=
len
+
VARHDRSZ
;
pfree
(
result
);
return
res
;
}
}
pfree
(
result
);
return
NULL
;
return
res
;
}
/****************************************************************************
...
...
@@ -2834,17 +2821,24 @@ timestamp_to_char(PG_FUNCTION_ARGS)
text
*
fmt
=
PG_GETARG_TEXT_P
(
1
),
*
res
;
TmToChar
tmtc
;
struct
pg_tm
*
tm
;
int
thisdate
;
if
((
VARSIZE
(
fmt
)
-
VARHDRSZ
)
<=
0
||
TIMESTAMP_NOT_FINITE
(
dt
))
PG_RETURN_NULL
();
ZERO_tmtc
(
&
tmtc
);
tm
=
tmtcTm
(
&
tmtc
);
if
(
timestamp2tm
(
dt
,
NULL
,
tm
tcTm
(
&
tmtc
)
,
&
tmtcFsec
(
&
tmtc
),
NULL
,
NULL
)
!=
0
)
if
(
timestamp2tm
(
dt
,
NULL
,
tm
,
&
tmtcFsec
(
&
tmtc
),
NULL
,
NULL
)
!=
0
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DATETIME_VALUE_OUT_OF_RANGE
),
errmsg
(
"timestamp out of range"
)));
thisdate
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
);
tm
->
tm_wday
=
(
thisdate
+
1
)
%
7
;
tm
->
tm_yday
=
thisdate
-
date2j
(
tm
->
tm_year
,
1
,
1
)
+
1
;
if
(
!
(
res
=
datetime_to_char_body
(
&
tmtc
,
fmt
,
false
)))
PG_RETURN_NULL
();
...
...
@@ -2859,17 +2853,24 @@ timestamptz_to_char(PG_FUNCTION_ARGS)
*
res
;
TmToChar
tmtc
;
int
tz
;
struct
pg_tm
*
tm
;
int
thisdate
;
if
((
VARSIZE
(
fmt
)
-
VARHDRSZ
)
<=
0
||
TIMESTAMP_NOT_FINITE
(
dt
))
PG_RETURN_NULL
();
ZERO_tmtc
(
&
tmtc
);
tm
=
tmtcTm
(
&
tmtc
);
if
(
timestamp2tm
(
dt
,
&
tz
,
tm
tcTm
(
&
tmtc
)
,
&
tmtcFsec
(
&
tmtc
),
&
tmtcTzn
(
&
tmtc
),
NULL
)
!=
0
)
if
(
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
tmtcFsec
(
&
tmtc
),
&
tmtcTzn
(
&
tmtc
),
NULL
)
!=
0
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DATETIME_VALUE_OUT_OF_RANGE
),
errmsg
(
"timestamp out of range"
)));
thisdate
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
);
tm
->
tm_wday
=
(
thisdate
+
1
)
%
7
;
tm
->
tm_yday
=
thisdate
-
date2j
(
tm
->
tm_year
,
1
,
1
)
+
1
;
if
(
!
(
res
=
datetime_to_char_body
(
&
tmtc
,
fmt
,
false
)))
PG_RETURN_NULL
();
...
...
@@ -2888,15 +2889,20 @@ interval_to_char(PG_FUNCTION_ARGS)
text
*
fmt
=
PG_GETARG_TEXT_P
(
1
),
*
res
;
TmToChar
tmtc
;
struct
pg_tm
*
tm
;
if
((
VARSIZE
(
fmt
)
-
VARHDRSZ
)
<=
0
)
PG_RETURN_NULL
();
ZERO_tmtc
(
&
tmtc
);
tm
=
tmtcTm
(
&
tmtc
);
if
(
interval2tm
(
*
it
,
tm
tcTm
(
&
tmtc
)
,
&
tmtcFsec
(
&
tmtc
))
!=
0
)
if
(
interval2tm
(
*
it
,
tm
,
&
tmtcFsec
(
&
tmtc
))
!=
0
)
PG_RETURN_NULL
();
/* wday is meaningless, yday approximates the total span in days */
tm
->
tm_yday
=
(
tm
->
tm_year
*
MONTHS_PER_YEAR
+
tm
->
tm_mon
)
*
DAYS_PER_MONTH
+
tm
->
tm_mday
;
if
(
!
(
res
=
datetime_to_char_body
(
&
tmtc
,
fmt
,
true
)))
PG_RETURN_NULL
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录