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

Commitd0667af

Browse files
committed
Add support for INTERVAL's new typmod values to format_type.
1 parent01b73d3 commitd0667af

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

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

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.19 2001/10/08 19:55:07 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.20 2001/10/23 20:12:54 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -20,12 +20,14 @@
2020
#include"fmgr.h"
2121
#include"catalog/pg_type.h"
2222
#include"utils/builtins.h"
23+
#include"utils/datetime.h"
2324
#include"utils/numeric.h"
2425
#include"utils/syscache.h"
2526
#ifdefMULTIBYTE
2627
#include"mb/pg_wchar.h"
2728
#endif
2829

30+
#defineMASK(b) (1 << (b))
2931

3032
#defineMAX_INT32_LEN 11
3133
#define_textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
@@ -132,7 +134,8 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
132134
if (allow_invalid)
133135
returnpstrdup("???");
134136
else
135-
elog(ERROR,"could not locate data type with oid %u in catalog",type_oid);
137+
elog(ERROR,"could not locate data type with oid %u in catalog",
138+
type_oid);
136139
}
137140

138141
array_base_type= ((Form_pg_type)GETSTRUCT(tuple))->typelem;
@@ -149,7 +152,8 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
149152
if (allow_invalid)
150153
returnpstrdup("???[]");
151154
else
152-
elog(ERROR,"could not locate data type with oid %u in catalog",type_oid);
155+
elog(ERROR,"could not locate data type with oid %u in catalog",
156+
type_oid);
153157
}
154158
is_array= true;
155159
type_oid=array_base_type;
@@ -209,6 +213,73 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
209213
buf=pstrdup("numeric");
210214
break;
211215

216+
caseINTERVALOID:
217+
if (with_typemod)
218+
{
219+
intfields=typemod >>16;
220+
intprecision=typemod&0xFFFF;
221+
constchar*fieldstr;
222+
223+
switch (fields)
224+
{
225+
caseMASK(YEAR):
226+
fieldstr=" year";
227+
break;
228+
caseMASK(MONTH):
229+
fieldstr=" month";
230+
break;
231+
caseMASK(DAY):
232+
fieldstr=" day";
233+
break;
234+
caseMASK(HOUR):
235+
fieldstr=" hour";
236+
break;
237+
caseMASK(MINUTE):
238+
fieldstr=" minute";
239+
break;
240+
caseMASK(SECOND):
241+
fieldstr=" second";
242+
break;
243+
caseMASK(YEAR) |MASK(MONTH):
244+
fieldstr=" year to month";
245+
break;
246+
caseMASK(DAY) |MASK(HOUR):
247+
fieldstr=" day to hour";
248+
break;
249+
caseMASK(DAY) |MASK(HOUR) |MASK(MINUTE):
250+
fieldstr=" day to minute";
251+
break;
252+
caseMASK(DAY) |MASK(HOUR) |MASK(MINUTE) |MASK(SECOND):
253+
fieldstr=" day to second";
254+
break;
255+
caseMASK(HOUR) |MASK(MINUTE):
256+
fieldstr=" hour to minute";
257+
break;
258+
caseMASK(HOUR) |MASK(MINUTE) |MASK(SECOND):
259+
fieldstr=" hour to second";
260+
break;
261+
caseMASK(MINUTE) |MASK(SECOND):
262+
fieldstr=" minute to second";
263+
break;
264+
case0x7FFF:
265+
fieldstr="";
266+
break;
267+
default:
268+
elog(DEBUG,"Invalid INTERVAL typmod 0x%x",typemod);
269+
fieldstr="";
270+
break;
271+
}
272+
if (precision!=0xFFFF)
273+
buf=psnprintf(100,"interval(%d)%s",
274+
precision,fieldstr);
275+
else
276+
buf=psnprintf(100,"interval%s",
277+
fieldstr);
278+
}
279+
else
280+
buf=pstrdup("interval");
281+
break;
282+
212283
caseTIMEOID:
213284
if (with_typemod)
214285
buf=psnprintf(50,"time(%d) without time zone",
@@ -300,7 +371,7 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
300371
int32
301372
type_maximum_size(Oidtype_oid,int32typemod)
302373
{
303-
if (typemod <=0)
374+
if (typemod<0)
304375
return-1;
305376

306377
switch (type_oid)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp