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

Commit3e1beda

Browse files
author
Thomas G. Lockhart
committed
Implement precision support for timestamp and time, both with and without
time zones.SQL99 spec requires a default of zero (round to seconds) which is set in gram.y as typmod is set in the parse tree. We *could* change to a default of either 6 (for internal compatibility with previous versions) or 2 (for external compatibility with previous versions).Evaluate entries in pg_proc wrt the iscachable attribute for timestamp and other date/time types. Try to recognize cases where side effects like the current time zone setting may have an effect on results to decide whether something is cachable or not.
1 parenta51de40 commit3e1beda

File tree

22 files changed

+946
-942
lines changed

22 files changed

+946
-942
lines changed

‎src/backend/parser/analyze.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.198 2001/09/07 21:57:53 momjian Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.199 2001/10/03 05:29:12 thomas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -510,11 +510,10 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
510510
* No user-supplied value, so add a targetentry with DEFAULT
511511
* expr and correct data for the target column.
512512
*/
513-
te=makeTargetEntry(
514-
makeResdom(attrno,
513+
te=makeTargetEntry(makeResdom(attrno,
515514
thisatt->atttypid,
516515
thisatt->atttypmod,
517-
pstrdup(NameStr(thisatt->attname)),
516+
pstrdup(NameStr(thisatt->attname)),
518517
false),
519518
stringToNode(defval[ndef].adbin));
520519
qry->targetList=lappend(qry->targetList,te);

‎src/backend/parser/gram.y

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.256 2001/10/02 21:39:35 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.257 2001/10/03 05:29:12 thomas Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -4075,18 +4075,18 @@ opt_numeric: '(' Iconst ',' Iconst ')'
40754075
{
40764076
if ($2 <1 ||$2 > NUMERIC_MAX_PRECISION)
40774077
elog(ERROR,"NUMERIC precision %d must be beween 1 and %d",
4078-
$2, NUMERIC_MAX_PRECISION);
4078+
$2, NUMERIC_MAX_PRECISION);
40794079
if ($4 <0 ||$4 >$2)
40804080
elog(ERROR,"NUMERIC scale %d must be between 0 and precision %d",
4081-
$4,$2);
4081+
$4,$2);
40824082

40834083
$$ = (($2 <<16) |$4) + VARHDRSZ;
40844084
}
40854085
|'('Iconst')'
40864086
{
40874087
if ($2 <1 ||$2 > NUMERIC_MAX_PRECISION)
40884088
elog(ERROR,"NUMERIC precision %d must be beween 1 and %d",
4089-
$2, NUMERIC_MAX_PRECISION);
4089+
$2, NUMERIC_MAX_PRECISION);
40904090

40914091
$$ = ($2 <<16) + VARHDRSZ;
40924092
}
@@ -4163,7 +4163,7 @@ bit: BIT opt_varying
41634163
* SQL92 character data types
41644164
* The following implements CHAR() and VARCHAR().
41654165
*/
4166-
Character:character'('Iconst')'
4166+
Character:character'('Iconst')'opt_charset
41674167
{
41684168
$$ = makeNode(TypeName);
41694169
$$->name =$1;
@@ -4180,34 +4180,37 @@ Character: character '(' Iconst ')'
41804180
* truncate where necessary)
41814181
*/
41824182
$$->typmod = VARHDRSZ +$3;
4183+
4184+
if (($5 !=NULL) && (strcmp($5,"sql_text") !=0)) {
4185+
char *type;
4186+
4187+
type = palloc(strlen($$->name) +1 + strlen($5) +1);
4188+
strcpy(type, $$->name);
4189+
strcat(type,"_");
4190+
strcat(type, $5);
4191+
$$->name = xlateSqlType(type);
4192+
};
41834193
}
4184-
|character
4194+
|characteropt_charset
41854195
{
41864196
$$ = makeNode(TypeName);
41874197
$$->name =$1;
41884198
/* default length, if needed, will be inserted later*/
41894199
$$->typmod = -1;
4190-
}
4191-
;
41924200

