summaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_coerce.c
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>2001-10-03 05:29:27 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>2001-10-03 05:29:27 +0000
commit3e1beda2cde3495f41290e1ece5d544525810214 (patch)
tree25a07c51bba4a23b3fd4e02261064146bb7c884c /src/backend/parser/parse_coerce.c
parenta51de40fb60c0679d1987c25a2d3e47689be98d5 (diff)
downloadpostgresql-3e1beda2cde3495f41290e1ece5d544525810214.tar.gz
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.
Diffstat (limited to 'src/backend/parser/parse_coerce.c')
-rw-r--r--src/backend/parser/parse_coerce.c227
1 files changed, 14 insertions, 213 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 80164f86b3..e038a08725 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.61 2001/09/28 08:09:09 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.62 2001/10/03 05:29:12 thomas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -287,8 +287,7 @@ coerce_type_typmod(ParseState *pstate, Node *node,
* We assume that only typmod values greater than 0 indicate a forced
* conversion is necessary.
*/
- if (atttypmod <= 0 ||
- atttypmod == exprTypmod(node))
+ if ((atttypmod <= 0) || (atttypmod == exprTypmod(node)))
return node;
funcname = typeidTypeName(targetTypeId);
@@ -376,9 +375,9 @@ select_common_type(List *typeids, const char *context)
Oid ntype = (Oid) lfirsti(l);
/* move on to next one if no new information... */
- if (ntype && (ntype != UNKNOWNOID) && (ntype != ptype))
+ if ((ntype != InvalidOid) && (ntype != UNKNOWNOID) && (ntype != ptype))
{
- if (!ptype || ptype == UNKNOWNOID)
+ if ((ptype == InvalidOid) || ptype == UNKNOWNOID)
{
/* so far, only nulls so take anything... */
ptype = ntype;
@@ -456,6 +455,9 @@ coerce_to_common_type(ParseState *pstate, Node *node,
/* TypeCategory()
* Assign a category to the specified OID.
+ * XXX This should be moved to system catalog lookups
+ * to allow for better type extensibility.
+ * - thomas 2001-09-30
*/
CATEGORY
TypeCategory(Oid inType)
@@ -538,16 +540,22 @@ TypeCategory(Oid inType)
/* IsPreferredType()
* Check if this type is a preferred type.
+ * XXX This should be moved to system catalog lookups
+ * to allow for better type extensibility.
+ * - thomas 2001-09-30
*/
bool
IsPreferredType(CATEGORY category, Oid type)
{
- return type == PreferredType(category, type);
+ return (type == PreferredType(category, type));
} /* IsPreferredType() */
/* PreferredType()
* Return the preferred type OID for the specified category.
+ * XXX This should be moved to system catalog lookups
+ * to allow for better type extensibility.
+ * - thomas 2001-09-30
*/
static Oid
PreferredType(CATEGORY category, Oid type)
@@ -603,210 +611,3 @@ PreferredType(CATEGORY category, Oid type)
}
return result;
} /* PreferredType() */
-
-
-#ifdef NOT_USED
-Oid
-PromoteTypeToNext(Oid inType)
-{
- Oid result;
-
- switch (inType)
- {
- case (CHAROID):
- case (BPCHAROID):
- result = VARCHAROID;
- break;
-
- case (VARCHAROID):
- result = TEXTOID;
- break;
-
- case (INT2OID):
- case (CASHOID):
- result = INT4OID;
- break;
-
- case (INT4OID):
- case (INT8OID):
- case (FLOAT4OID):
- result = FLOAT8OID;
- break;
-
- case (NUMERICOID):
- result = NUMERICOID;
- break;
-
- case (DATEOID):
- result = TIMESTAMPOID;
- break;
-
- case (ABSTIMEOID):
- case (TIMESTAMPOID):
- result = TIMESTAMPTZOID;
- break;
-
- case (TIMEOID):
- case (RELTIMEOID):
- result = INTERVALOID;
- break;
-
- case (BOOLOID):
- case (TEXTOID):
- case (FLOAT8OID):
- case (TIMESTAMPTZOID):
- case (INTERVALOID):
- default:
- result = inType;
- break;
- }
- return result;
-} /* PromoteTypeToNext() */
-
-
-Oid
-DemoteType(Oid inType)
-{
- Oid result;
-
- switch (inType)
- {
- case (FLOAT4OID):
- case (FLOAT8OID):
- result = INT4OID;
- break;
-
- default:
- result = inType;
- break;
- }
- return result;
-} /* DemoteType() */
-
-
-Oid
-PromoteLesserType(Oid inType1, Oid inType2, Oid *newType1, Oid *newType2)
-{
- Oid result;
-
- if (inType1 == inType2)
- {
- result = PromoteTypeToNext(inType1);
- inType1 = result;
- *arg2 = result;
- return result;
- }
-
- kind1 = ClassifyType(inType1);
- kind2 = ClassifyType(*arg2);
- if (kind1 != kind2)
- {
- *newType1 = inType1;
- *newType2 = inType2;
- result = InvalidOid;
- }
-
- isBuiltIn1 = IS_BUILTIN_TYPE(inType1);
- isBuiltIn2 = IS_BUILTIN_TYPE(*arg2);
-
- if (isBuiltIn1 && isBuiltIn2)
- {
- switch (*arg1)
- {
- case (CHAROID):
- switch (*arg2)
- {
- case (BPCHAROID):
- case (VARCHAROID):
- case (TEXTOID):
-
- case (INT2OID):
- case (INT4OID):
- case (FLOAT4OID):
- case (FLOAT8OID):
- case (CASHOID):
-
- case (POINTOID):
- case (LSEGOID):
- case (LINEOID):
- case (BOXOID):
- case (PATHOID):
- case (CIRCLEOID):
- case (POLYGONOID):
-
- case (InvalidOid):
- case (UNKNOWNOID):
- case (BOOLOID):
- default:
- *arg1 = InvalidOid;
- *arg2 = InvalidOid;
- result = InvalidOid;
- }
- }
- }
- else if (isBuiltIn1 && !isBuiltIn2)
- {
- if ((promotedType = PromoteBuiltInType(*arg1)) != *arg1)
- {
- *arg1 = promotedType;
- return promotedType;
- }
- else if (CanCoerceType(*arg1, *arg2))
- {
- *arg1 = *arg2;
- return *arg2;
- }
- }
- else if (!isBuiltIn1 && isBuiltIn2)
- {
- if ((promotedType = PromoteBuiltInType(*arg2)) != *arg2)
- {
- *arg2 = promotedType;
- return promotedType;
- }
- else if (CanCoerceType(*arg2, *arg1))
- {
- *arg2 = *arg1;
- return *arg1;
- }
- }
-
-
- if (*arg2 == InvalidOid)
- return InvalidOid;
-
- switch (*arg1)
- {
- case (CHAROID):
- switch (*arg2)
- {
- case (BPCHAROID):
- case (VARCHAROID):
- case (TEXTOID):
-
- case (INT2OID):
- case (INT4OID):
- case (FLOAT4OID):
- case (FLOAT8OID):
- case (CASHOID):
-
- case (POINTOID):
- case (LSEGOID):
- case (LINEOID):
- case (BOXOID):
- case (PATHOID):
- case (CIRCLEOID):
- case (POLYGONOID):
-
- case (InvalidOid):
- case (UNKNOWNOID):
- case (BOOLOID):
- default:
- *arg1 = InvalidOid;
- *arg2 = InvalidOid;
- result = InvalidOid;
- }
- }
-}
-
-#endif