4193-
character:CHARACTERopt_varyingopt_charset
4194-
{
4195-
char *type, *c;
4196-
if (($3 ==NULL) || (strcmp($3,"sql_text") ==0)) {
4197-
if ($2) type = xlateSqlType("varchar");
4198-
else type = xlateSqlType("bpchar");
4199-
}else {
4200-
if ($2) {
4201-
c = palloc(strlen("var") + strlen($3) +1);
4202-
strcpy(c,"var");
4203-
strcat(c, $3);
4204-
type = xlateSqlType(c);
4205-
}else {
4206-
type = xlateSqlType($3);
4207-
}
4201+
if (($2 !=NULL) && (strcmp($2,"sql_text") !=0)) {
4202+
char *type;
4203+
4204+
type = palloc(strlen($$->name) +1 + strlen($2) +1);
4205+
strcpy(type, $$->name);
4206+
strcat(type,"_");
4207+
strcat(type, $2);
4208+
$$->name = xlateSqlType(type);
42084209
};
4209-
$$ = type;
42104210
}
4211+
;
4212+
4213+
character:CHARACTERopt_varying{$$ = xlateSqlType($2 ?"varchar":"bpchar"); }
42114214
|CHARopt_varying{$$ = xlateSqlType($2 ?"varchar":"bpchar"); }
42124215
|VARCHAR{$$ = xlateSqlType("varchar"); }
42134216
|NATIONALCHARACTERopt_varying{$$ = xlateSqlType($3 ?"varchar":"bpchar"); }
@@ -4233,6 +4236,22 @@ ConstDatetime: datetime
42334236
$$->name = xlateSqlType($1);
42344237
$$->typmod = -1;
42354238
}
4239+
|TIMESTAMP'('Iconst')'opt_timezone_x
4240+
{
4241+
$$ = makeNode(TypeName);
4242+
if ($5)
4243+
$$->name = xlateSqlType("timestamptz");
4244+
else
4245+
$$->name = xlateSqlType("timestamp");
4246+
/* XXX the timezone field seems to be unused
4247+
* - thomas 2001-09-06
4248+
*/
4249+
$$->timezone =$5;
4250+
if (($3 <0) || ($3 >13))
4251+
elog(ERROR,"TIMESTAMP %s precision %d must be beween 0 and %d",
4252+
($5?" WITH TIME ZONE":""), 0, 13);
4253+
$$->typmod =$3;
4254+
}
42364255
|TIMESTAMPopt_timezone_x
42374256
{
42384257
$$ = makeNode(TypeName);
@@ -4244,7 +4263,19 @@ ConstDatetime: datetime
42444263
* - thomas 2001-09-06
42454264
*/
42464265
$$->timezone =$2;
4247-
$$->typmod = -1;
4266+
$$->typmod =0;
4267+
}
4268+
|TIME'('Iconst')'opt_timezone
4269+
{
4270+
$$ = makeNode(TypeName);
4271+
if ($5)
4272+
$$->name = xlateSqlType("timetz");
4273+
else
4274+
$$->name = xlateSqlType("time");
4275+
if (($3 <0) || ($3 >13))
4276+
elog(ERROR,"TIME %s precision %d must be beween 0 and %d",
4277+
($5?" WITH TIME ZONE":""), 0, 13);
4278+
$$->typmod =$3;
42484279
}
42494280
|TIMEopt_timezone
42504281
{
@@ -4253,7 +4284,10 @@ ConstDatetime: datetime
42534284
$$->name = xlateSqlType("timetz");
42544285
else
42554286
$$->name = xlateSqlType("time");
4256-
$$->typmod = -1;
4287+
/* SQL99 specified a default precision of zero.
4288+
* - thomas 2001-09-30
4289+
*/
4290+
$$->typmod =0;
42574291
}
42584292
;
42594293

@@ -5586,8 +5620,6 @@ ColId: IDENT{ $$ = $1; }
55865620
|NATIONAL{$$ ="national"; }
55875621
|NONE{$$ ="none"; }
55885622
|PATH_P{$$ ="path"; }
5589-
|TIME{$$ ="time"; }
5590-
|TIMESTAMP{$$ ="timestamp"; }
55915623
;
55925624

55935625
/* Parser tokens to be used as identifiers.
@@ -5839,6 +5871,8 @@ ColLabel: ColId{ $$ = $1; }
58395871
|SUBSTRING{$$ ="substring"; }
58405872
|TABLE{$$ ="table"; }
58415873
|THEN{$$ ="then"; }
5874+
|TIME{$$ ="time"; }
5875+
|TIMESTAMP{$$ ="timestamp"; }
58425876
|TO{$$ ="to"; }
58435877
|TRAILING{$$ ="trailing"; }
58445878
|TRANSACTION{$$ ="transaction"; }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp