Commit b6a1d25b authored by Tom Lane's avatar Tom Lane

Error message editing in utils/adt. Again thanks to Joe Conway for doing

the bulk of the heavy lifting ...
parent 524cfad2
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.91 2003/06/27 00:33:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.92 2003/07/27 04:53:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -90,8 +90,12 @@ getid(const char *s, char *n) ...@@ -90,8 +90,12 @@ getid(const char *s, char *n)
else else
{ {
if (len >= NAMEDATALEN-1) if (len >= NAMEDATALEN-1)
elog(ERROR, "identifier must be less than %d characters", ereport(ERROR,
NAMEDATALEN); (errcode(ERRCODE_NAME_TOO_LONG),
errmsg("identifier too long"),
errdetail("Identifier must be less than %d characters.",
NAMEDATALEN)));
n[len++] = *s; n[len++] = *s;
} }
} }
...@@ -157,26 +161,34 @@ aclparse(const char *s, AclItem *aip) ...@@ -157,26 +161,34 @@ aclparse(const char *s, AclItem *aip)
Assert(s && aip); Assert(s && aip);
#ifdef ACLDEBUG #ifdef ACLDEBUG
elog(LOG, "aclparse: input = '%s'", s); elog(LOG, "aclparse: input = \"%s\"", s);
#endif #endif
idtype = ACL_IDTYPE_UID; idtype = ACL_IDTYPE_UID;
s = getid(s, name); s = getid(s, name);
if (*s != '=') if (*s != '=')
{ {
/* we just read a keyword, not a name */ /* we just read a keyword, not a name */
if (strncmp(name, ACL_IDTYPE_GID_KEYWORD, sizeof(name)) == 0) if (strcmp(name, ACL_IDTYPE_GID_KEYWORD) == 0)
idtype = ACL_IDTYPE_GID; idtype = ACL_IDTYPE_GID;
else if (strncmp(name, ACL_IDTYPE_UID_KEYWORD, sizeof(name)) != 0) else if (strcmp(name, ACL_IDTYPE_UID_KEYWORD) != 0)
elog(ERROR, "aclparse: bad keyword, must be [group|user]"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("unrecognized keyword: \"%s\"", name),
errhint("ACL keyword must be \"group\" or \"user\".")));
s = getid(s, name); /* move s to the name beyond the keyword */ s = getid(s, name); /* move s to the name beyond the keyword */
if (name[0] == '\0') if (name[0] == '\0')
elog(ERROR, "aclparse: a name must follow the [group|user] keyword"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing name"),
errhint("A name must follow the [group|user] keyword.")));
} }
if (name[0] == '\0') if (name[0] == '\0')
idtype = ACL_IDTYPE_WORLD; idtype = ACL_IDTYPE_WORLD;
if (*s != '=') if (*s != '=')
elog(ERROR, "aclparse: expecting \"=\" sign"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing \"=\" sign")));
privs = goption = ACL_NO_RIGHTS; privs = goption = ACL_NO_RIGHTS;
...@@ -221,8 +233,10 @@ aclparse(const char *s, AclItem *aip) ...@@ -221,8 +233,10 @@ aclparse(const char *s, AclItem *aip)
read = ACL_CREATE_TEMP; read = ACL_CREATE_TEMP;
break; break;
default: default:
elog(ERROR, "aclparse: mode flags must use \"%s\"", ereport(ERROR,
ACL_ALL_RIGHTS_STR); (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid mode character: must be one of \"%s\"",
ACL_ALL_RIGHTS_STR)));
} }
privs |= read; privs |= read;
...@@ -247,14 +261,18 @@ aclparse(const char *s, AclItem *aip) ...@@ -247,14 +261,18 @@ aclparse(const char *s, AclItem *aip)
{ {
s = getid(s + 1, name2); s = getid(s + 1, name2);
if (name2[0] == '\0') if (name2[0] == '\0')
elog(ERROR, "aclparse: a name must follow the \"/\" sign"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("a name must follow the \"/\" sign")));
aip->ai_grantor = get_usesysid(name2); aip->ai_grantor = get_usesysid(name2);
} }
else else
{ {
aip->ai_grantor = BOOTSTRAP_USESYSID; aip->ai_grantor = BOOTSTRAP_USESYSID;
elog(WARNING, "defaulting grantor to %u", BOOTSTRAP_USESYSID); ereport(WARNING,
(errcode(ERRCODE_INVALID_GRANTOR),
errmsg("defaulting grantor to %u", BOOTSTRAP_USESYSID)));
} }
ACLITEM_SET_PRIVS_IDTYPE(*aip, privs, goption, idtype); ACLITEM_SET_PRIVS_IDTYPE(*aip, privs, goption, idtype);
...@@ -280,7 +298,7 @@ allocacl(int n) ...@@ -280,7 +298,7 @@ allocacl(int n)
Size size; Size size;
if (n < 0) if (n < 0)
elog(ERROR, "allocacl: invalid size: %d", n); elog(ERROR, "invalid size: %d", n);
size = ACL_N_SIZE(n); size = ACL_N_SIZE(n);
new_acl = (Acl *) palloc0(size); new_acl = (Acl *) palloc0(size);
new_acl->size = size; new_acl->size = size;
...@@ -311,7 +329,10 @@ aclitemin(PG_FUNCTION_ARGS) ...@@ -311,7 +329,10 @@ aclitemin(PG_FUNCTION_ARGS)
while (isspace((unsigned char) *s)) while (isspace((unsigned char) *s))
++s; ++s;
if (*s) if (*s)
elog(ERROR, "aclitemin: extra garbage at end of specification"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("extra garbage at the end of the ACL specification")));
PG_RETURN_ACLITEM_P(aip); PG_RETURN_ACLITEM_P(aip);
} }
...@@ -373,8 +394,8 @@ aclitemout(PG_FUNCTION_ARGS) ...@@ -373,8 +394,8 @@ aclitemout(PG_FUNCTION_ARGS)
case ACL_IDTYPE_WORLD: case ACL_IDTYPE_WORLD:
break; break;
default: default:
elog(ERROR, "aclitemout: bad idtype: %d", elog(ERROR, "unrecognized idtype: %d",
ACLITEM_GET_IDTYPE(*aip)); (int) ACLITEM_GET_IDTYPE(*aip));
break; break;
} }
while (*p) while (*p)
...@@ -482,7 +503,7 @@ acldefault(GrantObjectType objtype, AclId ownerid) ...@@ -482,7 +503,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
owner_default = ACL_ALL_RIGHTS_NAMESPACE; owner_default = ACL_ALL_RIGHTS_NAMESPACE;
break; break;
default: default:
elog(ERROR, "acldefault: bogus objtype %d", (int) objtype); elog(ERROR, "unrecognized objtype: %d", (int) objtype);
world_default = ACL_NO_RIGHTS; /* keep compiler quiet */ world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
owner_default = ACL_NO_RIGHTS; owner_default = ACL_NO_RIGHTS;
break; break;
...@@ -644,7 +665,10 @@ restart: ...@@ -644,7 +665,10 @@ restart:
AclItem mod_acl; AclItem mod_acl;
if (behavior == DROP_RESTRICT) if (behavior == DROP_RESTRICT)
elog(ERROR, "dependent privileges exist (use CASCADE to revoke them too)"); ereport(ERROR,
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
errmsg("dependent privileges exist"),
errhint("Use CASCADE to revoke them too.")));
mod_acl.ai_grantor = grantee; mod_acl.ai_grantor = grantee;
mod_acl.ai_grantee = aip[i].ai_grantee; mod_acl.ai_grantee = aip[i].ai_grantee;
...@@ -718,7 +742,9 @@ aclremove(PG_FUNCTION_ARGS) ...@@ -718,7 +742,9 @@ aclremove(PG_FUNCTION_ARGS)
new_aip = ACL_DAT(new_acl); new_aip = ACL_DAT(new_acl);
if (dst == 0) if (dst == 0)
{ /* start */ { /* start */
elog(ERROR, "aclremove: removal of the world ACL??"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot remove the world ACL")));
} }
else if (dst == old_num - 1) else if (dst == old_num - 1)
{ /* end */ { /* end */
...@@ -784,7 +810,9 @@ makeaclitem(PG_FUNCTION_ARGS) ...@@ -784,7 +810,9 @@ makeaclitem(PG_FUNCTION_ARGS)
} }
else if (u_grantee != 0 && g_grantee != 0) else if (u_grantee != 0 && g_grantee != 0)
{ {
elog(ERROR, "cannot specify both user and group"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot specify both user and group")));
} }
else if (u_grantee != 0) else if (u_grantee != 0)
{ {
...@@ -840,7 +868,9 @@ convert_priv_string(text *priv_type_text) ...@@ -840,7 +868,9 @@ convert_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "TEMPORARY") == 0) if (strcasecmp(priv_type, "TEMPORARY") == 0)
return ACL_CREATE_TEMP; return ACL_CREATE_TEMP;
elog(ERROR, "invalid privilege type %s", priv_type); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */ return ACL_NO_RIGHTS; /* keep compiler quiet */
} }
...@@ -1063,8 +1093,9 @@ convert_table_priv_string(text *priv_type_text) ...@@ -1063,8 +1093,9 @@ convert_table_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "TRIGGER WITH GRANT OPTION") == 0) if (strcasecmp(priv_type, "TRIGGER WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_TRIGGER); return ACL_GRANT_OPTION_FOR(ACL_TRIGGER);
elog(ERROR, "has_table_privilege: invalid privilege type %s", ereport(ERROR,
priv_type); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */ return ACL_NO_RIGHTS; /* keep compiler quiet */
} }
...@@ -1237,7 +1268,9 @@ convert_database_name(text *databasename) ...@@ -1237,7 +1268,9 @@ convert_database_name(text *databasename)
oid = get_database_oid(dbname); oid = get_database_oid(dbname);
if (!OidIsValid(oid)) if (!OidIsValid(oid))
elog(ERROR, "database \"%s\" does not exist", dbname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
return oid; return oid;
} }
...@@ -1272,8 +1305,9 @@ convert_database_priv_string(text *priv_type_text) ...@@ -1272,8 +1305,9 @@ convert_database_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "TEMP WITH GRANT OPTION") == 0) if (strcasecmp(priv_type, "TEMP WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP); return ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP);
elog(ERROR, "has_database_privilege: invalid privilege type %s", ereport(ERROR,
priv_type); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */ return ACL_NO_RIGHTS; /* keep compiler quiet */
} }
...@@ -1448,7 +1482,9 @@ convert_function_name(text *functionname) ...@@ -1448,7 +1482,9 @@ convert_function_name(text *functionname)
CStringGetDatum(funcname))); CStringGetDatum(funcname)));
if (!OidIsValid(oid)) if (!OidIsValid(oid))
elog(ERROR, "function \"%s\" does not exist", funcname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("function \"%s\" does not exist", funcname)));
return oid; return oid;
} }
...@@ -1473,8 +1509,9 @@ convert_function_priv_string(text *priv_type_text) ...@@ -1473,8 +1509,9 @@ convert_function_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "EXECUTE WITH GRANT OPTION") == 0) if (strcasecmp(priv_type, "EXECUTE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_EXECUTE); return ACL_GRANT_OPTION_FOR(ACL_EXECUTE);
elog(ERROR, "has_function_privilege: invalid privilege type %s", ereport(ERROR,
priv_type); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */ return ACL_NO_RIGHTS; /* keep compiler quiet */
} }
...@@ -1649,7 +1686,9 @@ convert_language_name(text *languagename) ...@@ -1649,7 +1686,9 @@ convert_language_name(text *languagename)
CStringGetDatum(langname), CStringGetDatum(langname),
0, 0, 0); 0, 0, 0);
if (!OidIsValid(oid)) if (!OidIsValid(oid))
elog(ERROR, "language \"%s\" does not exist", langname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", langname)));
return oid; return oid;
} }
...@@ -1674,8 +1713,9 @@ convert_language_priv_string(text *priv_type_text) ...@@ -1674,8 +1713,9 @@ convert_language_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0) if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE); return ACL_GRANT_OPTION_FOR(ACL_USAGE);
elog(ERROR, "has_language_privilege: invalid privilege type %s", ereport(ERROR,
priv_type); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */ return ACL_NO_RIGHTS; /* keep compiler quiet */
} }
...@@ -1850,7 +1890,9 @@ convert_schema_name(text *schemaname) ...@@ -1850,7 +1890,9 @@ convert_schema_name(text *schemaname)
CStringGetDatum(nspname), CStringGetDatum(nspname),
0, 0, 0); 0, 0, 0);
if (!OidIsValid(oid)) if (!OidIsValid(oid))
elog(ERROR, "schema \"%s\" does not exist", nspname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
return oid; return oid;
} }
...@@ -1880,7 +1922,8 @@ convert_schema_priv_string(text *priv_type_text) ...@@ -1880,7 +1922,8 @@ convert_schema_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0) if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE); return ACL_GRANT_OPTION_FOR(ACL_USAGE);
elog(ERROR, "has_schema_privilege: invalid privilege type %s", ereport(ERROR,
priv_type); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */ return ACL_NO_RIGHTS; /* keep compiler quiet */
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.5 2003/07/01 00:04:38 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.6 2003/07/27 04:53:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "utils/array.h" #include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -44,7 +45,10 @@ array_push(PG_FUNCTION_ARGS) ...@@ -44,7 +45,10 @@ array_push(PG_FUNCTION_ARGS)
ArrayMetaState *my_extra; ArrayMetaState *my_extra;
if (arg0_typeid == InvalidOid || arg1_typeid == InvalidOid) if (arg0_typeid == InvalidOid || arg1_typeid == InvalidOid)
elog(ERROR, "array_push: cannot determine input data types"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data types")));
arg0_elemid = get_element_type(arg0_typeid); arg0_elemid = get_element_type(arg0_typeid);
arg1_elemid = get_element_type(arg1_typeid); arg1_elemid = get_element_type(arg1_typeid);
...@@ -63,7 +67,9 @@ array_push(PG_FUNCTION_ARGS) ...@@ -63,7 +67,9 @@ array_push(PG_FUNCTION_ARGS)
else else
{ {
/* Shouldn't get here given proper type checking in parser */ /* Shouldn't get here given proper type checking in parser */
elog(ERROR, "array_push: neither input type is an array"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("neither input type is an array")));
PG_RETURN_NULL(); /* keep compiler quiet */ PG_RETURN_NULL(); /* keep compiler quiet */
} }
...@@ -87,8 +93,9 @@ array_push(PG_FUNCTION_ARGS) ...@@ -87,8 +93,9 @@ array_push(PG_FUNCTION_ARGS)
else if (ARR_NDIM(v) == 0) else if (ARR_NDIM(v) == 0)
indx = 1; indx = 1;
else else
elog(ERROR, "only empty and one-dimensional arrays are supported"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("input must be empty or one-dimensional array")));
/* /*
* We arrange to look up info about element type only once per series * We arrange to look up info about element type only once per series
...@@ -169,16 +176,25 @@ array_cat(PG_FUNCTION_ARGS) ...@@ -169,16 +176,25 @@ array_cat(PG_FUNCTION_ARGS)
/* the rest fall into combo 2, 3, or 4 */ /* the rest fall into combo 2, 3, or 4 */
if (ndims1 != ndims2 && ndims1 != ndims2 - 1 && ndims1 != ndims2 + 1) if (ndims1 != ndims2 && ndims1 != ndims2 - 1 && ndims1 != ndims2 + 1)
elog(ERROR, "Cannot concatenate incompatible arrays of %d and " ereport(ERROR,
"%d dimensions", ndims1, ndims2); (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays of %d and %d dimensions are not "
"compatible for concatenation.",
ndims1, ndims2)));
element_type1 = ARR_ELEMTYPE(v1); element_type1 = ARR_ELEMTYPE(v1);
element_type2 = ARR_ELEMTYPE(v2); element_type2 = ARR_ELEMTYPE(v2);
/* Do we have a matching element types */ /* Do we have a matching element types */
if (element_type1 != element_type2) if (element_type1 != element_type2)
elog(ERROR, "Cannot concatenate incompatible arrays with element " ereport(ERROR,
"type %u and %u", element_type1, element_type2); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with element types %s and %s are not "
"compatible for concatenation.",
format_type_be(element_type1),
format_type_be(element_type2))));
/* OK, use it */ /* OK, use it */
element_type = element_type1; element_type = element_type1;
...@@ -211,7 +227,11 @@ array_cat(PG_FUNCTION_ARGS) ...@@ -211,7 +227,11 @@ array_cat(PG_FUNCTION_ARGS)
for (i = 0; i < ndims1; i++) for (i = 0; i < ndims1; i++)
{ {
if (dims1[i] != dims2[i] || lbs1[i] != lbs2[i]) if (dims1[i] != dims2[i] || lbs1[i] != lbs2[i])
elog(ERROR, "Cannot concatenate arrays with differing dimensions"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with differing dimensions are not "
"compatible for concatenation.")));
dims[i + 1] = dims1[i]; dims[i + 1] = dims1[i];
lbs[i + 1] = lbs1[i]; lbs[i + 1] = lbs1[i];
...@@ -237,7 +257,11 @@ array_cat(PG_FUNCTION_ARGS) ...@@ -237,7 +257,11 @@ array_cat(PG_FUNCTION_ARGS)
for (i = 0; i < ndims1; i++) for (i = 0; i < ndims1; i++)
{ {
if (dims1[i] != dims[i + 1] || lbs1[i] != lbs[i + 1]) if (dims1[i] != dims[i + 1] || lbs1[i] != lbs[i + 1])
elog(ERROR, "Cannot concatenate arrays with differing dimensions"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with differing dimensions are not "
"compatible for concatenation.")));
} }
} }
else /* (ndims1 == ndims2 + 1) */ else /* (ndims1 == ndims2 + 1) */
...@@ -260,7 +284,11 @@ array_cat(PG_FUNCTION_ARGS) ...@@ -260,7 +284,11 @@ array_cat(PG_FUNCTION_ARGS)
for (i = 0; i < ndims2; i++) for (i = 0; i < ndims2; i++)
{ {
if (dims2[i] != dims[i + 1] || lbs2[i] != lbs[i + 1]) if (dims2[i] != dims[i + 1] || lbs2[i] != lbs[i + 1])
elog(ERROR, "Cannot concatenate arrays with differing dimensions"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with differing dimensions are not "
"compatible for concatenation.")));
} }
} }
...@@ -302,9 +330,18 @@ create_singleton_array(FunctionCallInfo fcinfo, ...@@ -302,9 +330,18 @@ create_singleton_array(FunctionCallInfo fcinfo,
ArrayMetaState *my_extra; ArrayMetaState *my_extra;
if (element_type == 0) if (element_type == 0)
elog(ERROR, "Invalid array element type: %u", element_type); ereport(ERROR,
if (ndims < 1 || ndims > MAXDIM) (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
elog(ERROR, "Invalid number of dimensions %d", ndims); errmsg("invalid array element type: %u", element_type)));
if (ndims < 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid number of dimensions: %d", ndims)));
if (ndims > MAXDIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
dvalues[0] = element; dvalues[0] = element;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.93 2003/07/01 00:04:38 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.94 2003/07/27 04:53:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -203,10 +203,17 @@ array_in(PG_FUNCTION_ARGS) ...@@ -203,10 +203,17 @@ array_in(PG_FUNCTION_ARGS)
break; /* no more dimension items */ break; /* no more dimension items */
p++; p++;
if (ndim >= MAXDIM) if (ndim >= MAXDIM)
elog(ERROR, "array_in: more than %d dimensions", MAXDIM); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
for (q = p; isdigit((unsigned char) *q); q++); for (q = p; isdigit((unsigned char) *q); q++);
if (q == p) /* no digits? */ if (q == p) /* no digits? */
elog(ERROR, "array_in: missing dimension value"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing dimension value")));
if (*q == ':') if (*q == ':')
{ {
/* [m:n] format */ /* [m:n] format */
...@@ -215,7 +222,9 @@ array_in(PG_FUNCTION_ARGS) ...@@ -215,7 +222,9 @@ array_in(PG_FUNCTION_ARGS)
p = q + 1; p = q + 1;
for (q = p; isdigit((unsigned char) *q); q++); for (q = p; isdigit((unsigned char) *q); q++);
if (q == p) /* no digits? */ if (q == p) /* no digits? */
elog(ERROR, "array_in: missing dimension value"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing dimension value")));
} }
else else
{ {
...@@ -223,12 +232,18 @@ array_in(PG_FUNCTION_ARGS) ...@@ -223,12 +232,18 @@ array_in(PG_FUNCTION_ARGS)
lBound[ndim] = 1; lBound[ndim] = 1;
} }
if (*q != ']') if (*q != ']')
elog(ERROR, "array_in: missing ']' in array declaration"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing \"]\" in array dimensions")));
*q = '\0'; *q = '\0';
ub = atoi(p); ub = atoi(p);
p = q + 1; p = q + 1;
if (ub < lBound[ndim]) if (ub < lBound[ndim])
elog(ERROR, "array_in: upper_bound cannot be < lower_bound"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("upper bound cannot be less than lower bound")));
dim[ndim] = ub - lBound[ndim] + 1; dim[ndim] = ub - lBound[ndim] + 1;
ndim++; ndim++;
} }
...@@ -237,7 +252,9 @@ array_in(PG_FUNCTION_ARGS) ...@@ -237,7 +252,9 @@ array_in(PG_FUNCTION_ARGS)
{ {
/* No array dimensions, so intuit dimensions from brace structure */ /* No array dimensions, so intuit dimensions from brace structure */
if (*p != '{') if (*p != '{')
elog(ERROR, "array_in: Need to specify dimension"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("array value must start with \"{\" or dimension information")));
ndim = ArrayCount(p, dim, typdelim); ndim = ArrayCount(p, dim, typdelim);
for (i = 0; i < ndim; i++) for (i = 0; i < ndim; i++)
lBound[i] = 1; lBound[i] = 1;
...@@ -246,7 +263,9 @@ array_in(PG_FUNCTION_ARGS) ...@@ -246,7 +263,9 @@ array_in(PG_FUNCTION_ARGS)
{ {
/* If array dimensions are given, expect '=' operator */ /* If array dimensions are given, expect '=' operator */
if (strncmp(p, ASSGN, strlen(ASSGN)) != 0) if (strncmp(p, ASSGN, strlen(ASSGN)) != 0)
elog(ERROR, "array_in: missing assignment operator"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing assignment operator")));
p += strlen(ASSGN); p += strlen(ASSGN);
while (isspace((unsigned char) *p)) while (isspace((unsigned char) *p))
p++; p++;
...@@ -272,7 +291,9 @@ array_in(PG_FUNCTION_ARGS) ...@@ -272,7 +291,9 @@ array_in(PG_FUNCTION_ARGS)
} }
if (*p != '{') if (*p != '{')
elog(ERROR, "array_in: missing left brace"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing left brace")));
dataPtr = ReadArrayStr(p, nitems, ndim, dim, &my_extra->proc, typelem, dataPtr = ReadArrayStr(p, nitems, ndim, dim, &my_extra->proc, typelem,
typmod, typdelim, typlen, typbyval, typalign, typmod, typdelim, typlen, typbyval, typalign,
...@@ -328,14 +349,18 @@ ArrayCount(char *str, int *dim, char typdelim) ...@@ -328,14 +349,18 @@ ArrayCount(char *str, int *dim, char typdelim)
{ {
case '\0': case '\0':
/* Signal a premature end of the string */ /* Signal a premature end of the string */
elog(ERROR, "malformed array constant: %s", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", str)));
break; break;
case '\\': case '\\':
/* skip the escaped character */ /* skip the escaped character */
if (*(ptr + 1)) if (*(ptr + 1))
ptr++; ptr++;
else else
elog(ERROR, "malformed array constant: %s", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", str)));
break; break;
case '\"': case '\"':
scanning_string = !scanning_string; scanning_string = !scanning_string;
...@@ -344,7 +369,10 @@ ArrayCount(char *str, int *dim, char typdelim) ...@@ -344,7 +369,10 @@ ArrayCount(char *str, int *dim, char typdelim)
if (!scanning_string) if (!scanning_string)
{ {
if (nest_level >= MAXDIM) if (nest_level >= MAXDIM)
elog(ERROR, "array_in: illformed array constant"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
temp[nest_level] = 0; temp[nest_level] = 0;
nest_level++; nest_level++;
if (ndim < nest_level) if (ndim < nest_level)
...@@ -355,7 +383,9 @@ ArrayCount(char *str, int *dim, char typdelim) ...@@ -355,7 +383,9 @@ ArrayCount(char *str, int *dim, char typdelim)
if (!scanning_string) if (!scanning_string)
{ {
if (nest_level == 0) if (nest_level == 0)
elog(ERROR, "array_in: illformed array constant"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", str)));
nest_level--; nest_level--;
if (nest_level == 0) if (nest_level == 0)
eoArray = itemdone = true; eoArray = itemdone = true;
...@@ -447,7 +477,9 @@ ReadArrayStr(char *arrayStr, ...@@ -447,7 +477,9 @@ ReadArrayStr(char *arrayStr,
{ {
case '\0': case '\0':
/* Signal a premature end of the string */ /* Signal a premature end of the string */
elog(ERROR, "malformed array constant: %s", arrayStr); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", arrayStr)));
break; break;
case '\\': case '\\':
{ {
...@@ -457,7 +489,9 @@ ReadArrayStr(char *arrayStr, ...@@ -457,7 +489,9 @@ ReadArrayStr(char *arrayStr,
for (cptr = ptr; *cptr != '\0'; cptr++) for (cptr = ptr; *cptr != '\0'; cptr++)
*cptr = *(cptr + 1); *cptr = *(cptr + 1);
if (*ptr == '\0') if (*ptr == '\0')
elog(ERROR, "malformed array constant: %s", arrayStr); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", arrayStr)));
break; break;
} }
case '\"': case '\"':
...@@ -476,7 +510,9 @@ ReadArrayStr(char *arrayStr, ...@@ -476,7 +510,9 @@ ReadArrayStr(char *arrayStr,
if (!scanning_string) if (!scanning_string)
{ {
if (nest_level >= ndim) if (nest_level >= ndim)
elog(ERROR, "array_in: illformed array constant"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", arrayStr)));
nest_level++; nest_level++;
indx[nest_level - 1] = 0; indx[nest_level - 1] = 0;
/* skip leading whitespace */ /* skip leading whitespace */
...@@ -489,7 +525,9 @@ ReadArrayStr(char *arrayStr, ...@@ -489,7 +525,9 @@ ReadArrayStr(char *arrayStr,
if (!scanning_string) if (!scanning_string)
{ {
if (nest_level == 0) if (nest_level == 0)
elog(ERROR, "array_in: illformed array constant"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", arrayStr)));
if (i == -1) if (i == -1)
i = ArrayGetOffset0(ndim, indx, prod); i = ArrayGetOffset0(ndim, indx, prod);
indx[nest_level - 1] = 0; indx[nest_level - 1] = 0;
...@@ -525,7 +563,10 @@ ReadArrayStr(char *arrayStr, ...@@ -525,7 +563,10 @@ ReadArrayStr(char *arrayStr,
} }
*ptr++ = '\0'; *ptr++ = '\0';
if (i < 0 || i >= nitems) if (i < 0 || i >= nitems)
elog(ERROR, "array_in: illformed array constant"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", arrayStr)));
values[i] = FunctionCall3(inputproc, values[i] = FunctionCall3(inputproc,
CStringGetDatum(itemstart), CStringGetDatum(itemstart),
ObjectIdGetDatum(typelem), ObjectIdGetDatum(typelem),
...@@ -839,16 +880,29 @@ array_recv(PG_FUNCTION_ARGS) ...@@ -839,16 +880,29 @@ array_recv(PG_FUNCTION_ARGS)
/* Get the array header information */ /* Get the array header information */
ndim = pq_getmsgint(buf, 4); ndim = pq_getmsgint(buf, 4);
if (ndim < 0 || ndim > MAXDIM) if (ndim < 0) /* we do allow zero-dimension arrays */
elog(ERROR, "array_recv: invalid number of dimensions"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid number of dimensions: %d", ndim)));
if (ndim > MAXDIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
flags = pq_getmsgint(buf, 4); flags = pq_getmsgint(buf, 4);
if (flags != 0) if (flags != 0)
elog(ERROR, "array_recv: invalid array flags"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid array flags")));
element_type = pq_getmsgint(buf, sizeof(Oid)); element_type = pq_getmsgint(buf, sizeof(Oid));
if (element_type != spec_element_type) if (element_type != spec_element_type)
{ {
/* XXX Can we allow taking the input element type in any cases? */ /* XXX Can we allow taking the input element type in any cases? */
elog(ERROR, "array_recv: wrong element type"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("wrong element type")));
} }
for (i = 0; i < ndim; i++) for (i = 0; i < ndim; i++)
...@@ -889,8 +943,10 @@ array_recv(PG_FUNCTION_ARGS) ...@@ -889,8 +943,10 @@ array_recv(PG_FUNCTION_ARGS)
&my_extra->typalign, &my_extra->typdelim, &my_extra->typalign, &my_extra->typdelim,
&my_extra->typelem, &my_extra->typiofunc); &my_extra->typelem, &my_extra->typiofunc);
if (!OidIsValid(my_extra->typiofunc)) if (!OidIsValid(my_extra->typiofunc))
elog(ERROR, "No binary input function available for type %s", ereport(ERROR,
format_type_be(element_type)); (errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no binary input function available for type %s",
format_type_be(element_type))));
fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc, fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
fcinfo->flinfo->fn_mcxt); fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type; my_extra->element_type = element_type;
...@@ -955,7 +1011,9 @@ ReadArrayBinary(StringInfo buf, ...@@ -955,7 +1011,9 @@ ReadArrayBinary(StringInfo buf,
/* Get and check the item length */ /* Get and check the item length */
itemlen = pq_getmsgint(buf, 4); itemlen = pq_getmsgint(buf, 4);
if (itemlen < 0 || itemlen > (buf->len - buf->cursor)) if (itemlen < 0 || itemlen > (buf->len - buf->cursor))
elog(ERROR, "insufficient data left in message"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("insufficient data left in message")));
/* /*
* Rather than copying data around, we just set up a phony * Rather than copying data around, we just set up a phony
...@@ -981,8 +1039,10 @@ ReadArrayBinary(StringInfo buf, ...@@ -981,8 +1039,10 @@ ReadArrayBinary(StringInfo buf,
/* Trouble if it didn't eat the whole buffer */ /* Trouble if it didn't eat the whole buffer */
if (elem_buf.cursor != itemlen) if (elem_buf.cursor != itemlen)
elog(ERROR, "Improper binary format in array element %d", ereport(ERROR,
i + 1); (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("improper binary format in array element %d",
i + 1)));
buf->data[buf->cursor] = csave; buf->data[buf->cursor] = csave;
} }
...@@ -1060,8 +1120,10 @@ array_send(PG_FUNCTION_ARGS) ...@@ -1060,8 +1120,10 @@ array_send(PG_FUNCTION_ARGS)
&my_extra->typalign, &my_extra->typdelim, &my_extra->typalign, &my_extra->typdelim,
&my_extra->typelem, &my_extra->typiofunc); &my_extra->typelem, &my_extra->typiofunc);
if (!OidIsValid(my_extra->typiofunc)) if (!OidIsValid(my_extra->typiofunc))
elog(ERROR, "No binary output function available for type %s", ereport(ERROR,
format_type_be(element_type)); (errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no binary output function available for type %s",
format_type_be(element_type))));
fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc, fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
fcinfo->flinfo->fn_mcxt); fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type; my_extra->element_type = element_type;
...@@ -1407,7 +1469,9 @@ array_get_slice(ArrayType *array, ...@@ -1407,7 +1469,9 @@ array_get_slice(ArrayType *array,
* Code below shows how we could support it if the parser were * Code below shows how we could support it if the parser were
* changed to label output as a suitable varlena array type. * changed to label output as a suitable varlena array type.
*/ */
elog(ERROR, "Slices of fixed-length arrays not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("slices of fixed-length arrays not implemented")));
/* /*
* fixed-length arrays -- these are assumed to be 1-d, 0-based XXX * fixed-length arrays -- these are assumed to be 1-d, 0-based XXX
...@@ -1543,9 +1607,15 @@ array_set(ArrayType *array, ...@@ -1543,9 +1607,15 @@ array_set(ArrayType *array,
* cannot extend them, either. * cannot extend them, either.
*/ */
if (nSubscripts != 1) if (nSubscripts != 1)
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
if (indx[0] < 0 || indx[0] * elmlen >= arraylen) if (indx[0] < 0 || indx[0] * elmlen >= arraylen)
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
newarray = (ArrayType *) palloc(arraylen); newarray = (ArrayType *) palloc(arraylen);
memcpy(newarray, array, arraylen); memcpy(newarray, array, arraylen);
elt_ptr = (char *) newarray + indx[0] * elmlen; elt_ptr = (char *) newarray + indx[0] * elmlen;
...@@ -1582,7 +1652,9 @@ array_set(ArrayType *array, ...@@ -1582,7 +1652,9 @@ array_set(ArrayType *array,
} }
if (ndim != nSubscripts || ndim <= 0 || ndim > MAXDIM) if (ndim != nSubscripts || ndim <= 0 || ndim > MAXDIM)
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
/* copy dim/lb since we may modify them */ /* copy dim/lb since we may modify them */
memcpy(dim, ARR_DIMS(array), ndim * sizeof(int)); memcpy(dim, ARR_DIMS(array), ndim * sizeof(int));
...@@ -1602,7 +1674,9 @@ array_set(ArrayType *array, ...@@ -1602,7 +1674,9 @@ array_set(ArrayType *array,
extendbefore = true; extendbefore = true;
} }
else else
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
} }
if (indx[i] >= (dim[i] + lb[i])) if (indx[i] >= (dim[i] + lb[i]))
{ {
...@@ -1612,7 +1686,9 @@ array_set(ArrayType *array, ...@@ -1612,7 +1686,9 @@ array_set(ArrayType *array,
extendafter = true; extendafter = true;
} }
else else
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
} }
} }
...@@ -1727,7 +1803,9 @@ array_set_slice(ArrayType *array, ...@@ -1727,7 +1803,9 @@ array_set_slice(ArrayType *array,
/* /*
* fixed-length arrays -- not got round to doing this... * fixed-length arrays -- not got round to doing this...
*/ */
elog(ERROR, "Updates on slices of fixed-length arrays not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("updates on slices of fixed-length arrays not implemented")));
} }
/* detoast arrays if necessary */ /* detoast arrays if necessary */
...@@ -1763,7 +1841,9 @@ array_set_slice(ArrayType *array, ...@@ -1763,7 +1841,9 @@ array_set_slice(ArrayType *array,
} }
if (ndim < nSubscripts || ndim <= 0 || ndim > MAXDIM) if (ndim < nSubscripts || ndim <= 0 || ndim > MAXDIM)
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
/* copy dim/lb since we may modify them */ /* copy dim/lb since we may modify them */
memcpy(dim, ARR_DIMS(array), ndim * sizeof(int)); memcpy(dim, ARR_DIMS(array), ndim * sizeof(int));
...@@ -1778,7 +1858,9 @@ array_set_slice(ArrayType *array, ...@@ -1778,7 +1858,9 @@ array_set_slice(ArrayType *array,
for (i = 0; i < nSubscripts; i++) for (i = 0; i < nSubscripts; i++)
{ {
if (lowerIndx[i] > upperIndx[i]) if (lowerIndx[i] > upperIndx[i])
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
if (lowerIndx[i] < lb[i]) if (lowerIndx[i] < lb[i])
{ {
if (ndim == 1 && upperIndx[i] >= lb[i] - 1) if (ndim == 1 && upperIndx[i] >= lb[i] - 1)
...@@ -1787,14 +1869,18 @@ array_set_slice(ArrayType *array, ...@@ -1787,14 +1869,18 @@ array_set_slice(ArrayType *array,
lb[i] = lowerIndx[i]; lb[i] = lowerIndx[i];
} }
else else
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
} }
if (upperIndx[i] >= (dim[i] + lb[i])) if (upperIndx[i] >= (dim[i] + lb[i]))
{ {
if (ndim == 1 && lowerIndx[i] <= (dim[i] + lb[i])) if (ndim == 1 && lowerIndx[i] <= (dim[i] + lb[i]))
dim[i] = upperIndx[i] - lb[i] + 1; dim[i] = upperIndx[i] - lb[i] + 1;
else else
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
} }
} }
/* fill any missing subscript positions with full array range */ /* fill any missing subscript positions with full array range */
...@@ -1803,7 +1889,9 @@ array_set_slice(ArrayType *array, ...@@ -1803,7 +1889,9 @@ array_set_slice(ArrayType *array,
lowerIndx[i] = lb[i]; lowerIndx[i] = lb[i];
upperIndx[i] = dim[i] + lb[i] - 1; upperIndx[i] = dim[i] + lb[i] - 1;
if (lowerIndx[i] > upperIndx[i]) if (lowerIndx[i] > upperIndx[i])
elog(ERROR, "Invalid array subscripts"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("invalid array subscripts")));
} }
/* /*
...@@ -1813,7 +1901,9 @@ array_set_slice(ArrayType *array, ...@@ -1813,7 +1901,9 @@ array_set_slice(ArrayType *array,
mda_get_range(ndim, span, lowerIndx, upperIndx); mda_get_range(ndim, span, lowerIndx, upperIndx);
nsrcitems = ArrayGetNItems(ndim, span); nsrcitems = ArrayGetNItems(ndim, span);
if (nsrcitems > ArrayGetNItems(ARR_NDIM(srcArray), ARR_DIMS(srcArray))) if (nsrcitems > ArrayGetNItems(ARR_NDIM(srcArray), ARR_DIMS(srcArray)))
elog(ERROR, "Source array too small"); ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("source array too small")));
/* /*
* Compute space occupied by new entries, space occupied by replaced * Compute space occupied by new entries, space occupied by replaced
...@@ -1948,9 +2038,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) ...@@ -1948,9 +2038,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
/* Get input array */ /* Get input array */
if (fcinfo->nargs < 1) if (fcinfo->nargs < 1)
elog(ERROR, "array_map: invalid nargs: %d", fcinfo->nargs); elog(ERROR, "invalid nargs: %d", fcinfo->nargs);
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
elog(ERROR, "array_map: null input array"); elog(ERROR, "null input array");
v = PG_GETARG_ARRAYTYPE_P(0); v = PG_GETARG_ARRAYTYPE_P(0);
Assert(ARR_ELEMTYPE(v) == inpType); Assert(ARR_ELEMTYPE(v) == inpType);
...@@ -2034,7 +2124,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) ...@@ -2034,7 +2124,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
fcinfo->isnull = false; fcinfo->isnull = false;
values[i] = FunctionCallInvoke(fcinfo); values[i] = FunctionCallInvoke(fcinfo);
if (fcinfo->isnull) if (fcinfo->isnull)
elog(ERROR, "array_map: cannot handle NULL in array"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("NULL array elements not supported")));
/* Ensure data is not toasted */ /* Ensure data is not toasted */
if (typlen == -1) if (typlen == -1)
...@@ -2129,9 +2221,30 @@ construct_md_array(Datum *elems, ...@@ -2129,9 +2221,30 @@ construct_md_array(Datum *elems,
int i; int i;
int nelems; int nelems;
if (ndims < 1 || ndims > MAXDIM) if (ndims < 0) /* we do allow zero-dimension arrays */
elog(ERROR, "Number of array dimensions, %d, exceeds the maximum allowed (%d)", ereport(ERROR,
ndims, MAXDIM); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid number of dimensions: %d", ndims)));
if (ndims > MAXDIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
/* fast track for empty array */
if (ndims == 0)
{
/* Allocate and initialize 0-D result array */
nbytes = ARR_OVERHEAD(ndims);
result = (ArrayType *) palloc(nbytes);
result->size = nbytes;
result->ndim = ndims;
result->flags = 0;
result->elemtype = elmtype;
return result;
}
nelems = ArrayGetNItems(ndims, dims); nelems = ArrayGetNItems(ndims, dims);
...@@ -2249,7 +2362,9 @@ array_eq(PG_FUNCTION_ARGS) ...@@ -2249,7 +2362,9 @@ array_eq(PG_FUNCTION_ARGS)
FunctionCallInfoData locfcinfo; FunctionCallInfoData locfcinfo;
if (element_type != ARR_ELEMTYPE(array2)) if (element_type != ARR_ELEMTYPE(array2))
elog(ERROR, "cannot compare arrays of different element types"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot compare arrays of different element types")));
/* fast path if the arrays do not have the same number of elements */ /* fast path if the arrays do not have the same number of elements */
if (nitems1 != nitems2) if (nitems1 != nitems2)
...@@ -2415,7 +2530,9 @@ array_cmp(FunctionCallInfo fcinfo) ...@@ -2415,7 +2530,9 @@ array_cmp(FunctionCallInfo fcinfo)
element_type = ARR_ELEMTYPE(array1); element_type = ARR_ELEMTYPE(array1);
if (element_type != ARR_ELEMTYPE(array2)) if (element_type != ARR_ELEMTYPE(array2))
elog(ERROR, "cannot compare arrays of different element types"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot compare arrays of different element types")));
/* /*
* We arrange to look up the element type info and related functions * We arrange to look up the element type info and related functions
...@@ -2797,10 +2914,15 @@ array_type_coerce(PG_FUNCTION_ARGS) ...@@ -2797,10 +2914,15 @@ array_type_coerce(PG_FUNCTION_ARGS)
Oid funcId; Oid funcId;
if (tgt_type == InvalidOid) if (tgt_type == InvalidOid)
elog(ERROR, "Cannot determine target array type"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine target array type")));
tgt_elem_type = get_element_type(tgt_type); tgt_elem_type = get_element_type(tgt_type);
if (tgt_elem_type == InvalidOid) if (tgt_elem_type == InvalidOid)
elog(ERROR, "Target type is not an array"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("target type is not an array")));
/* /*
* We don't deal with domain constraints yet, so bail out. * We don't deal with domain constraints yet, so bail out.
...@@ -2811,8 +2933,10 @@ array_type_coerce(PG_FUNCTION_ARGS) ...@@ -2811,8 +2933,10 @@ array_type_coerce(PG_FUNCTION_ARGS)
* check to the coercion. * check to the coercion.
*/ */
if (getBaseType(tgt_elem_type) != tgt_elem_type) if (getBaseType(tgt_elem_type) != tgt_elem_type)
elog(ERROR, "array coercion to domain type elements not " \ ereport(ERROR,
"currently supported"); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("array coercion to domain type elements not "
"currently supported")));
if (!find_coercion_pathway(tgt_elem_type, src_elem_type, if (!find_coercion_pathway(tgt_elem_type, src_elem_type,
COERCION_EXPLICIT, &funcId)) COERCION_EXPLICIT, &funcId))
...@@ -2901,7 +3025,9 @@ accumArrayResult(ArrayBuildState *astate, ...@@ -2901,7 +3025,9 @@ accumArrayResult(ArrayBuildState *astate,
} }
if (disnull) if (disnull)
elog(ERROR, "NULL elements not allowed in Arrays"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("NULL array elements not supported")));
/* Use datumCopy to ensure pass-by-ref stuff is copied into mcontext */ /* Use datumCopy to ensure pass-by-ref stuff is copied into mcontext */
astate->dvalues[astate->nelems++] = astate->dvalues[astate->nelems++] =
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.15 2003/07/14 16:41:38 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.16 2003/07/27 04:53:03 tgl Exp $
* *
*----------------------------------------------------------------------- *-----------------------------------------------------------------------
*/ */
...@@ -63,8 +63,10 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *dest, int ...@@ -63,8 +63,10 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *dest, int
} }
else else
{ {
elog(ERROR, "unsupported encoding conversion from %s to ASCII", ereport(ERROR,
pg_encoding_to_char(enc)); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unsupported encoding conversion from %s to ASCII",
pg_encoding_to_char(enc))));
return; /* keep compiler quiet */ return; /* keep compiler quiet */
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.27 2003/05/12 23:08:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.28 2003/07/27 04:53:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -75,7 +75,9 @@ boolin(PG_FUNCTION_ARGS) ...@@ -75,7 +75,9 @@ boolin(PG_FUNCTION_ARGS)
break; break;
} }
elog(ERROR, "Bad boolean external representation '%s'", b); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for boolean: \"%s\"", b)));
/* not reached */ /* not reached */
PG_RETURN_BOOL(false); PG_RETURN_BOOL(false);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by * workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.58 2003/05/13 18:03:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.59 2003/07/27 04:53:03 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -193,7 +193,9 @@ cash_in(PG_FUNCTION_ARGS) ...@@ -193,7 +193,9 @@ cash_in(PG_FUNCTION_ARGS)
s++; s++;
if (*s != '\0') if (*s != '\0')
elog(ERROR, "Bad money external representation %s", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for money: \"%s\"", str)));
result = (value * sgn); result = (value * sgn);
...@@ -290,7 +292,9 @@ cash_out(PG_FUNCTION_ARGS) ...@@ -290,7 +292,9 @@ cash_out(PG_FUNCTION_ARGS)
if (minus) if (minus)
{ {
if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count + strlen(nsymbol)))) if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count + strlen(nsymbol))))
elog(ERROR, "Memory allocation failed, can't output cash"); ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* Position code of 0 means use parens */ /* Position code of 0 means use parens */
if (convention == 0) if (convention == 0)
...@@ -303,7 +307,9 @@ cash_out(PG_FUNCTION_ARGS) ...@@ -303,7 +307,9 @@ cash_out(PG_FUNCTION_ARGS)
else else
{ {
if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count))) if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count)))
elog(ERROR, "Memory allocation failed, can't output cash"); ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
strcpy(result, buf + count); strcpy(result, buf + count);
} }
...@@ -468,7 +474,9 @@ cash_div_flt8(PG_FUNCTION_ARGS) ...@@ -468,7 +474,9 @@ cash_div_flt8(PG_FUNCTION_ARGS)
Cash result; Cash result;
if (f == 0.0) if (f == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / f); result = rint(c / f);
PG_RETURN_CASH(result); PG_RETURN_CASH(result);
...@@ -518,7 +526,9 @@ cash_div_flt4(PG_FUNCTION_ARGS) ...@@ -518,7 +526,9 @@ cash_div_flt4(PG_FUNCTION_ARGS)
Cash result; Cash result;
if (f == 0.0) if (f == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / f); result = rint(c / f);
PG_RETURN_CASH(result); PG_RETURN_CASH(result);
...@@ -569,7 +579,9 @@ cash_div_int4(PG_FUNCTION_ARGS) ...@@ -569,7 +579,9 @@ cash_div_int4(PG_FUNCTION_ARGS)
Cash result; Cash result;
if (i == 0) if (i == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / i); result = rint(c / i);
...@@ -619,7 +631,9 @@ cash_div_int2(PG_FUNCTION_ARGS) ...@@ -619,7 +631,9 @@ cash_div_int2(PG_FUNCTION_ARGS)
Cash result; Cash result;
if (s == 0) if (s == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / s); result = rint(c / s);
PG_RETURN_CASH(result); PG_RETURN_CASH(result);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.35 2003/05/12 23:08:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.36 2003/07/27 04:53:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -181,7 +181,9 @@ chardiv(PG_FUNCTION_ARGS) ...@@ -181,7 +181,9 @@ chardiv(PG_FUNCTION_ARGS)
char arg2 = PG_GETARG_CHAR(1); char arg2 = PG_GETARG_CHAR(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_CHAR((int8) arg1 / (int8) arg2); PG_RETURN_CHAR((int8) arg1 / (int8) arg2);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.86 2003/07/24 04:38:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.87 2003/07/27 04:53:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -67,11 +67,15 @@ date_in(PG_FUNCTION_ARGS) ...@@ -67,11 +67,15 @@ date_in(PG_FUNCTION_ARGS)
char lowstr[MAXDATELEN + 1]; char lowstr[MAXDATELEN + 1];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad date external representation (too long) '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for date: \"%s\"", str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0)) || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
elog(ERROR, "Bad date external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for date: \"%s\"", str)));
switch (dtype) switch (dtype)
{ {
...@@ -79,8 +83,10 @@ date_in(PG_FUNCTION_ARGS) ...@@ -79,8 +83,10 @@ date_in(PG_FUNCTION_ARGS)
break; break;
case DTK_CURRENT: case DTK_CURRENT:
elog(ERROR, "Date CURRENT no longer supported" ereport(ERROR,
"\n\tdate_in() internal coding error"); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"current\" is no longer supported")));
GetCurrentDateTime(tm); GetCurrentDateTime(tm);
break; break;
...@@ -89,7 +95,9 @@ date_in(PG_FUNCTION_ARGS) ...@@ -89,7 +95,9 @@ date_in(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "Unrecognized date external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for date: \"%s\"", str)));
} }
date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
...@@ -356,7 +364,9 @@ timestamp_date(PG_FUNCTION_ARGS) ...@@ -356,7 +364,9 @@ timestamp_date(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to convert timestamp to date"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
...@@ -426,7 +436,9 @@ timestamptz_date(PG_FUNCTION_ARGS) ...@@ -426,7 +436,9 @@ timestamptz_date(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to convert timestamp to date"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
...@@ -451,7 +463,9 @@ abstime_date(PG_FUNCTION_ARGS) ...@@ -451,7 +463,9 @@ abstime_date(PG_FUNCTION_ARGS)
case INVALID_ABSTIME: case INVALID_ABSTIME:
case NOSTART_ABSTIME: case NOSTART_ABSTIME:
case NOEND_ABSTIME: case NOEND_ABSTIME:
elog(ERROR, "Unable to convert reserved abstime value to date"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert reserved abstime value to date")));
/* /*
* pretend to drop through to make compiler think that result * pretend to drop through to make compiler think that result
...@@ -510,7 +524,10 @@ text_date(PG_FUNCTION_ARGS) ...@@ -510,7 +524,10 @@ text_date(PG_FUNCTION_ARGS)
dstr[MAXDATELEN + 1]; dstr[MAXDATELEN + 1];
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN) if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "Bad date external representation (too long)"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for date: \"%s\"",
VARDATA(str))));
sp = VARDATA(str); sp = VARDATA(str);
dp = dstr; dp = dstr;
...@@ -548,11 +565,15 @@ time_in(PG_FUNCTION_ARGS) ...@@ -548,11 +565,15 @@ time_in(PG_FUNCTION_ARGS)
int ftype[MAXDATEFIELDS]; int ftype[MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad time external representation (too long) '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for time: \"%s\"", str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) || (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad time external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for time: \"%s\"", str)));
tm2time(tm, fsec, &result); tm2time(tm, fsec, &result);
AdjustTimeForTypmod(&result, typmod); AdjustTimeForTypmod(&result, typmod);
...@@ -978,7 +999,9 @@ timestamp_time(PG_FUNCTION_ARGS) ...@@ -978,7 +999,9 @@ timestamp_time(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to convert timestamp to time"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -1013,7 +1036,9 @@ timestamptz_time(PG_FUNCTION_ARGS) ...@@ -1013,7 +1036,9 @@ timestamptz_time(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to convert timestamptz to time"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -1228,7 +1253,10 @@ text_time(PG_FUNCTION_ARGS) ...@@ -1228,7 +1253,10 @@ text_time(PG_FUNCTION_ARGS)
dstr[MAXDATELEN + 1]; dstr[MAXDATELEN + 1];
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN) if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "Bad time external representation (too long)"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for time: \"%s\"",
VARDATA(str))));
sp = VARDATA(str); sp = VARDATA(str);
dp = dstr; dp = dstr;
...@@ -1259,9 +1287,12 @@ time_part(PG_FUNCTION_ARGS) ...@@ -1259,9 +1287,12 @@ time_part(PG_FUNCTION_ARGS)
lowunits[MAXDATELEN + 1]; lowunits[MAXDATELEN + 1];
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIME units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("TIME units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -1326,9 +1357,12 @@ time_part(PG_FUNCTION_ARGS) ...@@ -1326,9 +1357,12 @@ time_part(PG_FUNCTION_ARGS)
case DTK_CENTURY: case DTK_CENTURY:
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
default: default:
elog(ERROR, "TIME units '%s' not supported", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("TIME units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
result = 0; result = 0;
} }
} }
...@@ -1342,9 +1376,11 @@ time_part(PG_FUNCTION_ARGS) ...@@ -1342,9 +1376,11 @@ time_part(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "TIME units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("TIME units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
result = 0; result = 0;
} }
...@@ -1394,12 +1430,17 @@ timetz_in(PG_FUNCTION_ARGS) ...@@ -1394,12 +1430,17 @@ timetz_in(PG_FUNCTION_ARGS)
int ftype[MAXDATEFIELDS]; int ftype[MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad time with time zone" ereport(ERROR,
" external representation (too long) '%s'", str); (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for time with time zone: \"%s\"",
str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) || (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad time external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for time with time zone: \"%s\"",
str)));
result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
tm2timetz(tm, fsec, tz, result); tm2timetz(tm, fsec, tz, result);
...@@ -1898,7 +1939,9 @@ timestamptz_timetz(PG_FUNCTION_ARGS) ...@@ -1898,7 +1939,9 @@ timestamptz_timetz(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); PG_RETURN_NULL();
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to convert timestamptz to timetz"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
...@@ -1974,7 +2017,10 @@ text_timetz(PG_FUNCTION_ARGS) ...@@ -1974,7 +2017,10 @@ text_timetz(PG_FUNCTION_ARGS)
dstr[MAXDATELEN + 1]; dstr[MAXDATELEN + 1];
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN) if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "Bad timetz external representation (too long)"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for time with time zone: \"%s\"",
VARDATA(str))));
sp = VARDATA(str); sp = VARDATA(str);
dp = dstr; dp = dstr;
...@@ -2005,9 +2051,12 @@ timetz_part(PG_FUNCTION_ARGS) ...@@ -2005,9 +2051,12 @@ timetz_part(PG_FUNCTION_ARGS)
lowunits[MAXDATELEN + 1]; lowunits[MAXDATELEN + 1];
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMETZ units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("TIMETZ units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -2086,9 +2135,12 @@ timetz_part(PG_FUNCTION_ARGS) ...@@ -2086,9 +2135,12 @@ timetz_part(PG_FUNCTION_ARGS)
case DTK_CENTURY: case DTK_CENTURY:
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
default: default:
elog(ERROR, "TIMETZ units '%s' not supported", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("TIMETZ units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
result = 0; result = 0;
} }
} }
...@@ -2102,9 +2154,12 @@ timetz_part(PG_FUNCTION_ARGS) ...@@ -2102,9 +2154,12 @@ timetz_part(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "TIMETZ units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("TIMETZ units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
result = 0; result = 0;
} }
...@@ -2129,9 +2184,12 @@ timetz_zone(PG_FUNCTION_ARGS) ...@@ -2129,9 +2184,12 @@ timetz_zone(PG_FUNCTION_ARGS)
lowzone[MAXDATELEN + 1]; lowzone[MAXDATELEN + 1];
if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN) if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "Time zone '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("time zone \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(zone)))); PointerGetDatum(zone))))));
up = VARDATA(zone); up = VARDATA(zone);
lp = lowzone; lp = lowzone;
for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
...@@ -2163,7 +2221,10 @@ timetz_zone(PG_FUNCTION_ARGS) ...@@ -2163,7 +2221,10 @@ timetz_zone(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "Time zone '%s' not recognized", lowzone); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("time zone \"%s\" not recognized", lowzone)));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -2182,9 +2243,11 @@ timetz_izone(PG_FUNCTION_ARGS) ...@@ -2182,9 +2243,11 @@ timetz_izone(PG_FUNCTION_ARGS)
int tz; int tz;
if (zone->month != 0) if (zone->month != 0)
elog(ERROR, "INTERVAL time zone '%s' not legal (month specified)", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("INTERVAL time zone \"%s\" not legal",
DatumGetCString(DirectFunctionCall1(interval_out, DatumGetCString(DirectFunctionCall1(interval_out,
PointerGetDatum(zone)))); PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
tz = -(zone->time / INT64CONST(1000000)); tz = -(zone->time / INT64CONST(1000000));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.106 2003/06/25 21:14:14 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.107 2003/07/27 04:53:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1251,7 +1251,10 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -1251,7 +1251,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
switch (val) switch (val)
{ {
case DTK_CURRENT: case DTK_CURRENT:
elog(ERROR, "'CURRENT' is no longer supported"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"current\" is no longer supported")));
return -1; return -1;
break; break;
...@@ -1428,7 +1431,10 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -1428,7 +1431,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
if (tm->tm_year > 0) if (tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1); tm->tm_year = -(tm->tm_year - 1);
else else
elog(ERROR, "Inconsistent use of year %04d and 'BC'", tm->tm_year); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("inconsistent use of year %04d and \"BC\"",
tm->tm_year)));
} }
else if (is2digits) else if (is2digits)
{ {
...@@ -1965,7 +1971,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf, ...@@ -1965,7 +1971,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
switch (val) switch (val)
{ {
case DTK_CURRENT: case DTK_CURRENT:
elog(ERROR, "'CURRENT' is no longer supported"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"current\" is no longer supported")));
return -1; return -1;
break; break;
...@@ -2238,7 +2246,10 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm) ...@@ -2238,7 +2246,10 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
if (tm->tm_year > 0) if (tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1); tm->tm_year = -(tm->tm_year - 1);
else else
elog(ERROR, "Inconsistent use of year %04d and 'BC'", tm->tm_year); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("inconsistent use of year %04d and \"BC\"",
tm->tm_year)));
} }
else if (is2digits) else if (is2digits)
{ {
...@@ -2554,7 +2565,7 @@ DecodeNumberField(int len, char *str, int fmask, ...@@ -2554,7 +2565,7 @@ DecodeNumberField(int len, char *str, int fmask,
* *
* Return 0 if okay (and set *tzp), nonzero if not okay. * Return 0 if okay (and set *tzp), nonzero if not okay.
* *
* NB: this must *not* elog on failure; see commands/variable.c. * NB: this must *not* ereport on failure; see commands/variable.c.
* *
* Note: we allow timezone offsets up to 13:59. There are places that * Note: we allow timezone offsets up to 13:59. There are places that
* use +1300 summer time. * use +1300 summer time.
...@@ -2611,7 +2622,7 @@ DecodeTimezone(char *str, int *tzp) ...@@ -2611,7 +2622,7 @@ DecodeTimezone(char *str, int *tzp)
* *
* Return 0 if okay (and set *tzp), nonzero if not okay. * Return 0 if okay (and set *tzp), nonzero if not okay.
* *
* NB: this must *not* elog on failure; see commands/variable.c. * NB: this must *not* ereport on failure; see commands/variable.c.
*/ */
int int
DecodePosixTimezone(char *str, int *tzp) DecodePosixTimezone(char *str, int *tzp)
...@@ -2663,7 +2674,7 @@ DecodePosixTimezone(char *str, int *tzp) ...@@ -2663,7 +2674,7 @@ DecodePosixTimezone(char *str, int *tzp)
* Implement a cache lookup since it is likely that dates * Implement a cache lookup since it is likely that dates
* will be related in format. * will be related in format.
* *
* NB: this must *not* elog on failure; * NB: this must *not* ereport on failure;
* see commands/variable.c. * see commands/variable.c.
*/ */
int int
...@@ -3715,7 +3726,7 @@ CheckDateTokenTable(const char *tablename, datetkn *base, unsigned int nel) ...@@ -3715,7 +3726,7 @@ CheckDateTokenTable(const char *tablename, datetkn *base, unsigned int nel)
{ {
if (strncmp(base[i-1].token, base[i].token, TOKMAXLEN) >= 0) if (strncmp(base[i-1].token, base[i].token, TOKMAXLEN) >= 0)
{ {
elog(LOG, "Ordering error in %s table: \"%.*s\" >= \"%.*s\"", elog(LOG, "ordering error in %s table: \"%.*s\" >= \"%.*s\"",
tablename, tablename,
TOKMAXLEN, base[i-1].token, TOKMAXLEN, base[i-1].token,
TOKMAXLEN, base[i].token); TOKMAXLEN, base[i].token);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.25 2002/09/04 20:31:27 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.26 2003/07/27 04:53:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -75,7 +75,10 @@ datumGetSize(Datum value, bool typByVal, int typLen) ...@@ -75,7 +75,10 @@ datumGetSize(Datum value, bool typByVal, int typLen)
struct varlena *s = (struct varlena *) DatumGetPointer(value); struct varlena *s = (struct varlena *) DatumGetPointer(value);
if (!PointerIsValid(s)) if (!PointerIsValid(s))
elog(ERROR, "datumGetSize: Invalid Datum Pointer"); ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
size = (Size) VARATT_SIZE(s); size = (Size) VARATT_SIZE(s);
} }
else if (typLen == -2) else if (typLen == -2)
...@@ -84,12 +87,15 @@ datumGetSize(Datum value, bool typByVal, int typLen) ...@@ -84,12 +87,15 @@ datumGetSize(Datum value, bool typByVal, int typLen)
char *s = (char *) DatumGetPointer(value); char *s = (char *) DatumGetPointer(value);
if (!PointerIsValid(s)) if (!PointerIsValid(s))
elog(ERROR, "datumGetSize: Invalid Datum Pointer"); ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
size = (Size) (strlen(s) + 1); size = (Size) (strlen(s) + 1);
} }
else else
{ {
elog(ERROR, "datumGetSize: Invalid typLen %d", typLen); elog(ERROR, "invalid typLen: %d", typLen);
size = 0; /* keep compiler quiet */ size = 0; /* keep compiler quiet */
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/encode.c,v 1.6 2001/11/05 17:46:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/encode.c,v 1.7 2003/07/27 04:53:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,7 +50,9 @@ binary_encode(PG_FUNCTION_ARGS) ...@@ -50,7 +50,9 @@ binary_encode(PG_FUNCTION_ARGS)
enc = pg_find_encoding(namebuf); enc = pg_find_encoding(namebuf);
if (enc == NULL) if (enc == NULL)
elog(ERROR, "No such encoding as '%s'", namebuf); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized encoding: \"%s\"", namebuf)));
resultlen = enc->encode_len(VARDATA(data), datalen); resultlen = enc->encode_len(VARDATA(data), datalen);
result = palloc(VARHDRSZ + resultlen); result = palloc(VARHDRSZ + resultlen);
...@@ -59,7 +61,7 @@ binary_encode(PG_FUNCTION_ARGS) ...@@ -59,7 +61,7 @@ binary_encode(PG_FUNCTION_ARGS)
/* Make this FATAL 'cause we've trodden on memory ... */ /* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen) if (res > resultlen)
elog(FATAL, "Overflow - encode estimate too small"); elog(FATAL, "overflow - encode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res; VARATT_SIZEP(result) = VARHDRSZ + res;
...@@ -84,7 +86,9 @@ binary_decode(PG_FUNCTION_ARGS) ...@@ -84,7 +86,9 @@ binary_decode(PG_FUNCTION_ARGS)
enc = pg_find_encoding(namebuf); enc = pg_find_encoding(namebuf);
if (enc == NULL) if (enc == NULL)
elog(ERROR, "No such encoding as '%s'", namebuf); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized encoding: \"%s\"", namebuf)));
resultlen = enc->decode_len(VARDATA(data), datalen); resultlen = enc->decode_len(VARDATA(data), datalen);
result = palloc(VARHDRSZ + resultlen); result = palloc(VARHDRSZ + resultlen);
...@@ -93,7 +97,7 @@ binary_decode(PG_FUNCTION_ARGS) ...@@ -93,7 +97,7 @@ binary_decode(PG_FUNCTION_ARGS)
/* Make this FATAL 'cause we've trodden on memory ... */ /* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen) if (res > resultlen)
elog(FATAL, "Overflow - decode estimate too small"); elog(FATAL, "overflow - decode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res; VARATT_SIZEP(result) = VARHDRSZ + res;
...@@ -141,7 +145,9 @@ get_hex(unsigned c) ...@@ -141,7 +145,9 @@ get_hex(unsigned c)
res = hexlookup[c]; res = hexlookup[c];
if (res < 0) if (res < 0)
elog(ERROR, "Bad hex code: '%c'", c); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid hex digit: \"%c\"", c)));
return (uint8) res; return (uint8) res;
} }
...@@ -167,7 +173,10 @@ hex_decode(const uint8 *src, unsigned len, uint8 *dst) ...@@ -167,7 +173,10 @@ hex_decode(const uint8 *src, unsigned len, uint8 *dst)
} }
v1 = get_hex(*s++) << 4; v1 = get_hex(*s++) << 4;
if (s >= srcend) if (s >= srcend)
elog(ERROR, "hex_decode: invalid data"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid hex data: odd number of digits")));
v2 = get_hex(*s++); v2 = get_hex(*s++);
*p++ = v1 | v2; *p++ = v1 | v2;
} }
...@@ -281,7 +290,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst) ...@@ -281,7 +290,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
else if (pos == 3) else if (pos == 3)
end = 2; end = 2;
else else
elog(ERROR, "base64: unexpected '='"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unexpected \"=\"")));
} }
b = 0; b = 0;
} }
...@@ -291,7 +302,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst) ...@@ -291,7 +302,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
if (c > 0 && c < 127) if (c > 0 && c < 127)
b = b64lookup[c]; b = b64lookup[c];
if (b < 0) if (b < 0)
elog(ERROR, "base64: Invalid symbol"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid symbol")));
} }
/* add it to buffer */ /* add it to buffer */
buf = (buf << 6) + b; buf = (buf << 6) + b;
...@@ -309,7 +322,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst) ...@@ -309,7 +322,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
} }
if (pos != 0) if (pos != 0)
elog(ERROR, "base64: invalid end sequence"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid end sequence")));
return p - dst; return p - dst;
} }
...@@ -416,7 +431,9 @@ esc_decode(const uint8 *src, unsigned srclen, uint8 *dst) ...@@ -416,7 +431,9 @@ esc_decode(const uint8 *src, unsigned srclen, uint8 *dst)
* One backslash, not followed by ### valid octal. Should * One backslash, not followed by ### valid octal. Should
* never get here, since esc_dec_len does same check. * never get here, since esc_dec_len does same check.
*/ */
elog(ERROR, "decode: Bad input string for type bytea"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for bytea")));
} }
len++; len++;
...@@ -479,7 +496,9 @@ esc_dec_len(const uint8 *src, unsigned srclen) ...@@ -479,7 +496,9 @@ esc_dec_len(const uint8 *src, unsigned srclen)
/* /*
* one backslash, not followed by ### valid octal * one backslash, not followed by ### valid octal
*/ */
elog(ERROR, "decode: Bad input string for type bytea"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for bytea")));
} }
len++; len++;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.89 2003/05/26 00:55:25 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.90 2003/07/27 04:53:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -115,7 +115,7 @@ static void CheckFloat8Val(double val); ...@@ -115,7 +115,7 @@ static void CheckFloat8Val(double val);
* check to see if a float4 val is outside of * check to see if a float4 val is outside of
* the FLOAT4_MIN, FLOAT4_MAX bounds. * the FLOAT4_MIN, FLOAT4_MAX bounds.
* *
* raise an elog warning if it is * raise an ereport warning if it is
*/ */
static void static void
CheckFloat4Val(double val) CheckFloat4Val(double val)
...@@ -128,9 +128,14 @@ CheckFloat4Val(double val) ...@@ -128,9 +128,14 @@ CheckFloat4Val(double val)
return; return;
#else #else
if (fabs(val) > FLOAT4_MAX) if (fabs(val) > FLOAT4_MAX)
elog(ERROR, "Bad float4 input format -- overflow"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float4 value out of range: overflow")));
if (val != 0.0 && fabs(val) < FLOAT4_MIN) if (val != 0.0 && fabs(val) < FLOAT4_MIN)
elog(ERROR, "Bad float4 input format -- underflow"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float4 value out of range: underflow")));
return; return;
#endif /* UNSAFE_FLOATS */ #endif /* UNSAFE_FLOATS */
} }
...@@ -139,7 +144,7 @@ CheckFloat4Val(double val) ...@@ -139,7 +144,7 @@ CheckFloat4Val(double val)
* check to see if a float8 val is outside of * check to see if a float8 val is outside of
* the FLOAT8_MIN, FLOAT8_MAX bounds. * the FLOAT8_MIN, FLOAT8_MAX bounds.
* *
* raise an elog error if it is * raise an ereport error if it is
*/ */
static void static void
CheckFloat8Val(double val) CheckFloat8Val(double val)
...@@ -152,9 +157,13 @@ CheckFloat8Val(double val) ...@@ -152,9 +157,13 @@ CheckFloat8Val(double val)
return; return;
#else #else
if (fabs(val) > FLOAT8_MAX) if (fabs(val) > FLOAT8_MAX)
elog(ERROR, "Bad float8 input format -- overflow"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float8 value out of range: overflow")));
if (val != 0.0 && fabs(val) < FLOAT8_MIN) if (val != 0.0 && fabs(val) < FLOAT8_MIN)
elog(ERROR, "Bad float8 input format -- underflow"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float8 value out of range: underflow")));
#endif /* UNSAFE_FLOATS */ #endif /* UNSAFE_FLOATS */
} }
...@@ -184,12 +193,17 @@ float4in(PG_FUNCTION_ARGS) ...@@ -184,12 +193,17 @@ float4in(PG_FUNCTION_ARGS)
if (strcasecmp(num, "NaN") == 0) if (strcasecmp(num, "NaN") == 0)
val = NAN; val = NAN;
else else
elog(ERROR, "Bad float4 input format '%s'", num); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for float4: \"%s\"",
num)));
} }
else else
{ {
if (errno == ERANGE) if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float4", num); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"%s\" is out of range for float4", num)));
} }
/* /*
...@@ -280,12 +294,17 @@ float8in(PG_FUNCTION_ARGS) ...@@ -280,12 +294,17 @@ float8in(PG_FUNCTION_ARGS)
else if (strcasecmp(num, "-Infinity") == 0) else if (strcasecmp(num, "-Infinity") == 0)
val = -HUGE_VAL; val = -HUGE_VAL;
else else
elog(ERROR, "Bad float8 input format '%s'", num); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for float8: \"%s\"",
num)));
} }
else else
{ {
if (errno == ERANGE) if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float8", num); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"%s\" is out of range for float8", num)));
} }
CheckFloat8Val(val); CheckFloat8Val(val);
...@@ -535,7 +554,9 @@ float4div(PG_FUNCTION_ARGS) ...@@ -535,7 +554,9 @@ float4div(PG_FUNCTION_ARGS)
double result; double result;
if (arg2 == 0.0) if (arg2 == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* Do division in float8, then check for overflow */ /* Do division in float8, then check for overflow */
result = (float8) arg1 / (float8) arg2; result = (float8) arg1 / (float8) arg2;
...@@ -597,7 +618,9 @@ float8div(PG_FUNCTION_ARGS) ...@@ -597,7 +618,9 @@ float8div(PG_FUNCTION_ARGS)
float8 result; float8 result;
if (arg2 == 0.0) if (arg2 == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = arg1 / arg2; result = arg1 / arg2;
...@@ -847,7 +870,9 @@ dtoi4(PG_FUNCTION_ARGS) ...@@ -847,7 +870,9 @@ dtoi4(PG_FUNCTION_ARGS)
int32 result; int32 result;
if ((num < INT_MIN) || (num > INT_MAX)) if ((num < INT_MIN) || (num > INT_MAX))
elog(ERROR, "dtoi4: integer out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int32) rint(num); result = (int32) rint(num);
PG_RETURN_INT32(result); PG_RETURN_INT32(result);
...@@ -864,7 +889,9 @@ dtoi2(PG_FUNCTION_ARGS) ...@@ -864,7 +889,9 @@ dtoi2(PG_FUNCTION_ARGS)
int16 result; int16 result;
if ((num < SHRT_MIN) || (num > SHRT_MAX)) if ((num < SHRT_MIN) || (num > SHRT_MAX))
elog(ERROR, "dtoi2: integer out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int16) rint(num); result = (int16) rint(num);
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
...@@ -909,7 +936,9 @@ ftoi4(PG_FUNCTION_ARGS) ...@@ -909,7 +936,9 @@ ftoi4(PG_FUNCTION_ARGS)
int32 result; int32 result;
if ((num < INT_MIN) || (num > INT_MAX)) if ((num < INT_MIN) || (num > INT_MAX))
elog(ERROR, "ftoi4: integer out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int32) rint(num); result = (int32) rint(num);
PG_RETURN_INT32(result); PG_RETURN_INT32(result);
...@@ -926,7 +955,9 @@ ftoi2(PG_FUNCTION_ARGS) ...@@ -926,7 +955,9 @@ ftoi2(PG_FUNCTION_ARGS)
int16 result; int16 result;
if ((num < SHRT_MIN) || (num > SHRT_MAX)) if ((num < SHRT_MIN) || (num > SHRT_MAX))
elog(ERROR, "ftoi2: integer out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int16) rint(num); result = (int16) rint(num);
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
...@@ -1160,7 +1191,9 @@ dsqrt(PG_FUNCTION_ARGS) ...@@ -1160,7 +1191,9 @@ dsqrt(PG_FUNCTION_ARGS)
float8 result; float8 result;
if (arg1 < 0) if (arg1 < 0)
elog(ERROR, "can't take sqrt of a negative number"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take square root of a negative number")));
result = sqrt(arg1); result = sqrt(arg1);
...@@ -1204,7 +1237,9 @@ dpow(PG_FUNCTION_ARGS) ...@@ -1204,7 +1237,9 @@ dpow(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "pow() result is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("result is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1232,7 +1267,9 @@ dexp(PG_FUNCTION_ARGS) ...@@ -1232,7 +1267,9 @@ dexp(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "exp() result is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("result is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1250,9 +1287,14 @@ dlog1(PG_FUNCTION_ARGS) ...@@ -1250,9 +1287,14 @@ dlog1(PG_FUNCTION_ARGS)
float8 result; float8 result;
if (arg1 == 0.0) if (arg1 == 0.0)
elog(ERROR, "can't take log of zero"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of zero")));
if (arg1 < 0) if (arg1 < 0)
elog(ERROR, "can't take log of a negative number"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of a negative number")));
result = log(arg1); result = log(arg1);
...@@ -1271,9 +1313,14 @@ dlog10(PG_FUNCTION_ARGS) ...@@ -1271,9 +1313,14 @@ dlog10(PG_FUNCTION_ARGS)
float8 result; float8 result;
if (arg1 == 0.0) if (arg1 == 0.0)
elog(ERROR, "can't take log of zero"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of zero")));
if (arg1 < 0) if (arg1 < 0)
elog(ERROR, "can't take log of a negative number"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of a negative number")));
result = log10(arg1); result = log10(arg1);
...@@ -1298,7 +1345,9 @@ dacos(PG_FUNCTION_ARGS) ...@@ -1298,7 +1345,9 @@ dacos(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "acos(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1321,7 +1370,9 @@ dasin(PG_FUNCTION_ARGS) ...@@ -1321,7 +1370,9 @@ dasin(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "asin(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1344,7 +1395,9 @@ datan(PG_FUNCTION_ARGS) ...@@ -1344,7 +1395,9 @@ datan(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "atan(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1368,7 +1421,9 @@ datan2(PG_FUNCTION_ARGS) ...@@ -1368,7 +1421,9 @@ datan2(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "atan2(%f,%f) input is out of range", arg1, arg2); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1391,7 +1446,9 @@ dcos(PG_FUNCTION_ARGS) ...@@ -1391,7 +1446,9 @@ dcos(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "cos(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1414,7 +1471,9 @@ dcot(PG_FUNCTION_ARGS) ...@@ -1414,7 +1471,9 @@ dcot(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "cot(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
result = 1.0 / result; result = 1.0 / result;
CheckFloat8Val(result); CheckFloat8Val(result);
...@@ -1438,7 +1497,9 @@ dsin(PG_FUNCTION_ARGS) ...@@ -1438,7 +1497,9 @@ dsin(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "sin(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1461,7 +1522,9 @@ dtan(PG_FUNCTION_ARGS) ...@@ -1461,7 +1522,9 @@ dtan(PG_FUNCTION_ARGS)
|| !finite(result) || !finite(result)
#endif #endif
) )
elog(ERROR, "tan(%f) input is out of range", arg1); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result); CheckFloat8Val(result);
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
...@@ -1777,7 +1840,9 @@ float48div(PG_FUNCTION_ARGS) ...@@ -1777,7 +1840,9 @@ float48div(PG_FUNCTION_ARGS)
float8 result; float8 result;
if (arg2 == 0.0) if (arg2 == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = arg1 / arg2; result = arg1 / arg2;
CheckFloat8Val(result); CheckFloat8Val(result);
...@@ -1837,7 +1902,9 @@ float84div(PG_FUNCTION_ARGS) ...@@ -1837,7 +1902,9 @@ float84div(PG_FUNCTION_ARGS)
float8 result; float8 result;
if (arg2 == 0.0) if (arg2 == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = arg1 / arg2; result = arg1 / arg2;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.34 2002/09/04 20:31:27 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.35 2003/07/27 04:53:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -133,8 +133,7 @@ format_type_internal(Oid type_oid, int32 typemod, ...@@ -133,8 +133,7 @@ format_type_internal(Oid type_oid, int32 typemod,
if (allow_invalid) if (allow_invalid)
return pstrdup("???"); return pstrdup("???");
else else
elog(ERROR, "could not locate data type with oid %u in catalog", elog(ERROR, "cache lookup failed for type %u", type_oid);
type_oid);
} }
typeform = (Form_pg_type) GETSTRUCT(tuple); typeform = (Form_pg_type) GETSTRUCT(tuple);
...@@ -159,8 +158,7 @@ format_type_internal(Oid type_oid, int32 typemod, ...@@ -159,8 +158,7 @@ format_type_internal(Oid type_oid, int32 typemod,
if (allow_invalid) if (allow_invalid)
return pstrdup("???[]"); return pstrdup("???[]");
else else
elog(ERROR, "could not locate data type with oid %u in catalog", elog(ERROR, "cache lookup failed for type %u", type_oid);
type_oid);
} }
typeform = (Form_pg_type) GETSTRUCT(tuple); typeform = (Form_pg_type) GETSTRUCT(tuple);
type_oid = array_base_type; type_oid = array_base_type;
...@@ -312,7 +310,7 @@ format_type_internal(Oid type_oid, int32 typemod, ...@@ -312,7 +310,7 @@ format_type_internal(Oid type_oid, int32 typemod,
fieldstr = ""; fieldstr = "";
break; break;
default: default:
elog(LOG, "Invalid INTERVAL typmod 0x%x", typemod); elog(ERROR, "invalid INTERVAL typmod: 0x%x", typemod);
fieldstr = ""; fieldstr = "";
break; break;
} }
......
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.c * formatting.c
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.63 2003/04/02 02:33:52 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.64 2003/07/27 04:53:05 tgl Exp $
* *
* *
* Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group
...@@ -961,7 +961,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -961,7 +961,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_BRACKET(num)) if (IS_BRACKET(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): '9' must be ahead of 'PR'."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"9\" must be ahead of \"PR\"")));
} }
if (IS_MULTI(num)) if (IS_MULTI(num))
{ {
...@@ -978,7 +980,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -978,7 +980,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_BRACKET(num)) if (IS_BRACKET(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): '0' must be ahead of 'PR'."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"0\" must be ahead of \"PR\"")));
} }
if (!IS_ZERO(num) && !IS_DECIMAL(num)) if (!IS_ZERO(num) && !IS_DECIMAL(num))
{ {
...@@ -1005,12 +1009,16 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1005,12 +1009,16 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): not unique decimal point."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("multiple decimal points")));
} }
if (IS_MULTI(num)) if (IS_MULTI(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'V' and decimal poin together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"V\" and decimal point together")));
} }
num->flag |= NUM_F_DECIMAL; num->flag |= NUM_F_DECIMAL;
break; break;
...@@ -1023,12 +1031,16 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1023,12 +1031,16 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): not unique 'S'."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("not unique \"S\"")));
} }
if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num)) if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'S' and 'PL'/'MI'/'SG'/'PR' together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
} }
if (!IS_DECIMAL(num)) if (!IS_DECIMAL(num))
{ {
...@@ -1050,7 +1062,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1050,7 +1062,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'S' and 'MI' together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"MI\" together")));
} }
num->flag |= NUM_F_MINUS; num->flag |= NUM_F_MINUS;
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
...@@ -1061,7 +1075,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1061,7 +1075,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'S' and 'PL' together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"PL\" together")));
} }
num->flag |= NUM_F_PLUS; num->flag |= NUM_F_PLUS;
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
...@@ -1072,7 +1088,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1072,7 +1088,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'S' and 'SG' together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"SG\" together")));
} }
num->flag |= NUM_F_MINUS; num->flag |= NUM_F_MINUS;
num->flag |= NUM_F_PLUS; num->flag |= NUM_F_PLUS;
...@@ -1082,7 +1100,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1082,7 +1100,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num)) if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'PR' and 'S'/'PL'/'MI'/'SG' together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
} }
num->flag |= NUM_F_BRACKET; num->flag |= NUM_F_BRACKET;
break; break;
...@@ -1101,14 +1121,18 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1101,14 +1121,18 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
{ {
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): can't use 'V' and decimal poin together."); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"V\" and decimal point together")));
} }
num->flag |= NUM_F_MULTI; num->flag |= NUM_F_MULTI;
break; break;
case NUM_E: case NUM_E:
NUM_cache_remove(last_NUMCacheEntry); NUM_cache_remove(last_NUMCacheEntry);
elog(ERROR, "to_char/to_number(): 'E' is not supported."); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"E\" is not supported")));
} }
return; return;
...@@ -1132,7 +1156,7 @@ parse_format(FormatNode *node, char *str, KeyWord *kw, ...@@ -1132,7 +1156,7 @@ parse_format(FormatNode *node, char *str, KeyWord *kw,
last = 0; last = 0;
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "to_char/number(): run parser."); elog(DEBUG_elog_output, "to_char/number(): run parser");
#endif #endif
n = node; n = node;
...@@ -1343,7 +1367,7 @@ dump_node(FormatNode *node, int max) ...@@ -1343,7 +1367,7 @@ dump_node(FormatNode *node, int max)
return; return;
} }
else else
elog(DEBUG_elog_output, "%d:\t UnKnown NODE !!!", a); elog(DEBUG_elog_output, "%d:\t unknown NODE!", a);
} }
} }
...@@ -1367,7 +1391,9 @@ get_th(char *num, int type) ...@@ -1367,7 +1391,9 @@ get_th(char *num, int type)
last = *(num + (len - 1)); last = *(num + (len - 1));
if (!isdigit((unsigned char) last)) if (!isdigit((unsigned char) last))
elog(ERROR, "get_th: '%s' is not number.", num); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%s\" is not a number", num)));
/* /*
* All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get * All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get
...@@ -1628,7 +1654,9 @@ strdigits_len(char *str) ...@@ -1628,7 +1654,9 @@ strdigits_len(char *str)
return len; return len;
} }
#define AMPM_ERROR elog(ERROR, "to_timestamp(): bad AM/PM string") #define AMPM_ERROR ereport(ERROR, \
(errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
errmsg("invalid AM/PM string")));
/* ---------- /* ----------
* Master function of TIME for: * Master function of TIME for:
...@@ -1972,15 +2000,19 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1972,15 +2000,19 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
return siz - 1; return siz - 1;
} }
else if (flag == FROM_CHAR) else if (flag == FROM_CHAR)
elog(ERROR, "to_timestamp(): TZ/tz not supported."); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"TZ\"/\"tz\" not supported")));
} }
return -1; return -1;
} }
#define CHECK_SEQ_SEARCH(_l, _s) \ #define CHECK_SEQ_SEARCH(_l, _s) \
do { \ do { \
if (_l <= 0) { \ if ((_l) <= 0) { \
elog(ERROR, "to_timestamp(): bad value for %s", _s); \ ereport(ERROR, \
(errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
errmsg("invalid value for %s", (_s)))); \
} \ } \
} while (0) } while (0)
...@@ -2614,7 +2646,7 @@ DCH_cache_getnew(char *str) ...@@ -2614,7 +2646,7 @@ DCH_cache_getnew(char *str)
DCHCacheEntry *old = DCHCache + 0; DCHCacheEntry *old = DCHCache + 0;
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Cache is full (%d)", n_DCHCache); elog(DEBUG_elog_output, "cache is full (%d)", n_DCHCache);
#endif #endif
for (ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++) for (ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
{ {
...@@ -2788,17 +2820,16 @@ timestamp_to_char(PG_FUNCTION_ARGS) ...@@ -2788,17 +2820,16 @@ timestamp_to_char(PG_FUNCTION_ARGS)
text *fmt = PG_GETARG_TEXT_P(1), text *fmt = PG_GETARG_TEXT_P(1),
*res; *res;
TmToChar tmtc; TmToChar tmtc;
int r = 0;
if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt)) if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt))
PG_RETURN_NULL(); PG_RETURN_NULL();
ZERO_tmtc(&tmtc); ZERO_tmtc(&tmtc);
r = timestamp2tm(dt, NULL, tmtcTm(&tmtc), &tmtcFsec(&tmtc), NULL); if (timestamp2tm(dt, NULL, tmtcTm(&tmtc), &tmtcFsec(&tmtc), NULL) != 0)
ereport(ERROR,
if (r != 0) (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
elog(ERROR, "to_char(): Unable to convert timestamp to tm"); errmsg("timestamp out of range")));
if (!(res = datetime_to_char_body(&tmtc, fmt))) if (!(res = datetime_to_char_body(&tmtc, fmt)))
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -2813,18 +2844,17 @@ timestamptz_to_char(PG_FUNCTION_ARGS) ...@@ -2813,18 +2844,17 @@ timestamptz_to_char(PG_FUNCTION_ARGS)
text *fmt = PG_GETARG_TEXT_P(1), text *fmt = PG_GETARG_TEXT_P(1),
*res; *res;
TmToChar tmtc; TmToChar tmtc;
int tz, int tz;
r = 0;
if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt)) if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt))
PG_RETURN_NULL(); PG_RETURN_NULL();
ZERO_tmtc(&tmtc); ZERO_tmtc(&tmtc);
r = timestamp2tm(dt, &tz, tmtcTm(&tmtc), &tmtcFsec(&tmtc), &tmtcTzn(&tmtc)); if (timestamp2tm(dt, &tz, tmtcTm(&tmtc), &tmtcFsec(&tmtc), &tmtcTzn(&tmtc)) != 0)
ereport(ERROR,
if (r != 0) (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
elog(ERROR, "to_char(): Unable to convert timestamp to tm"); errmsg("timestamp out of range")));
if (!(res = datetime_to_char_body(&tmtc, fmt))) if (!(res = datetime_to_char_body(&tmtc, fmt)))
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -3000,7 +3030,9 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -3000,7 +3030,9 @@ to_timestamp(PG_FUNCTION_ARGS)
if (tmfc.pm || tmfc.am) if (tmfc.pm || tmfc.am)
{ {
if (tm.tm_hour < 1 || tm.tm_hour > 12) if (tm.tm_hour < 1 || tm.tm_hour > 12)
elog(ERROR, "to_timestamp(): AM/PM hour must be between 1 and 12"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("AM/PM hour must be between 1 and 12")));
if (tmfc.pm && tm.tm_hour < 12) if (tmfc.pm && tm.tm_hour < 12)
tm.tm_hour += 12; tm.tm_hour += 12;
...@@ -3037,7 +3069,10 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -3037,7 +3069,10 @@ to_timestamp(PG_FUNCTION_ARGS)
if (tm.tm_year > 0) if (tm.tm_year > 0)
tm.tm_year = -(tm.tm_year - 1); tm.tm_year = -(tm.tm_year - 1);
else else
elog(ERROR, "Inconsistent use of year %04d and 'BC'", tm.tm_year); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("inconsistent use of year %04d and \"BC\"",
tm.tm_year)));
} }
if (tmfc.j) if (tmfc.j)
...@@ -3069,7 +3104,9 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -3069,7 +3104,9 @@ to_timestamp(PG_FUNCTION_ARGS)
{31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0}}; {31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0}};
if (!tm.tm_year) if (!tm.tm_year)
elog(ERROR, "to_timestamp() cat't convert yday without year information"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("cannot convert yday without year information")));
y = ysum[isleap(tm.tm_year)]; y = ysum[isleap(tm.tm_year)];
...@@ -3104,7 +3141,9 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -3104,7 +3141,9 @@ to_timestamp(PG_FUNCTION_ARGS)
tz = DetermineLocalTimeZone(&tm); tz = DetermineLocalTimeZone(&tm);
if (tm2timestamp(&tm, fsec, &tz, &result) != 0) if (tm2timestamp(&tm, fsec, &tz, &result) != 0)
elog(ERROR, "to_timestamp(): can't convert 'tm' to timestamp."); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
PG_RETURN_TIMESTAMP(result); PG_RETURN_TIMESTAMP(result);
} }
...@@ -3190,7 +3229,7 @@ NUM_cache_getnew(char *str) ...@@ -3190,7 +3229,7 @@ NUM_cache_getnew(char *str)
old = ent; old = ent;
} }
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "OLD: '%s' AGE: %d", old->str, old->age); elog(DEBUG_elog_output, "OLD: \"%s\" AGE: %d", old->str, old->age);
#endif #endif
StrNCpy(old->str, str, NUM_CACHE_SIZE + 1); StrNCpy(old->str, str, NUM_CACHE_SIZE + 1);
/* old->format fill parser */ /* old->format fill parser */
...@@ -3477,7 +3516,7 @@ get_last_relevant_decnum(char *num) ...@@ -3477,7 +3516,7 @@ get_last_relevant_decnum(char *num)
*p = strchr(num, '.'); *p = strchr(num, '.');
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "CALL: get_last_relevant_decnum()"); elog(DEBUG_elog_output, "get_last_relevant_decnum()");
#endif #endif
if (!p) if (!p)
...@@ -3523,7 +3562,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) ...@@ -3523,7 +3562,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
{ {
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read sign (%c).", *Np->inout_p); elog(DEBUG_elog_output, "Try read sign (%c)", *Np->inout_p);
#endif #endif
/* /*
...@@ -3535,7 +3574,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) ...@@ -3535,7 +3574,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
int x = strlen(Np->L_negative_sign); int x = strlen(Np->L_negative_sign);
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read locale sign (%c).", *Np->inout_p); elog(DEBUG_elog_output, "Try read locale sign (%c)", *Np->inout_p);
#endif #endif
if (!strncmp(Np->inout_p, Np->L_negative_sign, x)) if (!strncmp(Np->inout_p, Np->L_negative_sign, x))
{ {
...@@ -3554,7 +3593,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) ...@@ -3554,7 +3593,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
} }
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read sipmle sign (%c).", *Np->inout_p); elog(DEBUG_elog_output, "Try read simple sign (%c)", *Np->inout_p);
#endif #endif
/* /*
...@@ -3595,7 +3634,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) ...@@ -3595,7 +3634,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
Np->read_post++; Np->read_post++;
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Read digit (%c).", *Np->inout_p); elog(DEBUG_elog_output, "Read digit (%c)", *Np->inout_p);
#endif #endif
/* /*
...@@ -3606,7 +3645,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) ...@@ -3606,7 +3645,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
{ {
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read decimal point (%c).", *Np->inout_p); elog(DEBUG_elog_output, "Try read decimal point (%c)", *Np->inout_p);
#endif #endif
if (*Np->inout_p == '.') if (*Np->inout_p == '.')
{ {
...@@ -3621,7 +3660,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) ...@@ -3621,7 +3660,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
int x = strlen(Np->decimal); int x = strlen(Np->decimal);
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read locale point (%c).", *Np->inout_p); elog(DEBUG_elog_output, "Try read locale point (%c)",
*Np->inout_p);
#endif #endif
if (!strncmp(Np->inout_p, Np->decimal, x)) if (!strncmp(Np->inout_p, Np->decimal, x))
{ {
...@@ -3661,8 +3701,7 @@ NUM_numpart_to_char(NUMProc *Np, int id) ...@@ -3661,8 +3701,7 @@ NUM_numpart_to_char(NUMProc *Np, int id)
* current position in inout! * current position in inout!
*/ */
elog(DEBUG_elog_output, elog(DEBUG_elog_output,
"SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: \"%s\", INOUT: \"%s\"",
"SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: '%s', INOUT: '%s'",
Np->sign_wrote, Np->sign_wrote,
Np->num_curr, Np->num_curr,
Np->number_p, Np->number_p,
...@@ -3863,7 +3902,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, ...@@ -3863,7 +3902,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
if (IS_ROMAN(Np->Num)) if (IS_ROMAN(Np->Num))
{ {
if (Np->type == FROM_CHAR) if (Np->type == FROM_CHAR)
elog(ERROR, "to_number(): RN is not supported"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"RN\" not supported")));
Np->Num->lsign = Np->Num->pre_lsign_num = Np->Num->post = Np->Num->lsign = Np->Num->pre_lsign_num = Np->Num->post =
Np->Num->pre = Np->num_pre = Np->sign = 0; Np->Num->pre = Np->num_pre = Np->sign = 0;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.77 2003/05/13 18:03:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.78 2003/07/27 04:53:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -287,7 +287,9 @@ path_encode(bool closed, int npts, Point *pt) ...@@ -287,7 +287,9 @@ path_encode(bool closed, int npts, Point *pt)
/* Check for integer overflow */ /* Check for integer overflow */
if ((size - 2) / npts != (P_MAXLEN + 3)) if ((size - 2) / npts != (P_MAXLEN + 3))
elog(ERROR, "Too many points requested"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("too many points requested")));
result = palloc(size); result = palloc(size);
...@@ -308,7 +310,10 @@ path_encode(bool closed, int npts, Point *pt) ...@@ -308,7 +310,10 @@ path_encode(bool closed, int npts, Point *pt)
{ {
*cp++ = LDELIM; *cp++ = LDELIM;
if (!pair_encode(pt->x, pt->y, cp)) if (!pair_encode(pt->x, pt->y, cp))
elog(ERROR, "Unable to format path"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not format path")));
cp += strlen(cp); cp += strlen(cp);
*cp++ = RDELIM; *cp++ = RDELIM;
*cp++ = DELIM; *cp++ = DELIM;
...@@ -380,7 +385,9 @@ box_in(PG_FUNCTION_ARGS) ...@@ -380,7 +385,9 @@ box_in(PG_FUNCTION_ARGS)
if ((!path_decode(FALSE, 2, str, &isopen, &s, &(box->high))) if ((!path_decode(FALSE, 2, str, &isopen, &s, &(box->high)))
|| (*s != '\0')) || (*s != '\0'))
elog(ERROR, "Bad box external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for box: \"%s\"", str)));
/* reorder corners if necessary... */ /* reorder corners if necessary... */
if (box->high.x < box->low.x) if (box->high.x < box->low.x)
...@@ -891,12 +898,17 @@ line_in(PG_FUNCTION_ARGS) ...@@ -891,12 +898,17 @@ line_in(PG_FUNCTION_ARGS)
if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg.p[0]))) if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg.p[0])))
|| (*s != '\0')) || (*s != '\0'))
elog(ERROR, "Bad line external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for line: \"%s\"", str)));
line = (LINE *) palloc(sizeof(LINE)); line = (LINE *) palloc(sizeof(LINE));
line_construct_pts(line, &lseg.p[0], &lseg.p[1]); line_construct_pts(line, &lseg.p[0], &lseg.p[1]);
#else #else
elog(ERROR, "line not yet implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("line not yet implemented")));
line = NULL; line = NULL;
#endif #endif
...@@ -960,7 +972,9 @@ line_out(PG_FUNCTION_ARGS) ...@@ -960,7 +972,9 @@ line_out(PG_FUNCTION_ARGS)
return path_encode(TRUE, 2, (Point *) &(ls->p[0])); return path_encode(TRUE, 2, (Point *) &(ls->p[0]));
#else #else
elog(ERROR, "line not yet implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("line not yet implemented")));
result = NULL; result = NULL;
#endif #endif
...@@ -973,7 +987,9 @@ line_out(PG_FUNCTION_ARGS) ...@@ -973,7 +987,9 @@ line_out(PG_FUNCTION_ARGS)
Datum Datum
line_recv(PG_FUNCTION_ARGS) line_recv(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "line not yet implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("line not yet implemented")));
return 0; return 0;
} }
...@@ -983,7 +999,9 @@ line_recv(PG_FUNCTION_ARGS) ...@@ -983,7 +999,9 @@ line_recv(PG_FUNCTION_ARGS)
Datum Datum
line_send(PG_FUNCTION_ARGS) line_send(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "line not yet implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("line not yet implemented")));
return 0; return 0;
} }
...@@ -1306,7 +1324,9 @@ path_in(PG_FUNCTION_ARGS) ...@@ -1306,7 +1324,9 @@ path_in(PG_FUNCTION_ARGS)
int depth = 0; int depth = 0;
if ((npts = pair_count(str, ',')) <= 0) if ((npts = pair_count(str, ',')) <= 0)
elog(ERROR, "Bad path external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for path: \"%s\"", str)));
s = str; s = str;
while (isspace((unsigned char) *s)) while (isspace((unsigned char) *s))
...@@ -1327,7 +1347,9 @@ path_in(PG_FUNCTION_ARGS) ...@@ -1327,7 +1347,9 @@ path_in(PG_FUNCTION_ARGS)
if ((!path_decode(TRUE, npts, s, &isopen, &s, &(path->p[0]))) if ((!path_decode(TRUE, npts, s, &isopen, &s, &(path->p[0])))
&& (!((depth == 0) && (*s == '\0'))) && !((depth >= 1) && (*s == RDELIM))) && (!((depth == 0) && (*s == '\0'))) && !((depth >= 1) && (*s == RDELIM)))
elog(ERROR, "Bad path external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for path: \"%s\"", str)));
path->closed = (!isopen); path->closed = (!isopen);
...@@ -1362,7 +1384,9 @@ path_recv(PG_FUNCTION_ARGS) ...@@ -1362,7 +1384,9 @@ path_recv(PG_FUNCTION_ARGS)
closed = pq_getmsgbyte(buf); closed = pq_getmsgbyte(buf);
npts = pq_getmsgint(buf, sizeof(int32)); npts = pq_getmsgint(buf, sizeof(int32));
if (npts < 0 || npts >= (int32) (INT_MAX / sizeof(Point))) if (npts < 0 || npts >= (int32) (INT_MAX / sizeof(Point)))
elog(ERROR, "Invalid number of points in external path"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid number of points in external path")));
size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts; size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts;
path = (PATH *) palloc(size); path = (PATH *) palloc(size);
...@@ -1701,7 +1725,9 @@ point_in(PG_FUNCTION_ARGS) ...@@ -1701,7 +1725,9 @@ point_in(PG_FUNCTION_ARGS)
char *s; char *s;
if (!pair_decode(str, &x, &y, &s) || (*s != '\0')) if (!pair_decode(str, &x, &y, &s) || (*s != '\0'))
elog(ERROR, "Bad point external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for point: \"%s\"", str)));
point = (Point *) palloc(sizeof(Point)); point = (Point *) palloc(sizeof(Point));
...@@ -1927,7 +1953,9 @@ lseg_in(PG_FUNCTION_ARGS) ...@@ -1927,7 +1953,9 @@ lseg_in(PG_FUNCTION_ARGS)
if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg->p[0]))) if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg->p[0])))
|| (*s != '\0')) || (*s != '\0'))
elog(ERROR, "Bad lseg external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for lseg: \"%s\"", str)));
#ifdef NOT_USED #ifdef NOT_USED
lseg->m = point_sl(&lseg->p[0], &lseg->p[1]); lseg->m = point_sl(&lseg->p[0], &lseg->p[1]);
...@@ -2517,7 +2545,9 @@ dist_lb(PG_FUNCTION_ARGS) ...@@ -2517,7 +2545,9 @@ dist_lb(PG_FUNCTION_ARGS)
#endif #endif
/* need to think about this one for a while */ /* need to think about this one for a while */
elog(ERROR, "dist_lb not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("dist_lb not implemented")));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -3028,7 +3058,9 @@ close_lb(PG_FUNCTION_ARGS) ...@@ -3028,7 +3058,9 @@ close_lb(PG_FUNCTION_ARGS)
#endif #endif
/* think about this one for a while */ /* think about this one for a while */
elog(ERROR, "close_lb not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("close_lb not implemented")));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -3305,7 +3337,9 @@ make_bound_box(POLYGON *poly) ...@@ -3305,7 +3337,9 @@ make_bound_box(POLYGON *poly)
box_fill(&(poly->boundbox), x1, x2, y1, y2); box_fill(&(poly->boundbox), x1, x2, y1, y2);
} }
else else
elog(ERROR, "Unable to create bounding box for empty polygon"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot create bounding box for empty polygon")));
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------
...@@ -3327,7 +3361,9 @@ poly_in(PG_FUNCTION_ARGS) ...@@ -3327,7 +3361,9 @@ poly_in(PG_FUNCTION_ARGS)
char *s; char *s;
if ((npts = pair_count(str, ',')) <= 0) if ((npts = pair_count(str, ',')) <= 0)
elog(ERROR, "Bad polygon external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for polygon: \"%s\"", str)));
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts; size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts;
poly = (POLYGON *) palloc0(size); /* zero any holes */ poly = (POLYGON *) palloc0(size); /* zero any holes */
...@@ -3337,7 +3373,9 @@ poly_in(PG_FUNCTION_ARGS) ...@@ -3337,7 +3373,9 @@ poly_in(PG_FUNCTION_ARGS)
if ((!path_decode(FALSE, npts, str, &isopen, &s, &(poly->p[0]))) if ((!path_decode(FALSE, npts, str, &isopen, &s, &(poly->p[0])))
|| (*s != '\0')) || (*s != '\0'))
elog(ERROR, "Bad polygon external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for polygon: \"%s\"", str)));
make_bound_box(poly); make_bound_box(poly);
...@@ -3375,7 +3413,9 @@ poly_recv(PG_FUNCTION_ARGS) ...@@ -3375,7 +3413,9 @@ poly_recv(PG_FUNCTION_ARGS)
npts = pq_getmsgint(buf, sizeof(int32)); npts = pq_getmsgint(buf, sizeof(int32));
if (npts < 0 || npts >= (int32) ((INT_MAX - offsetof(POLYGON, p[0])) / sizeof(Point))) if (npts < 0 || npts >= (int32) ((INT_MAX - offsetof(POLYGON, p[0])) / sizeof(Point)))
elog(ERROR, "Invalid number of points in external polygon"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid number of points in external polygon")));
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts; size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts;
poly = (POLYGON *) palloc0(size); /* zero any holes */ poly = (POLYGON *) palloc0(size); /* zero any holes */
...@@ -3683,7 +3723,9 @@ poly_distance(PG_FUNCTION_ARGS) ...@@ -3683,7 +3723,9 @@ poly_distance(PG_FUNCTION_ARGS)
POLYGON *polyb = PG_GETARG_POLYGON_P(1); POLYGON *polyb = PG_GETARG_POLYGON_P(1);
#endif #endif
elog(ERROR, "poly_distance not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("poly_distance not implemented")));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -3762,7 +3804,9 @@ point_div(PG_FUNCTION_ARGS) ...@@ -3762,7 +3804,9 @@ point_div(PG_FUNCTION_ARGS)
div = (p2->x * p2->x) + (p2->y * p2->y); div = (p2->x * p2->x) + (p2->y * p2->y);
if (div == 0.0) if (div == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result->x = ((p1->x * p2->x) + (p1->y * p2->y)) / div; result->x = ((p1->x * p2->x) + (p1->y * p2->y)) / div;
result->y = ((p2->x * p1->y) - (p2->y * p1->x)) / div; result->y = ((p2->x * p1->y) - (p2->y * p1->x)) / div;
...@@ -3881,7 +3925,9 @@ path_add(PG_FUNCTION_ARGS) ...@@ -3881,7 +3925,9 @@ path_add(PG_FUNCTION_ARGS)
/* Check for integer overflow */ /* Check for integer overflow */
if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) || if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) ||
size <= base_size) size <= base_size)
elog(ERROR, "Too many points requested"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("too many points requested")));
result = (PATH *) palloc(size); result = (PATH *) palloc(size);
...@@ -3989,7 +4035,9 @@ path_center(PG_FUNCTION_ARGS) ...@@ -3989,7 +4035,9 @@ path_center(PG_FUNCTION_ARGS)
PATH *path = PG_GETARG_PATH_P(0); PATH *path = PG_GETARG_PATH_P(0);
#endif #endif
elog(ERROR, "path_center not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("path_center not implemented")));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -4004,7 +4052,9 @@ path_poly(PG_FUNCTION_ARGS) ...@@ -4004,7 +4052,9 @@ path_poly(PG_FUNCTION_ARGS)
/* This is not very consistent --- other similar cases return NULL ... */ /* This is not very consistent --- other similar cases return NULL ... */
if (!path->closed) if (!path->closed)
elog(ERROR, "Open path cannot be converted to polygon"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("open path cannot be converted to polygon")));
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * path->npts; size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * path->npts;
poly = (POLYGON *) palloc(size); poly = (POLYGON *) palloc(size);
...@@ -4169,7 +4219,9 @@ circle_in(PG_FUNCTION_ARGS) ...@@ -4169,7 +4219,9 @@ circle_in(PG_FUNCTION_ARGS)
} }
if (!pair_decode(s, &circle->center.x, &circle->center.y, &s)) if (!pair_decode(s, &circle->center.x, &circle->center.y, &s))
elog(ERROR, "Bad circle external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for circle: \"%s\"", str)));
if (*s == DELIM) if (*s == DELIM)
s++; s++;
...@@ -4177,7 +4229,9 @@ circle_in(PG_FUNCTION_ARGS) ...@@ -4177,7 +4229,9 @@ circle_in(PG_FUNCTION_ARGS)
s++; s++;
if ((!single_decode(s, &circle->radius, &s)) || (circle->radius < 0)) if ((!single_decode(s, &circle->radius, &s)) || (circle->radius < 0))
elog(ERROR, "Bad circle external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for circle: \"%s\"", str)));
while (depth > 0) while (depth > 0)
{ {
...@@ -4190,11 +4244,15 @@ circle_in(PG_FUNCTION_ARGS) ...@@ -4190,11 +4244,15 @@ circle_in(PG_FUNCTION_ARGS)
s++; s++;
} }
else else
elog(ERROR, "Bad circle external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for circle: \"%s\"", str)));
} }
if (*s != '\0') if (*s != '\0')
elog(ERROR, "Bad circle external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for circle: \"%s\"", str)));
PG_RETURN_CIRCLE_P(circle); PG_RETURN_CIRCLE_P(circle);
} }
...@@ -4214,13 +4272,17 @@ circle_out(PG_FUNCTION_ARGS) ...@@ -4214,13 +4272,17 @@ circle_out(PG_FUNCTION_ARGS)
*cp++ = LDELIM_C; *cp++ = LDELIM_C;
*cp++ = LDELIM; *cp++ = LDELIM;
if (!pair_encode(circle->center.x, circle->center.y, cp)) if (!pair_encode(circle->center.x, circle->center.y, cp))
elog(ERROR, "Unable to format circle"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not format circle")));
cp += strlen(cp); cp += strlen(cp);
*cp++ = RDELIM; *cp++ = RDELIM;
*cp++ = DELIM; *cp++ = DELIM;
if (!single_encode(circle->radius, cp)) if (!single_encode(circle->radius, cp))
elog(ERROR, "Unable to format circle"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not format circle")));
cp += strlen(cp); cp += strlen(cp);
*cp++ = RDELIM_C; *cp++ = RDELIM_C;
...@@ -4245,7 +4307,9 @@ circle_recv(PG_FUNCTION_ARGS) ...@@ -4245,7 +4307,9 @@ circle_recv(PG_FUNCTION_ARGS)
circle->radius = pq_getmsgfloat8(buf); circle->radius = pq_getmsgfloat8(buf);
if (circle->radius < 0) if (circle->radius < 0)
elog(ERROR, "Invalid radius in external circle"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid radius in external circle")));
PG_RETURN_CIRCLE_P(circle); PG_RETURN_CIRCLE_P(circle);
} }
...@@ -4736,15 +4800,24 @@ circle_poly(PG_FUNCTION_ARGS) ...@@ -4736,15 +4800,24 @@ circle_poly(PG_FUNCTION_ARGS)
double angle; double angle;
double anglestep; double anglestep;
if (FPzero(circle->radius) || (npts < 2)) if (FPzero(circle->radius))
elog(ERROR, "Unable to convert circle to polygon"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert zero-size circle to polygon")));
if (npts < 2)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("must request at least 2 points")));
base_size = sizeof(poly->p[0]) * npts; base_size = sizeof(poly->p[0]) * npts;
size = offsetof(POLYGON, p[0]) +base_size; size = offsetof(POLYGON, p[0]) +base_size;
/* Check for integer overflow */ /* Check for integer overflow */
if (base_size / npts != sizeof(poly->p[0]) || size <= base_size) if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
elog(ERROR, "Too many points requested"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("too many points requested")));
poly = (POLYGON *) palloc0(size); /* zero any holes */ poly = (POLYGON *) palloc0(size); /* zero any holes */
poly->size = size; poly->size = size;
...@@ -4777,7 +4850,9 @@ poly_circle(PG_FUNCTION_ARGS) ...@@ -4777,7 +4850,9 @@ poly_circle(PG_FUNCTION_ARGS)
int i; int i;
if (poly->npts < 2) if (poly->npts < 2)
elog(ERROR, "Unable to convert polygon to circle"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot convert empty polygon to circle")));
circle = (CIRCLE *) palloc(sizeof(CIRCLE)); circle = (CIRCLE *) palloc(sizeof(CIRCLE));
...@@ -4798,7 +4873,9 @@ poly_circle(PG_FUNCTION_ARGS) ...@@ -4798,7 +4873,9 @@ poly_circle(PG_FUNCTION_ARGS)
circle->radius /= poly->npts; circle->radius /= poly->npts;
if (FPzero(circle->radius)) if (FPzero(circle->radius))
elog(ERROR, "Unable to convert polygon to circle"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot convert empty polygon to circle")));
PG_RETURN_CIRCLE_P(circle); PG_RETURN_CIRCLE_P(circle);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.54 2003/05/09 15:44:40 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.55 2003/07/27 04:53:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -121,7 +121,10 @@ int2vectorin(PG_FUNCTION_ARGS) ...@@ -121,7 +121,10 @@ int2vectorin(PG_FUNCTION_ARGS)
while (*intString && isspace((unsigned char) *intString)) while (*intString && isspace((unsigned char) *intString))
intString++; intString++;
if (*intString) if (*intString)
elog(ERROR, "int2vector value has too many values"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("int2vector has too many elements")));
while (slot < INDEX_MAX_KEYS) while (slot < INDEX_MAX_KEYS)
result[slot++] = 0; result[slot++] = 0;
...@@ -281,10 +284,10 @@ i4toi2(PG_FUNCTION_ARGS) ...@@ -281,10 +284,10 @@ i4toi2(PG_FUNCTION_ARGS)
{ {
int32 arg1 = PG_GETARG_INT32(0); int32 arg1 = PG_GETARG_INT32(0);
if (arg1 < SHRT_MIN) if (arg1 < SHRT_MIN || arg1 > SHRT_MAX)
elog(ERROR, "i4toi2: '%d' causes int2 underflow", arg1); ereport(ERROR,
if (arg1 > SHRT_MAX) (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
elog(ERROR, "i4toi2: '%d' causes int2 overflow", arg1); errmsg("integer out of range")));
PG_RETURN_INT16((int16) arg1); PG_RETURN_INT16((int16) arg1);
} }
...@@ -640,7 +643,9 @@ int4div(PG_FUNCTION_ARGS) ...@@ -640,7 +643,9 @@ int4div(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1); int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2); PG_RETURN_INT32(arg1 / arg2);
} }
...@@ -703,7 +708,9 @@ int2div(PG_FUNCTION_ARGS) ...@@ -703,7 +708,9 @@ int2div(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1); int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT16(arg1 / arg2); PG_RETURN_INT16(arg1 / arg2);
} }
...@@ -742,7 +749,9 @@ int24div(PG_FUNCTION_ARGS) ...@@ -742,7 +749,9 @@ int24div(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1); int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2); PG_RETURN_INT32(arg1 / arg2);
} }
...@@ -781,7 +790,9 @@ int42div(PG_FUNCTION_ARGS) ...@@ -781,7 +790,9 @@ int42div(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1); int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2); PG_RETURN_INT32(arg1 / arg2);
} }
...@@ -793,7 +804,9 @@ int4mod(PG_FUNCTION_ARGS) ...@@ -793,7 +804,9 @@ int4mod(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1); int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2); PG_RETURN_INT32(arg1 % arg2);
} }
...@@ -805,7 +818,9 @@ int2mod(PG_FUNCTION_ARGS) ...@@ -805,7 +818,9 @@ int2mod(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1); int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT16(arg1 % arg2); PG_RETURN_INT16(arg1 % arg2);
} }
...@@ -817,7 +832,9 @@ int24mod(PG_FUNCTION_ARGS) ...@@ -817,7 +832,9 @@ int24mod(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1); int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2); PG_RETURN_INT32(arg1 % arg2);
} }
...@@ -829,7 +846,9 @@ int42mod(PG_FUNCTION_ARGS) ...@@ -829,7 +846,9 @@ int42mod(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1); int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0) if (arg2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2); PG_RETURN_INT32(arg1 % arg2);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.44 2003/05/09 15:44:40 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.45 2003/07/27 04:53:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
/* /*
* scanint8 --- try to parse a string into an int8. * scanint8 --- try to parse a string into an int8.
* *
* If errorOK is false, elog a useful error message if the string is bad. * If errorOK is false, ereport a useful error message if the string is bad.
* If errorOK is true, just return "false" for bad input. * If errorOK is true, just return "false" for bad input.
*/ */
bool bool
...@@ -83,7 +83,9 @@ scanint8(const char *str, bool errorOK, int64 *result) ...@@ -83,7 +83,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
if (errorOK) if (errorOK)
return false; return false;
else else
elog(ERROR, "Bad int8 external representation \"%s\"", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for int8: \"%s\"", str)));
} }
/* process digits */ /* process digits */
...@@ -96,7 +98,9 @@ scanint8(const char *str, bool errorOK, int64 *result) ...@@ -96,7 +98,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
if (errorOK) if (errorOK)
return false; return false;
else else
elog(ERROR, "int8 value out of range: \"%s\"", str); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
} }
tmp = newtmp; tmp = newtmp;
} }
...@@ -107,7 +111,9 @@ scanint8(const char *str, bool errorOK, int64 *result) ...@@ -107,7 +111,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
if (errorOK) if (errorOK)
return false; return false;
else else
elog(ERROR, "Bad int8 external representation \"%s\"", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for int8: \"%s\"", str)));
} }
*result = (sign < 0) ? -tmp : tmp; *result = (sign < 0) ? -tmp : tmp;
...@@ -139,7 +145,7 @@ int8out(PG_FUNCTION_ARGS) ...@@ -139,7 +145,7 @@ int8out(PG_FUNCTION_ARGS)
char buf[MAXINT8LEN + 1]; char buf[MAXINT8LEN + 1];
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val)) < 0) if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val)) < 0)
elog(ERROR, "Unable to format int8"); elog(ERROR, "could not format int8");
result = pstrdup(buf); result = pstrdup(buf);
PG_RETURN_CSTRING(result); PG_RETURN_CSTRING(result);
...@@ -515,7 +521,9 @@ int8div(PG_FUNCTION_ARGS) ...@@ -515,7 +521,9 @@ int8div(PG_FUNCTION_ARGS)
int64 val2 = PG_GETARG_INT64(1); int64 val2 = PG_GETARG_INT64(1);
if (val2 == 0) if (val2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2); PG_RETURN_INT64(val1 / val2);
} }
...@@ -542,7 +550,9 @@ int8mod(PG_FUNCTION_ARGS) ...@@ -542,7 +550,9 @@ int8mod(PG_FUNCTION_ARGS)
int64 result; int64 result;
if (val2 == 0) if (val2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = val1 / val2; result = val1 / val2;
result *= val2; result *= val2;
...@@ -638,7 +648,9 @@ int84div(PG_FUNCTION_ARGS) ...@@ -638,7 +648,9 @@ int84div(PG_FUNCTION_ARGS)
int32 val2 = PG_GETARG_INT32(1); int32 val2 = PG_GETARG_INT32(1);
if (val2 == 0) if (val2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2); PG_RETURN_INT64(val1 / val2);
} }
...@@ -677,7 +689,9 @@ int48div(PG_FUNCTION_ARGS) ...@@ -677,7 +689,9 @@ int48div(PG_FUNCTION_ARGS)
int64 val2 = PG_GETARG_INT64(1); int64 val2 = PG_GETARG_INT64(1);
if (val2 == 0) if (val2 == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2); PG_RETURN_INT64(val1 / val2);
} }
...@@ -767,7 +781,9 @@ int84(PG_FUNCTION_ARGS) ...@@ -767,7 +781,9 @@ int84(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */ /* Test for overflow by reverse-conversion. */
if ((int64) result != val) if ((int64) result != val)
elog(ERROR, "int8 conversion to int4 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result); PG_RETURN_INT32(result);
} }
...@@ -790,7 +806,9 @@ int82(PG_FUNCTION_ARGS) ...@@ -790,7 +806,9 @@ int82(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */ /* Test for overflow by reverse-conversion. */
if ((int64) result != val) if ((int64) result != val)
elog(ERROR, "int8 conversion to int2 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
} }
...@@ -826,7 +844,9 @@ dtoi8(PG_FUNCTION_ARGS) ...@@ -826,7 +844,9 @@ dtoi8(PG_FUNCTION_ARGS)
result = (int64) val; result = (int64) val;
if ((float8) result != val) if ((float8) result != val)
elog(ERROR, "Floating point conversion to int8 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT64(result); PG_RETURN_INT64(result);
} }
...@@ -863,7 +883,9 @@ ftoi8(PG_FUNCTION_ARGS) ...@@ -863,7 +883,9 @@ ftoi8(PG_FUNCTION_ARGS)
result = (int64) dval; result = (int64) dval;
if ((float8) result != dval) if ((float8) result != dval)
elog(ERROR, "Floating point conversion to int8 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT64(result); PG_RETURN_INT64(result);
} }
...@@ -878,7 +900,9 @@ i8tooid(PG_FUNCTION_ARGS) ...@@ -878,7 +900,9 @@ i8tooid(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */ /* Test for overflow by reverse-conversion. */
if ((int64) result != val) if ((int64) result != val)
elog(ERROR, "int8 conversion to OID is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("OID out of range")));
PG_RETURN_OID(result); PG_RETURN_OID(result);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.53 2002/09/03 21:45:42 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.54 2003/07/27 04:53:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -448,7 +448,11 @@ like_escape_bytea(PG_FUNCTION_ARGS) ...@@ -448,7 +448,11 @@ like_escape_bytea(PG_FUNCTION_ARGS)
*/ */
BYTEA_NextChar(e, elen); BYTEA_NextChar(e, elen);
if (elen != 0) if (elen != 0)
elog(ERROR, "ESCAPE string must be empty or one character"); ereport(ERROR,
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
errmsg("invalid escape string"),
errhint("Escape string must be empty or one character.")));
e = VARDATA(esc); e = VARDATA(esc);
/* /*
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Copyright (c) 1996-2002, PostgreSQL Global Development Group * Copyright (c) 1996-2002, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like_match.c,v 1.4 2002/09/03 21:45:42 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/like_match.c,v 1.5 2003/07/27 04:53:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -286,7 +286,11 @@ do_like_escape(text *pat, text *esc) ...@@ -286,7 +286,11 @@ do_like_escape(text *pat, text *esc)
*/ */
NextChar(e, elen); NextChar(e, elen);
if (elen != 0) if (elen != 0)
elog(ERROR, "ESCAPE string must be empty or one character"); ereport(ERROR,
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
errmsg("invalid escape string"),
errhint("Escape string must be empty or one character.")));
e = VARDATA(esc); e = VARDATA(esc);
/* /*
......
/* /*
* PostgreSQL type definitions for MAC addresses. * PostgreSQL type definitions for MAC addresses.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.28 2003/05/13 18:03:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.29 2003/07/27 04:53:06 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -60,12 +60,16 @@ macaddr_in(PG_FUNCTION_ARGS) ...@@ -60,12 +60,16 @@ macaddr_in(PG_FUNCTION_ARGS)
count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s", count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s",
&a, &b, &c, &d, &e, &f, junk); &a, &b, &c, &d, &e, &f, junk);
if (count != 6) if (count != 6)
elog(ERROR, "macaddr_in: error in parsing \"%s\"", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for macaddr: \"%s\"", str)));
if ((a < 0) || (a > 255) || (b < 0) || (b > 255) || if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
(c < 0) || (c > 255) || (d < 0) || (d > 255) || (c < 0) || (c > 255) || (d < 0) || (d > 255) ||
(e < 0) || (e > 255) || (f < 0) || (f > 255)) (e < 0) || (e > 255) || (f < 0) || (f > 255))
elog(ERROR, "macaddr_in: illegal address \"%s\"", str); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("invalid octet value in macaddr: \"%s\"", str)));
result = (macaddr *) palloc(sizeof(macaddr)); result = (macaddr *) palloc(sizeof(macaddr));
...@@ -181,7 +185,9 @@ text_macaddr(PG_FUNCTION_ARGS) ...@@ -181,7 +185,9 @@ text_macaddr(PG_FUNCTION_ARGS)
len = (VARSIZE(addr) - VARHDRSZ); len = (VARSIZE(addr) - VARHDRSZ);
if (len >= sizeof(str)) if (len >= sizeof(str))
elog(ERROR, "Text is too long to convert to MAC address"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("text too long to convert to MAC address")));
memcpy(str, VARDATA(addr), len); memcpy(str, VARDATA(addr), len);
*(str + len) = '\0'; *(str + len) = '\0';
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.109 2003/07/17 00:55:37 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.110 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -239,8 +239,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn) ...@@ -239,8 +239,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/ */
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1); StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN) if (strlen(tm->tm_zone) > MAXTZLEN)
elog(WARNING, "Invalid timezone \'%s\'", ereport(WARNING,
tm->tm_zone); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid timezone name: \"%s\"",
tm->tm_zone)));
} }
} }
} }
...@@ -273,8 +275,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn) ...@@ -273,8 +275,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/ */
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1); StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN) if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
elog(WARNING, "Invalid timezone \'%s\'", ereport(WARNING,
tzname[tm->tm_isdst]); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid timezone name: \"%s\"",
tzname[tm->tm_isdst])));
} }
} }
} }
...@@ -367,11 +371,15 @@ abstimein(PG_FUNCTION_ARGS) ...@@ -367,11 +371,15 @@ abstimein(PG_FUNCTION_ARGS)
ftype[MAXDATEFIELDS]; ftype[MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad abstime external representation (too long) '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for abstime: \"%s\"", str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad abstime external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for abstime: \"%s\"", str)));
switch (dtype) switch (dtype)
{ {
...@@ -401,7 +409,8 @@ abstimein(PG_FUNCTION_ARGS) ...@@ -401,7 +409,8 @@ abstimein(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "Bad abstime (internal coding error) '%s'", str); elog(ERROR, "unexpected dtype %d while parsing abstime \"%s\"",
dtype, str);
result = INVALID_ABSTIME; result = INVALID_ABSTIME;
break; break;
}; };
...@@ -513,7 +522,7 @@ abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b) ...@@ -513,7 +522,7 @@ abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
return -1; /* non-INVALID < INVALID */ return -1; /* non-INVALID < INVALID */
#if 0 #if 0
/* CURRENT is no longer stored internally... */ /* CURRENT is no longer stored internally... */
/* XXX this is broken, should go away: */ /* XXX this is broken, should go away: */
if (a == CURRENT_ABSTIME) if (a == CURRENT_ABSTIME)
a = GetCurrentTransactionStartTime(); a = GetCurrentTransactionStartTime();
...@@ -617,7 +626,9 @@ timestamp_abstime(PG_FUNCTION_ARGS) ...@@ -617,7 +626,9 @@ timestamp_abstime(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "Unable to convert timestamp to abstime"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = INVALID_ABSTIME; result = INVALID_ABSTIME;
} }
...@@ -641,7 +652,9 @@ abstime_timestamp(PG_FUNCTION_ARGS) ...@@ -641,7 +652,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
switch (abstime) switch (abstime)
{ {
case INVALID_ABSTIME: case INVALID_ABSTIME:
elog(ERROR, "Unable to convert abstime 'invalid' to timestamp"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert \"invalid\" abstime to timestamp")));
TIMESTAMP_NOBEGIN(result); TIMESTAMP_NOBEGIN(result);
break; break;
...@@ -656,8 +669,9 @@ abstime_timestamp(PG_FUNCTION_ARGS) ...@@ -656,8 +669,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
default: default:
abstime2tm(abstime, &tz, tm, &tzn); abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, NULL, &result) != 0) if (tm2timestamp(tm, 0, NULL, &result) != 0)
elog(ERROR, "Unable to convert ABSTIME to TIMESTAMP" ereport(ERROR,
"\n\tabstime_timestamp() internal error"); (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
break; break;
}; };
...@@ -685,7 +699,9 @@ timestamptz_abstime(PG_FUNCTION_ARGS) ...@@ -685,7 +699,9 @@ timestamptz_abstime(PG_FUNCTION_ARGS)
result = tm2abstime(tm, 0); result = tm2abstime(tm, 0);
else else
{ {
elog(ERROR, "Unable to convert timestamp to abstime"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = INVALID_ABSTIME; result = INVALID_ABSTIME;
} }
...@@ -709,7 +725,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS) ...@@ -709,7 +725,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
switch (abstime) switch (abstime)
{ {
case INVALID_ABSTIME: case INVALID_ABSTIME:
elog(ERROR, "Unable to convert abstime 'invalid' to timestamptz"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert \"invalid\" abstime to timestamptz")));
TIMESTAMP_NOBEGIN(result); TIMESTAMP_NOBEGIN(result);
break; break;
...@@ -724,8 +742,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS) ...@@ -724,8 +742,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
default: default:
abstime2tm(abstime, &tz, tm, &tzn); abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, &tz, &result) != 0) if (tm2timestamp(tm, 0, &tz, &result) != 0)
elog(ERROR, "Unable to convert ABSTIME to TIMESTAMP WITH TIME ZONE" ereport(ERROR,
"\n\tabstime_timestamptz() internal error"); (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
break; break;
}; };
...@@ -755,11 +774,15 @@ reltimein(PG_FUNCTION_ARGS) ...@@ -755,11 +774,15 @@ reltimein(PG_FUNCTION_ARGS)
char lowstr[MAXDATELEN + 1]; char lowstr[MAXDATELEN + 1];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad reltime external representation (too long) '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for reltime: \"%s\"", str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0)) || (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(ERROR, "Bad reltime external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for reltime: \"%s\"", str)));
switch (dtype) switch (dtype)
{ {
...@@ -769,7 +792,8 @@ reltimein(PG_FUNCTION_ARGS) ...@@ -769,7 +792,8 @@ reltimein(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "Bad reltime (internal coding error) '%s'", str); elog(ERROR, "unexpected dtype %d while parsing reltime \"%s\"",
dtype, str);
result = INVALID_RELTIME; result = INVALID_RELTIME;
break; break;
} }
...@@ -851,7 +875,10 @@ tintervalin(PG_FUNCTION_ARGS) ...@@ -851,7 +875,10 @@ tintervalin(PG_FUNCTION_ARGS)
interval = (TimeInterval) palloc(sizeof(TimeIntervalData)); interval = (TimeInterval) palloc(sizeof(TimeIntervalData));
if (istinterval(intervalstr, &t1, &t2) == 0) if (istinterval(intervalstr, &t1, &t2) == 0)
elog(ERROR, "Unable to decode tinterval '%s'", intervalstr); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for tinterval: \"%s\"",
intervalstr)));
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
interval->status = T_INTERVAL_INVAL; /* undefined */ interval->status = T_INTERVAL_INVAL; /* undefined */
...@@ -911,7 +938,10 @@ tintervalrecv(PG_FUNCTION_ARGS) ...@@ -911,7 +938,10 @@ tintervalrecv(PG_FUNCTION_ARGS)
interval->status = pq_getmsgint(buf, sizeof(interval->status)); interval->status = pq_getmsgint(buf, sizeof(interval->status));
if (!(interval->status == T_INTERVAL_INVAL || if (!(interval->status == T_INTERVAL_INVAL ||
interval->status == T_INTERVAL_VALID)) interval->status == T_INTERVAL_VALID))
elog(ERROR, "Invalid status in external tinterval"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid status in external tinterval")));
interval->data[0] = pq_getmsgint(buf, sizeof(interval->data[0])); interval->data[0] = pq_getmsgint(buf, sizeof(interval->data[0]));
interval->data[1] = pq_getmsgint(buf, sizeof(interval->data[1])); interval->data[1] = pq_getmsgint(buf, sizeof(interval->data[1]));
...@@ -1000,7 +1030,9 @@ reltime_interval(PG_FUNCTION_ARGS) ...@@ -1000,7 +1030,9 @@ reltime_interval(PG_FUNCTION_ARGS)
switch (reltime) switch (reltime)
{ {
case INVALID_RELTIME: case INVALID_RELTIME:
elog(ERROR, "Unable to convert reltime 'invalid' to interval"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert \"invalid\" reltime to interval")));
result->time = 0; result->time = 0;
result->month = 0; result->month = 0;
break; break;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.46 2003/05/15 15:50:18 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.47 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -48,12 +48,10 @@ namein(PG_FUNCTION_ARGS) ...@@ -48,12 +48,10 @@ namein(PG_FUNCTION_ARGS)
char *s = PG_GETARG_CSTRING(0); char *s = PG_GETARG_CSTRING(0);
NameData *result; NameData *result;
int len; int len;
char *ermsg;
/* verify encoding */ /* verify encoding */
len = strlen(s); len = strlen(s);
if ((ermsg = pg_verifymbstr(s, len))) pg_verifymbstr(s, len, false);
elog(ERROR, "%s", ermsg);
len = pg_mbcliplen(s, len, NAMEDATALEN - 1); len = pg_mbcliplen(s, len, NAMEDATALEN - 1);
...@@ -87,7 +85,11 @@ namerecv(PG_FUNCTION_ARGS) ...@@ -87,7 +85,11 @@ namerecv(PG_FUNCTION_ARGS)
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
if (nbytes >= NAMEDATALEN) if (nbytes >= NAMEDATALEN)
elog(ERROR, "namerecv: input name too long"); ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("identifier too long"),
errdetail("Identifier must be less than %d characters.",
NAMEDATALEN)));
result = (NameData *) palloc0(NAMEDATALEN); result = (NameData *) palloc0(NAMEDATALEN);
memcpy(result, str, nbytes); memcpy(result, str, nbytes);
pfree(str); pfree(str);
......
/* /*
* PostgreSQL type definitions for the INET and CIDR types. * PostgreSQL type definitions for the INET and CIDR types.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.42 2003/06/24 22:21:22 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.43 2003/07/27 04:53:07 tgl Exp $
* *
* Jon Postel RIP 16 Oct 1998 * Jon Postel RIP 16 Oct 1998
*/ */
...@@ -85,8 +85,11 @@ network_in(char *src, int type) ...@@ -85,8 +85,11 @@ network_in(char *src, int type)
bits = inet_net_pton(ip_family(dst), src, ip_addr(dst), bits = inet_net_pton(ip_family(dst), src, ip_addr(dst),
type ? ip_addrsize(dst) : -1); type ? ip_addrsize(dst) : -1);
if ((bits < 0) || (bits > ip_maxbits(dst))) if ((bits < 0) || (bits > ip_maxbits(dst)))
elog(ERROR, "invalid %s value '%s'", ereport(ERROR,
type ? "CIDR" : "INET", src); (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
/* translator: first %s is inet or cidr */
errmsg("invalid input syntax for %s: \"%s\"",
type ? "cidr" : "inet", src)));
/* /*
* Error check: CIDR values must not have any bits set beyond * Error check: CIDR values must not have any bits set beyond
...@@ -95,7 +98,10 @@ network_in(char *src, int type) ...@@ -95,7 +98,10 @@ network_in(char *src, int type)
if (type) if (type)
{ {
if (!addressOK(ip_addr(dst), bits, ip_family(dst))) if (!addressOK(ip_addr(dst), bits, ip_family(dst)))
elog(ERROR, "invalid CIDR value '%s': has bits set to right of mask", src); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid cidr value: \"%s\"", src),
errdetail("Value has bits set to right of mask.")));
} }
VARATT_SIZEP(dst) = VARHDRSZ VARATT_SIZEP(dst) = VARHDRSZ
...@@ -139,7 +145,10 @@ inet_out(PG_FUNCTION_ARGS) ...@@ -139,7 +145,10 @@ inet_out(PG_FUNCTION_ARGS)
dst = inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src), dst = inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
tmp, sizeof(tmp)); tmp, sizeof(tmp));
if (dst == NULL) if (dst == NULL)
elog(ERROR, "unable to print address (%s)", strerror(errno)); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* For CIDR, add /n if not present */ /* For CIDR, add /n if not present */
if (ip_type(src) && strchr(tmp, '/') == NULL) if (ip_type(src) && strchr(tmp, '/') == NULL)
{ {
...@@ -180,18 +189,25 @@ inet_recv(PG_FUNCTION_ARGS) ...@@ -180,18 +189,25 @@ inet_recv(PG_FUNCTION_ARGS)
ip_family(addr) = pq_getmsgbyte(buf); ip_family(addr) = pq_getmsgbyte(buf);
if (ip_family(addr) != AF_INET) if (ip_family(addr) != AF_INET)
elog(ERROR, "Invalid family in external inet"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid family in external inet")));
bits = pq_getmsgbyte(buf); bits = pq_getmsgbyte(buf);
if (bits < 0 || bits > ip_maxbits(addr)) if (bits < 0 || bits > ip_maxbits(addr))
elog(ERROR, "Invalid bits in external inet"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid bits in external inet")));
ip_bits(addr) = bits; ip_bits(addr) = bits;
ip_type(addr) = pq_getmsgbyte(buf); ip_type(addr) = pq_getmsgbyte(buf);
if (ip_type(addr) != 0 && ip_type(addr) != 1) if (ip_type(addr) != 0 && ip_type(addr) != 1)
elog(ERROR, "Invalid type in external inet"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid type in external inet")));
nb = pq_getmsgbyte(buf); nb = pq_getmsgbyte(buf);
if (nb != ip_addrsize(addr)) if (nb != ip_addrsize(addr))
elog(ERROR, "Invalid length in external inet"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid length in external inet")));
VARATT_SIZEP(addr) = VARHDRSZ VARATT_SIZEP(addr) = VARHDRSZ
+ ((char *)ip_addr(addr) - (char *) VARDATA(addr)) + ((char *)ip_addr(addr) - (char *) VARDATA(addr))
+ ip_addrsize(addr); + ip_addrsize(addr);
...@@ -207,7 +223,10 @@ inet_recv(PG_FUNCTION_ARGS) ...@@ -207,7 +223,10 @@ inet_recv(PG_FUNCTION_ARGS)
if (ip_type(addr)) if (ip_type(addr))
{ {
if (!addressOK(ip_addr(addr), bits, ip_family(addr))) if (!addressOK(ip_addr(addr), bits, ip_family(addr)))
elog(ERROR, "invalid external CIDR value: has bits set to right of mask"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid external CIDR value"),
errdetail("Value has bits set to right of mask.")));
} }
PG_RETURN_INET_P(addr); PG_RETURN_INET_P(addr);
...@@ -291,7 +310,9 @@ inet_set_masklen(PG_FUNCTION_ARGS) ...@@ -291,7 +310,9 @@ inet_set_masklen(PG_FUNCTION_ARGS)
bits = ip_maxbits(src); bits = ip_maxbits(src);
if ((bits < 0) || (bits > ip_maxbits(src))) if ((bits < 0) || (bits > ip_maxbits(src)))
elog(ERROR, "set_masklen - invalid value '%d'", bits); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid mask length: %d", bits)));
/* clone the original data */ /* clone the original data */
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct)); dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
...@@ -477,7 +498,9 @@ network_host(PG_FUNCTION_ARGS) ...@@ -477,7 +498,9 @@ network_host(PG_FUNCTION_ARGS)
/* force display of max bits, regardless of masklen... */ /* force display of max bits, regardless of masklen... */
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip), if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
tmp, sizeof(tmp)) == NULL) tmp, sizeof(tmp)) == NULL)
elog(ERROR, "unable to print host (%s)", strerror(errno)); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* Suppress /n if present (shouldn't happen now) */ /* Suppress /n if present (shouldn't happen now) */
if ((ptr = strchr(tmp, '/')) != NULL) if ((ptr = strchr(tmp, '/')) != NULL)
...@@ -501,7 +524,10 @@ network_show(PG_FUNCTION_ARGS) ...@@ -501,7 +524,10 @@ network_show(PG_FUNCTION_ARGS)
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip), if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
tmp, sizeof(tmp)) == NULL) tmp, sizeof(tmp)) == NULL)
elog(ERROR, "unable to print host (%s)", strerror(errno)); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* Add /n if not present (which it won't be) */ /* Add /n if not present (which it won't be) */
if (strchr(tmp, '/') == NULL) if (strchr(tmp, '/') == NULL)
{ {
...@@ -534,8 +560,9 @@ network_abbrev(PG_FUNCTION_ARGS) ...@@ -534,8 +560,9 @@ network_abbrev(PG_FUNCTION_ARGS)
ip_bits(ip), tmp, sizeof(tmp)); ip_bits(ip), tmp, sizeof(tmp));
if (dst == NULL) if (dst == NULL)
elog(ERROR, "unable to print address (%s)", ereport(ERROR,
strerror(errno)); (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* Return string as a text datum */ /* Return string as a text datum */
len = strlen(tmp); len = strlen(tmp);
...@@ -818,7 +845,7 @@ convert_network_to_scalar(Datum value, Oid typid) ...@@ -818,7 +845,7 @@ convert_network_to_scalar(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel/scalargtsel * Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one network and one non-network operand. * on an operator with one network and one non-network operand.
*/ */
elog(ERROR, "convert_network_to_scalar: unsupported type %u", typid); elog(ERROR, "unsupported type: %u", typid);
return 0; return 0;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.32 2002/09/04 20:31:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.33 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -59,7 +59,10 @@ int4notin(PG_FUNCTION_ARGS) ...@@ -59,7 +59,10 @@ int4notin(PG_FUNCTION_ARGS)
names = textToQualifiedNameList(relation_and_attr, "int4notin"); names = textToQualifiedNameList(relation_and_attr, "int4notin");
nnames = length(names); nnames = length(names);
if (nnames < 2) if (nnames < 2)
elog(ERROR, "int4notin: must provide relationname.attributename"); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax"),
errhint("Must provide \"relationname.attributename\".")));
attribute = strVal(nth(nnames - 1, names)); attribute = strVal(nth(nnames - 1, names));
names = ltruncate(nnames - 1, names); names = ltruncate(nnames - 1, names);
relrv = makeRangeVarFromNameList(names); relrv = makeRangeVarFromNameList(names);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* Copyright (c) 1998-2003, PostgreSQL Global Development Group * Copyright (c) 1998-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.62 2003/07/03 19:41:47 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.63 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -390,7 +390,9 @@ numeric_recv(PG_FUNCTION_ARGS) ...@@ -390,7 +390,9 @@ numeric_recv(PG_FUNCTION_ARGS)
len = (uint16) pq_getmsgint(buf, sizeof(uint16)); len = (uint16) pq_getmsgint(buf, sizeof(uint16));
if (len < 0 || len > NUMERIC_MAX_PRECISION + NUMERIC_MAX_RESULT_SCALE) if (len < 0 || len > NUMERIC_MAX_PRECISION + NUMERIC_MAX_RESULT_SCALE)
elog(ERROR, "Invalid length in external numeric"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid length in external numeric")));
alloc_var(&value, len); alloc_var(&value, len);
...@@ -399,14 +401,19 @@ numeric_recv(PG_FUNCTION_ARGS) ...@@ -399,14 +401,19 @@ numeric_recv(PG_FUNCTION_ARGS)
if (!(value.sign == NUMERIC_POS || if (!(value.sign == NUMERIC_POS ||
value.sign == NUMERIC_NEG || value.sign == NUMERIC_NEG ||
value.sign == NUMERIC_NAN)) value.sign == NUMERIC_NAN))
elog(ERROR, "Invalid sign in external numeric"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid sign in external numeric")));
value.dscale = (uint16) pq_getmsgint(buf, sizeof(uint16)); value.dscale = (uint16) pq_getmsgint(buf, sizeof(uint16));
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
NumericDigit d = pq_getmsgint(buf, sizeof(NumericDigit)); NumericDigit d = pq_getmsgint(buf, sizeof(NumericDigit));
if (d < 0 || d >= NBASE) if (d < 0 || d >= NBASE)
elog(ERROR, "Invalid digit in external numeric"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid digit in external numeric")));
value.digits[i] = d; value.digits[i] = d;
} }
...@@ -1610,14 +1617,18 @@ numeric_int4(PG_FUNCTION_ARGS) ...@@ -1610,14 +1617,18 @@ numeric_int4(PG_FUNCTION_ARGS)
/* XXX would it be better to return NULL? */ /* XXX would it be better to return NULL? */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int4"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert NaN to integer")));
/* Convert to variable format and thence to int8 */ /* Convert to variable format and thence to int8 */
init_var(&x); init_var(&x);
set_var_from_num(num, &x); set_var_from_num(num, &x);
if (!numericvar_to_int8(&x, &val)) if (!numericvar_to_int8(&x, &val))
elog(ERROR, "numeric conversion to int4 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
free_var(&x); free_var(&x);
...@@ -1626,7 +1637,9 @@ numeric_int4(PG_FUNCTION_ARGS) ...@@ -1626,7 +1637,9 @@ numeric_int4(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */ /* Test for overflow by reverse-conversion. */
if ((int64) result != val) if ((int64) result != val)
elog(ERROR, "numeric conversion to int4 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result); PG_RETURN_INT32(result);
} }
...@@ -1660,14 +1673,18 @@ numeric_int8(PG_FUNCTION_ARGS) ...@@ -1660,14 +1673,18 @@ numeric_int8(PG_FUNCTION_ARGS)
/* XXX would it be better to return NULL? */ /* XXX would it be better to return NULL? */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int8"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert NaN to integer")));
/* Convert to variable format and thence to int8 */ /* Convert to variable format and thence to int8 */
init_var(&x); init_var(&x);
set_var_from_num(num, &x); set_var_from_num(num, &x);
if (!numericvar_to_int8(&x, &result)) if (!numericvar_to_int8(&x, &result))
elog(ERROR, "numeric conversion to int8 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
free_var(&x); free_var(&x);
...@@ -1704,14 +1721,18 @@ numeric_int2(PG_FUNCTION_ARGS) ...@@ -1704,14 +1721,18 @@ numeric_int2(PG_FUNCTION_ARGS)
/* XXX would it be better to return NULL? */ /* XXX would it be better to return NULL? */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int2"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert NaN to integer")));
/* Convert to variable format and thence to int8 */ /* Convert to variable format and thence to int8 */
init_var(&x); init_var(&x);
set_var_from_num(num, &x); set_var_from_num(num, &x);
if (!numericvar_to_int8(&x, &val)) if (!numericvar_to_int8(&x, &val))
elog(ERROR, "numeric conversion to int2 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
free_var(&x); free_var(&x);
...@@ -1720,7 +1741,9 @@ numeric_int2(PG_FUNCTION_ARGS) ...@@ -1720,7 +1741,9 @@ numeric_int2(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */ /* Test for overflow by reverse-conversion. */
if ((int64) result != val) if ((int64) result != val)
elog(ERROR, "numeric conversion to int2 is out of range"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
} }
...@@ -1903,7 +1926,7 @@ do_numeric_accum(ArrayType *transarray, Numeric newval) ...@@ -1903,7 +1926,7 @@ do_numeric_accum(ArrayType *transarray, Numeric newval)
NUMERICOID, -1, false, 'i', NUMERICOID, -1, false, 'i',
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 3) if (ndatums != 3)
elog(ERROR, "do_numeric_accum: expected 3-element numeric array"); elog(ERROR, "expected 3-element numeric array");
N = transdatums[0]; N = transdatums[0];
sumX = transdatums[1]; sumX = transdatums[1];
sumX2 = transdatums[2]; sumX2 = transdatums[2];
...@@ -1994,7 +2017,7 @@ numeric_avg(PG_FUNCTION_ARGS) ...@@ -1994,7 +2017,7 @@ numeric_avg(PG_FUNCTION_ARGS)
NUMERICOID, -1, false, 'i', NUMERICOID, -1, false, 'i',
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 3) if (ndatums != 3)
elog(ERROR, "numeric_avg: expected 3-element numeric array"); elog(ERROR, "expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]); N = DatumGetNumeric(transdatums[0]);
sumX = DatumGetNumeric(transdatums[1]); sumX = DatumGetNumeric(transdatums[1]);
/* ignore sumX2 */ /* ignore sumX2 */
...@@ -2030,7 +2053,7 @@ numeric_variance(PG_FUNCTION_ARGS) ...@@ -2030,7 +2053,7 @@ numeric_variance(PG_FUNCTION_ARGS)
NUMERICOID, -1, false, 'i', NUMERICOID, -1, false, 'i',
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 3) if (ndatums != 3)
elog(ERROR, "numeric_variance: expected 3-element numeric array"); elog(ERROR, "expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]); N = DatumGetNumeric(transdatums[0]);
sumX = DatumGetNumeric(transdatums[1]); sumX = DatumGetNumeric(transdatums[1]);
sumX2 = DatumGetNumeric(transdatums[2]); sumX2 = DatumGetNumeric(transdatums[2]);
...@@ -2106,7 +2129,7 @@ numeric_stddev(PG_FUNCTION_ARGS) ...@@ -2106,7 +2129,7 @@ numeric_stddev(PG_FUNCTION_ARGS)
NUMERICOID, -1, false, 'i', NUMERICOID, -1, false, 'i',
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 3) if (ndatums != 3)
elog(ERROR, "numeric_stddev: expected 3-element numeric array"); elog(ERROR, "expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]); N = DatumGetNumeric(transdatums[0]);
sumX = DatumGetNumeric(transdatums[1]); sumX = DatumGetNumeric(transdatums[1]);
sumX2 = DatumGetNumeric(transdatums[2]); sumX2 = DatumGetNumeric(transdatums[2]);
...@@ -2296,7 +2319,7 @@ int2_avg_accum(PG_FUNCTION_ARGS) ...@@ -2296,7 +2319,7 @@ int2_avg_accum(PG_FUNCTION_ARGS)
* We copied the input array, so it's okay to scribble on it directly. * We copied the input array, so it's okay to scribble on it directly.
*/ */
if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData)) if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData))
elog(ERROR, "int2_avg_accum: expected 2-element int8 array"); elog(ERROR, "expected 2-element int8 array");
transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray); transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray);
transdata->count++; transdata->count++;
...@@ -2316,7 +2339,7 @@ int4_avg_accum(PG_FUNCTION_ARGS) ...@@ -2316,7 +2339,7 @@ int4_avg_accum(PG_FUNCTION_ARGS)
* We copied the input array, so it's okay to scribble on it directly. * We copied the input array, so it's okay to scribble on it directly.
*/ */
if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData)) if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData))
elog(ERROR, "int4_avg_accum: expected 2-element int8 array"); elog(ERROR, "expected 2-element int8 array");
transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray); transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray);
transdata->count++; transdata->count++;
...@@ -2334,7 +2357,7 @@ int8_avg(PG_FUNCTION_ARGS) ...@@ -2334,7 +2357,7 @@ int8_avg(PG_FUNCTION_ARGS)
sumd; sumd;
if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData)) if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData))
elog(ERROR, "int8_avg: expected 2-element int8 array"); elog(ERROR, "expected 2-element int8 array");
transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray); transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray);
/* SQL92 defines AVG of no values to be NULL */ /* SQL92 defines AVG of no values to be NULL */
...@@ -2542,7 +2565,9 @@ set_var_from_str(const char *str, NumericVar *dest) ...@@ -2542,7 +2565,9 @@ set_var_from_str(const char *str, NumericVar *dest)
} }
if (!isdigit((unsigned char) *cp)) if (!isdigit((unsigned char) *cp))
elog(ERROR, "Bad numeric input format '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for numeric: \"%s\"", str)));
decdigits = (unsigned char *) palloc(strlen(cp) + DEC_DIGITS*2); decdigits = (unsigned char *) palloc(strlen(cp) + DEC_DIGITS*2);
...@@ -2563,7 +2588,10 @@ set_var_from_str(const char *str, NumericVar *dest) ...@@ -2563,7 +2588,10 @@ set_var_from_str(const char *str, NumericVar *dest)
else if (*cp == '.') else if (*cp == '.')
{ {
if (have_dp) if (have_dp)
elog(ERROR, "Bad numeric input format '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for numeric: \"%s\"",
str)));
have_dp = TRUE; have_dp = TRUE;
cp++; cp++;
} }
...@@ -2584,11 +2612,17 @@ set_var_from_str(const char *str, NumericVar *dest) ...@@ -2584,11 +2612,17 @@ set_var_from_str(const char *str, NumericVar *dest)
cp++; cp++;
exponent = strtol(cp, &endptr, 10); exponent = strtol(cp, &endptr, 10);
if (endptr == cp) if (endptr == cp)
elog(ERROR, "Bad numeric input format '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for numeric: \"%s\"",
str)));
cp = endptr; cp = endptr;
if (exponent > NUMERIC_MAX_PRECISION || if (exponent > NUMERIC_MAX_PRECISION ||
exponent < -NUMERIC_MAX_PRECISION) exponent < -NUMERIC_MAX_PRECISION)
elog(ERROR, "Bad numeric input format '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for numeric: \"%s\"",
str)));
dweight += (int) exponent; dweight += (int) exponent;
dscale -= (int) exponent; dscale -= (int) exponent;
if (dscale < 0) if (dscale < 0)
...@@ -2599,7 +2633,10 @@ set_var_from_str(const char *str, NumericVar *dest) ...@@ -2599,7 +2633,10 @@ set_var_from_str(const char *str, NumericVar *dest)
while (*cp) while (*cp)
{ {
if (!isspace((unsigned char) *cp)) if (!isspace((unsigned char) *cp))
elog(ERROR, "Bad numeric input format '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for numeric: \"%s\"",
str)));
cp++; cp++;
} }
...@@ -2893,7 +2930,9 @@ make_result(NumericVar *var) ...@@ -2893,7 +2930,9 @@ make_result(NumericVar *var)
/* Check for overflow of int16 fields */ /* Check for overflow of int16 fields */
if (result->n_weight != weight || if (result->n_weight != weight ||
NUMERIC_DSCALE(result) != var->dscale) NUMERIC_DSCALE(result) != var->dscale)
elog(ERROR, "Value overflows numeric format"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value overflows numeric format")));
dump_numeric("make_result()", result); dump_numeric("make_result()", result);
return result; return result;
...@@ -2961,9 +3000,11 @@ apply_typmod(NumericVar *var, int32 typmod) ...@@ -2961,9 +3000,11 @@ apply_typmod(NumericVar *var, int32 typmod)
#error unsupported NBASE #error unsupported NBASE
#endif #endif
if (ddigits > maxdigits) if (ddigits > maxdigits)
elog(ERROR, "overflow on numeric " ereport(ERROR,
"ABS(value) >= 10^%d for field with precision %d scale %d", (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
ddigits-1, precision, scale); errmsg("numeric field overflow"),
errdetail("ABS(value) >= 10^%d for field with precision %d, scale %d.",
ddigits-1, precision, scale)));
break; break;
} }
ddigits -= DEC_DIGITS; ddigits -= DEC_DIGITS;
...@@ -3098,7 +3139,10 @@ numeric_to_double_no_overflow(Numeric num) ...@@ -3098,7 +3139,10 @@ numeric_to_double_no_overflow(Numeric num)
if (*endptr != '\0') if (*endptr != '\0')
{ {
/* shouldn't happen ... */ /* shouldn't happen ... */
elog(ERROR, "Bad float8 input format '%s'", tmp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for float8: \"%s\"",
tmp)));
} }
pfree(tmp); pfree(tmp);
...@@ -3121,7 +3165,10 @@ numericvar_to_double_no_overflow(NumericVar *var) ...@@ -3121,7 +3165,10 @@ numericvar_to_double_no_overflow(NumericVar *var)
if (*endptr != '\0') if (*endptr != '\0')
{ {
/* shouldn't happen ... */ /* shouldn't happen ... */
elog(ERROR, "Bad float8 input format '%s'", tmp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for float8: \"%s\"",
tmp)));
} }
pfree(tmp); pfree(tmp);
...@@ -3613,7 +3660,9 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result, ...@@ -3613,7 +3660,9 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result,
* unnormalized divisor. * unnormalized divisor.
*/ */
if (var2ndigits == 0 || var2digits[0] == 0) if (var2ndigits == 0 || var2digits[0] == 0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* /*
* Now result zero check * Now result zero check
...@@ -4006,7 +4055,9 @@ sqrt_var(NumericVar *arg, NumericVar *result, int rscale) ...@@ -4006,7 +4055,9 @@ sqrt_var(NumericVar *arg, NumericVar *result, int rscale)
} }
if (stat < 0) if (stat < 0)
elog(ERROR, "math error on numeric - cannot compute SQRT of negative value"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take square root of a negative number")));
init_var(&tmp_arg); init_var(&tmp_arg);
init_var(&tmp_val); init_var(&tmp_val);
...@@ -4094,7 +4145,9 @@ exp_var(NumericVar *arg, NumericVar *result, int rscale) ...@@ -4094,7 +4145,9 @@ exp_var(NumericVar *arg, NumericVar *result, int rscale)
x.weight--; x.weight--;
/* Guard against overflow */ /* Guard against overflow */
if (xintval >= NUMERIC_MAX_RESULT_SCALE * 3) if (xintval >= NUMERIC_MAX_RESULT_SCALE * 3)
elog(ERROR, "argument for EXP() too big"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("argument for EXP() too big")));
} }
/* Select an appropriate scale for internal calculation */ /* Select an appropriate scale for internal calculation */
...@@ -4218,7 +4271,9 @@ ln_var(NumericVar *arg, NumericVar *result, int rscale) ...@@ -4218,7 +4271,9 @@ ln_var(NumericVar *arg, NumericVar *result, int rscale)
int local_rscale; int local_rscale;
if (cmp_var(arg, &const_zero) <= 0) if (cmp_var(arg, &const_zero) <= 0)
elog(ERROR, "math error on numeric - cannot compute LN of value <= zero"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of a negative number")));
local_rscale = rscale + 8; local_rscale = rscale + 8;
...@@ -4462,7 +4517,9 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale) ...@@ -4462,7 +4517,9 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale)
{ {
case 0: case 0:
if (base->ndigits == 0) if (base->ndigits == 0)
elog(ERROR, "zero raised to zero is undefined"); ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("zero raised to zero is undefined")));
set_var_from_var(&const_one, result); set_var_from_var(&const_one, result);
result->dscale = rscale; /* no need to round */ result->dscale = rscale; /* no need to round */
return; return;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.54 2002/09/04 20:31:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.55 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -51,27 +51,28 @@ ...@@ -51,27 +51,28 @@
* c, if not 0, is the terminator character that may appear after the * c, if not 0, is the terminator character that may appear after the
* integer. If 0, the string must end after the integer. * integer. If 0, the string must end after the integer.
* *
* Unlike plain atoi(), this will throw elog() upon bad input format or * Unlike plain atoi(), this will throw ereport() upon bad input format or
* overflow. * overflow.
*/ */
int32 int32
pg_atoi(char *s, int size, int c) pg_atoi(char *s, int size, int c)
{ {
long l = 0; long l;
char *badp = NULL; char *badp = NULL;
errno = 0;
/* /*
* Some versions of strtol treat the empty string as an error, but * Some versions of strtol treat the empty string as an error, but
* some seem not to. Make an explicit test to be sure we catch it. * some seem not to. Make an explicit test to be sure we catch it.
*/ */
if (s == (char *) NULL) if (s == (char *) NULL)
elog(ERROR, "pg_atoi: NULL pointer"); elog(ERROR, "NULL pointer");
else if (*s == 0) if (*s == 0)
elog(ERROR, "pg_atoi: zero-length string"); ereport(ERROR,
else (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
errno = 0;
l = strtol(s, &badp, 10); l = strtol(s, &badp, 10);
/* /*
...@@ -79,54 +80,44 @@ pg_atoi(char *s, int size, int c) ...@@ -79,54 +80,44 @@ pg_atoi(char *s, int size, int c)
* set EINVAL, which simply means it couldn't parse the input string. * set EINVAL, which simply means it couldn't parse the input string.
* This is handled by the second "if" consistent across platforms. * This is handled by the second "if" consistent across platforms.
*/ */
if (errno && errno != EINVAL) if (errno && errno != ERANGE && errno != EINVAL)
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
if (badp && *badp && *badp != c) if (badp && *badp && *badp != c)
elog(ERROR, "pg_atoi: error in \"%s\": can\'t parse \"%s\"", s, badp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
switch (size) switch (size)
{ {
case sizeof(int32): case sizeof(int32):
if (errno == ERANGE
#if defined(HAVE_LONG_INT_64) #if defined(HAVE_LONG_INT_64)
/* won't get ERANGE on these with 64-bit longs... */ /* won't get ERANGE on these with 64-bit longs... */
if (l < INT_MIN) || l < INT_MIN || l > INT_MAX
{ #endif
errno = ERANGE; )
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); ereport(ERROR,
} (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
if (l > INT_MAX) errmsg("%s is out of range for int4", s)));
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
#endif /* HAVE_LONG_INT_64 */
break; break;
case sizeof(int16): case sizeof(int16):
if (l < SHRT_MIN) if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
{ ereport(ERROR,
errno = ERANGE; (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); errmsg("%s is out of range for int2", s)));
}
if (l > SHRT_MAX)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
break; break;
case sizeof(int8): case sizeof(int8):
if (l < SCHAR_MIN) if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX)
{ ereport(ERROR,
errno = ERANGE; (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); errmsg("%s is out of range for int1", s)));
}
if (l > SCHAR_MAX)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
break; break;
default: default:
elog(ERROR, "pg_atoi: invalid result size: %d", size); elog(ERROR, "unsupported result size: %d", size);
} }
return (int32) l; return (int32) l;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.48 2003/05/09 15:44:40 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.49 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,7 +34,6 @@ oidin_subr(const char *funcname, const char *s, char **endloc) ...@@ -34,7 +34,6 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
Oid result; Oid result;
errno = 0; errno = 0;
cvt = strtoul(s, &endptr, 10); cvt = strtoul(s, &endptr, 10);
/* /*
...@@ -44,12 +43,21 @@ oidin_subr(const char *funcname, const char *s, char **endloc) ...@@ -44,12 +43,21 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
* Note that for historical reasons we accept an empty string as * Note that for historical reasons we accept an empty string as
* meaning 0. * meaning 0.
*/ */
if (errno && errno != EINVAL) if (errno && errno != ERANGE && errno != EINVAL)
elog(ERROR, "%s: error reading \"%s\": %m", ereport(ERROR,
funcname, s); (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for OID: \"%s\"",
s)));
if (endptr == s && *endptr) if (endptr == s && *endptr)
elog(ERROR, "%s: error in \"%s\": can't parse \"%s\"", ereport(ERROR,
funcname, s, endptr); (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for OID: \"%s\"",
s)));
if (errno == ERANGE)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for OID", s)));
if (endloc) if (endloc)
{ {
...@@ -62,8 +70,10 @@ oidin_subr(const char *funcname, const char *s, char **endloc) ...@@ -62,8 +70,10 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
while (*endptr && isspace((unsigned char) *endptr)) while (*endptr && isspace((unsigned char) *endptr))
endptr++; endptr++;
if (*endptr) if (*endptr)
elog(ERROR, "%s: error in \"%s\": can't parse \"%s\"", ereport(ERROR,
funcname, s, endptr); (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for OID: \"%s\"",
s)));
} }
result = (Oid) cvt; result = (Oid) cvt;
...@@ -83,8 +93,9 @@ oidin_subr(const char *funcname, const char *s, char **endloc) ...@@ -83,8 +93,9 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
#if OID_MAX != ULONG_MAX #if OID_MAX != ULONG_MAX
if (cvt != (unsigned long) result && if (cvt != (unsigned long) result &&
cvt != (unsigned long) ((int) result)) cvt != (unsigned long) ((int) result))
elog(ERROR, "%s: error reading \"%s\": %s", ereport(ERROR,
funcname, s, strerror(ERANGE)); (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for OID", s)));
#endif #endif
return result; return result;
...@@ -160,7 +171,9 @@ oidvectorin(PG_FUNCTION_ARGS) ...@@ -160,7 +171,9 @@ oidvectorin(PG_FUNCTION_ARGS)
while (*oidString && isspace((unsigned char) *oidString)) while (*oidString && isspace((unsigned char) *oidString))
oidString++; oidString++;
if (*oidString) if (*oidString)
elog(ERROR, "oidvector value has too many values"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("oidvector has too many elements")));
while (slot < INDEX_MAX_KEYS) while (slot < INDEX_MAX_KEYS)
result[slot++] = InvalidOid; result[slot++] = InvalidOid;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.45 2003/07/27 03:16:20 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.46 2003/07/27 04:53:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -201,7 +201,9 @@ lpad(PG_FUNCTION_ARGS) ...@@ -201,7 +201,9 @@ lpad(PG_FUNCTION_ARGS)
/* check for integer overflow */ /* check for integer overflow */
if (len != 0 && bytelen / pg_database_encoding_max_length() != len) if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
elog(ERROR, "Requested length too large"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested length too large")));
ret = (text *) palloc(VARHDRSZ + bytelen); ret = (text *) palloc(VARHDRSZ + bytelen);
...@@ -296,7 +298,9 @@ rpad(PG_FUNCTION_ARGS) ...@@ -296,7 +298,9 @@ rpad(PG_FUNCTION_ARGS)
/* Check for integer overflow */ /* Check for integer overflow */
if (len != 0 && bytelen / pg_database_encoding_max_length() != len) if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
elog(ERROR, "Requested length too large"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested length too large")));
ret = (text *) palloc(VARHDRSZ + bytelen); ret = (text *) palloc(VARHDRSZ + bytelen);
m = len - s1len; m = len - s1len;
...@@ -917,7 +921,9 @@ repeat(PG_FUNCTION_ARGS) ...@@ -917,7 +921,9 @@ repeat(PG_FUNCTION_ARGS)
int check2 = check + VARHDRSZ; int check2 = check + VARHDRSZ;
if ((check / slen) != count || check2 <= check) if ((check / slen) != count || check2 <= check)
elog(ERROR, "Requested buffer is too large."); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested length too large")));
} }
result = (text *) palloc(tlen); result = (text *) palloc(tlen);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Portions Copyright (c) 2002, PostgreSQL Global Development Group * Portions Copyright (c) 2002, PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.20 2002/10/18 20:44:02 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.21 2003/07/27 04:53:07 tgl Exp $
* *
*----------------------------------------------------------------------- *-----------------------------------------------------------------------
*/ */
...@@ -157,7 +157,7 @@ lc_collate_is_c(void) ...@@ -157,7 +157,7 @@ lc_collate_is_c(void)
return (bool) result; return (bool) result;
localeptr = setlocale(LC_COLLATE, NULL); localeptr = setlocale(LC_COLLATE, NULL);
if (!localeptr) if (!localeptr)
elog(PANIC, "Invalid LC_COLLATE setting"); elog(ERROR, "invalid LC_COLLATE setting");
if (strcmp(localeptr, "C") == 0) if (strcmp(localeptr, "C") == 0)
result = true; result = true;
......
...@@ -186,12 +186,16 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS) ...@@ -186,12 +186,16 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
if (fcinfo->resultinfo == NULL || if (fcinfo->resultinfo == NULL ||
!IsA(fcinfo->resultinfo, ReturnSetInfo)) !IsA(fcinfo->resultinfo, ReturnSetInfo))
elog(ERROR, "pg_stat_get_backend_idset: called in context that does not accept a set result"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that "
"cannot accept a set")));
if (fmgr_info->fn_extra == NULL) if (fmgr_info->fn_extra == NULL)
{ {
if (fmgr_info->fn_mcxt == NULL) if (fmgr_info->fn_mcxt == NULL)
elog(ERROR, "No function memory context in set-function"); elog(ERROR, "no function memory context in set-function");
fmgr_info->fn_extra = MemoryContextAlloc(fmgr_info->fn_mcxt, fmgr_info->fn_extra = MemoryContextAlloc(fmgr_info->fn_mcxt,
2 * sizeof(int)); 2 * sizeof(int));
((int *) (fmgr_info->fn_extra))[0] = 0; ((int *) (fmgr_info->fn_extra))[0] = 0;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.7 2003/05/13 18:03:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.8 2003/07/27 04:53:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -33,7 +33,9 @@ ...@@ -33,7 +33,9 @@
Datum Datum
record_in(PG_FUNCTION_ARGS) record_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "RECORD"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -44,7 +46,9 @@ record_in(PG_FUNCTION_ARGS) ...@@ -44,7 +46,9 @@ record_in(PG_FUNCTION_ARGS)
Datum Datum
record_out(PG_FUNCTION_ARGS) record_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "RECORD"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -55,7 +59,9 @@ record_out(PG_FUNCTION_ARGS) ...@@ -55,7 +59,9 @@ record_out(PG_FUNCTION_ARGS)
Datum Datum
record_recv(PG_FUNCTION_ARGS) record_recv(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a value of type %s", "RECORD"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a value of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -66,7 +72,9 @@ record_recv(PG_FUNCTION_ARGS) ...@@ -66,7 +72,9 @@ record_recv(PG_FUNCTION_ARGS)
Datum Datum
record_send(PG_FUNCTION_ARGS) record_send(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "RECORD"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -134,7 +142,9 @@ cstring_send(PG_FUNCTION_ARGS) ...@@ -134,7 +142,9 @@ cstring_send(PG_FUNCTION_ARGS)
Datum Datum
any_in(PG_FUNCTION_ARGS) any_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "ANY"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type any")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -145,7 +155,9 @@ any_in(PG_FUNCTION_ARGS) ...@@ -145,7 +155,9 @@ any_in(PG_FUNCTION_ARGS)
Datum Datum
any_out(PG_FUNCTION_ARGS) any_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "ANY"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type any")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -157,7 +169,9 @@ any_out(PG_FUNCTION_ARGS) ...@@ -157,7 +169,9 @@ any_out(PG_FUNCTION_ARGS)
Datum Datum
anyarray_in(PG_FUNCTION_ARGS) anyarray_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "ANYARRAY"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type anyarray")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -183,7 +197,9 @@ anyarray_out(PG_FUNCTION_ARGS) ...@@ -183,7 +197,9 @@ anyarray_out(PG_FUNCTION_ARGS)
Datum Datum
anyarray_recv(PG_FUNCTION_ARGS) anyarray_recv(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a value of type %s", "ANYARRAY"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a value of type anyarray")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -231,7 +247,9 @@ void_out(PG_FUNCTION_ARGS) ...@@ -231,7 +247,9 @@ void_out(PG_FUNCTION_ARGS)
Datum Datum
trigger_in(PG_FUNCTION_ARGS) trigger_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "TRIGGER"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type trigger")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -242,7 +260,9 @@ trigger_in(PG_FUNCTION_ARGS) ...@@ -242,7 +260,9 @@ trigger_in(PG_FUNCTION_ARGS)
Datum Datum
trigger_out(PG_FUNCTION_ARGS) trigger_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "TRIGGER"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type trigger")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -254,7 +274,9 @@ trigger_out(PG_FUNCTION_ARGS) ...@@ -254,7 +274,9 @@ trigger_out(PG_FUNCTION_ARGS)
Datum Datum
language_handler_in(PG_FUNCTION_ARGS) language_handler_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "LANGUAGE_HANDLER"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type language_handler")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -265,7 +287,9 @@ language_handler_in(PG_FUNCTION_ARGS) ...@@ -265,7 +287,9 @@ language_handler_in(PG_FUNCTION_ARGS)
Datum Datum
language_handler_out(PG_FUNCTION_ARGS) language_handler_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "LANGUAGE_HANDLER"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type language_handler")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -277,7 +301,9 @@ language_handler_out(PG_FUNCTION_ARGS) ...@@ -277,7 +301,9 @@ language_handler_out(PG_FUNCTION_ARGS)
Datum Datum
internal_in(PG_FUNCTION_ARGS) internal_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "INTERNAL"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type internal")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -288,7 +314,9 @@ internal_in(PG_FUNCTION_ARGS) ...@@ -288,7 +314,9 @@ internal_in(PG_FUNCTION_ARGS)
Datum Datum
internal_out(PG_FUNCTION_ARGS) internal_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "INTERNAL"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type internal")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -300,7 +328,9 @@ internal_out(PG_FUNCTION_ARGS) ...@@ -300,7 +328,9 @@ internal_out(PG_FUNCTION_ARGS)
Datum Datum
opaque_in(PG_FUNCTION_ARGS) opaque_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "OPAQUE"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type opaque")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -311,7 +341,9 @@ opaque_in(PG_FUNCTION_ARGS) ...@@ -311,7 +341,9 @@ opaque_in(PG_FUNCTION_ARGS)
Datum Datum
opaque_out(PG_FUNCTION_ARGS) opaque_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "OPAQUE"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type opaque")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -323,7 +355,9 @@ opaque_out(PG_FUNCTION_ARGS) ...@@ -323,7 +355,9 @@ opaque_out(PG_FUNCTION_ARGS)
Datum Datum
anyelement_in(PG_FUNCTION_ARGS) anyelement_in(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot accept a constant of type %s", "ANYELEMENT"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type anyelement")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -334,7 +368,9 @@ anyelement_in(PG_FUNCTION_ARGS) ...@@ -334,7 +368,9 @@ anyelement_in(PG_FUNCTION_ARGS)
Datum Datum
anyelement_out(PG_FUNCTION_ARGS) anyelement_out(PG_FUNCTION_ARGS)
{ {
elog(ERROR, "Cannot display a value of type %s", "ANYELEMENT"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type anyelement")));
PG_RETURN_VOID(); /* keep compiler quiet */ PG_RETURN_VOID(); /* keep compiler quiet */
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.45 2003/02/06 20:25:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.46 2003/07/27 04:53:08 tgl Exp $
* *
* Alistair Crooks added the code for the regex caching * Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance * agc - cached the regular expressions used - there's a good chance
...@@ -171,7 +171,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, ...@@ -171,7 +171,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg)); pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
/* XXX should we pg_regfree here? */ /* XXX should we pg_regfree here? */
elog(ERROR, "Invalid regular expression: %s", errMsg); ereport(ERROR,
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
errmsg("invalid regular expression: %s", errMsg)));
} }
/* /*
...@@ -182,7 +184,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len, ...@@ -182,7 +184,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
if (re_temp.cre_pat == NULL) if (re_temp.cre_pat == NULL)
{ {
pg_regfree(&re_temp.cre_re); pg_regfree(&re_temp.cre_re);
elog(ERROR, "Out of memory"); ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
} }
memcpy(re_temp.cre_pat, text_re, text_re_len); memcpy(re_temp.cre_pat, text_re, text_re_len);
re_temp.cre_flags = cflags; re_temp.cre_flags = cflags;
...@@ -450,7 +454,10 @@ similar_escape(PG_FUNCTION_ARGS) ...@@ -450,7 +454,10 @@ similar_escape(PG_FUNCTION_ARGS)
if (elen == 0) if (elen == 0)
e = NULL; /* no escape character */ e = NULL; /* no escape character */
else if (elen != 1) else if (elen != 1)
elog(ERROR, "ESCAPE string must be empty or one character"); ereport(ERROR,
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
errmsg("invalid escape string"),
errhint("Escape string must be empty or one character.")));
} }
/* We need room for ^, $, and up to 2 output bytes per input byte */ /* We need room for ^, $, and up to 2 output bytes per input byte */
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.77 2003/05/12 23:08:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.78 2003/07/27 04:53:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -112,10 +112,16 @@ regprocin(PG_FUNCTION_ARGS) ...@@ -112,10 +112,16 @@ regprocin(PG_FUNCTION_ARGS)
heap_close(hdesc, AccessShareLock); heap_close(hdesc, AccessShareLock);
if (matches == 0) if (matches == 0)
elog(ERROR, "No procedure with name %s", pro_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no procedure with name %s", pro_name_or_oid)));
else if (matches > 1) else if (matches > 1)
elog(ERROR, "There is more than one procedure named %s", ereport(ERROR,
pro_name_or_oid); (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one procedure named %s",
pro_name_or_oid)));
PG_RETURN_OID(result); PG_RETURN_OID(result);
} }
...@@ -127,10 +133,14 @@ regprocin(PG_FUNCTION_ARGS) ...@@ -127,10 +133,14 @@ regprocin(PG_FUNCTION_ARGS)
clist = FuncnameGetCandidates(names, -1); clist = FuncnameGetCandidates(names, -1);
if (clist == NULL) if (clist == NULL)
elog(ERROR, "No procedure with name %s", pro_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no procedure with name %s", pro_name_or_oid)));
else if (clist->next != NULL) else if (clist->next != NULL)
elog(ERROR, "There is more than one procedure named %s", ereport(ERROR,
pro_name_or_oid); (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one procedure named %s",
pro_name_or_oid)));
result = clist->oid; result = clist->oid;
...@@ -275,7 +285,9 @@ regprocedurein(PG_FUNCTION_ARGS) ...@@ -275,7 +285,9 @@ regprocedurein(PG_FUNCTION_ARGS)
} }
if (clist == NULL) if (clist == NULL)
elog(ERROR, "No procedure with name %s", pro_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no procedure with name %s", pro_name_or_oid)));
result = clist->oid; result = clist->oid;
...@@ -450,10 +462,15 @@ regoperin(PG_FUNCTION_ARGS) ...@@ -450,10 +462,15 @@ regoperin(PG_FUNCTION_ARGS)
heap_close(hdesc, AccessShareLock); heap_close(hdesc, AccessShareLock);
if (matches == 0) if (matches == 0)
elog(ERROR, "No operator with name %s", opr_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no operator with name %s", opr_name_or_oid)));
else if (matches > 1) else if (matches > 1)
elog(ERROR, "There is more than one operator named %s", ereport(ERROR,
opr_name_or_oid); (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one operator named %s",
opr_name_or_oid)));
PG_RETURN_OID(result); PG_RETURN_OID(result);
} }
...@@ -465,10 +482,14 @@ regoperin(PG_FUNCTION_ARGS) ...@@ -465,10 +482,14 @@ regoperin(PG_FUNCTION_ARGS)
clist = OpernameGetCandidates(names, '\0'); clist = OpernameGetCandidates(names, '\0');
if (clist == NULL) if (clist == NULL)
elog(ERROR, "No operator with name %s", opr_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no operator with name %s", opr_name_or_oid)));
else if (clist->next != NULL) else if (clist->next != NULL)
elog(ERROR, "There is more than one operator named %s", ereport(ERROR,
opr_name_or_oid); (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one operator named %s",
opr_name_or_oid)));
result = clist->oid; result = clist->oid;
...@@ -613,9 +634,15 @@ regoperatorin(PG_FUNCTION_ARGS) ...@@ -613,9 +634,15 @@ regoperatorin(PG_FUNCTION_ARGS)
parseNameAndArgTypes(opr_name_or_oid, "regoperatorin", true, parseNameAndArgTypes(opr_name_or_oid, "regoperatorin", true,
&names, &nargs, argtypes); &names, &nargs, argtypes);
if (nargs == 1) if (nargs == 1)
elog(ERROR, "regoperatorin: use NONE to denote the missing argument of a unary operator"); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_PARAMETER),
errmsg("missing argument"),
errhint("Use NONE to denote the missing argument of a unary operator.")));
if (nargs != 2) if (nargs != 2)
elog(ERROR, "regoperatorin: provide two argument types for operator"); ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("too many arguments"),
errhint("Provide two argument types for operator.")));
if (argtypes[0] == InvalidOid) if (argtypes[0] == InvalidOid)
oprkind = 'l'; oprkind = 'l';
...@@ -633,7 +660,9 @@ regoperatorin(PG_FUNCTION_ARGS) ...@@ -633,7 +660,9 @@ regoperatorin(PG_FUNCTION_ARGS)
} }
if (clist == NULL) if (clist == NULL)
elog(ERROR, "No operator with name %s", opr_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no operator with name %s", opr_name_or_oid)));
result = clist->oid; result = clist->oid;
...@@ -803,7 +832,9 @@ regclassin(PG_FUNCTION_ARGS) ...@@ -803,7 +832,9 @@ regclassin(PG_FUNCTION_ARGS)
if (HeapTupleIsValid(tuple = systable_getnext(sysscan))) if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))
result = HeapTupleGetOid(tuple); result = HeapTupleGetOid(tuple);
else else
elog(ERROR, "No class with name %s", class_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("no class with name %s", class_name_or_oid)));
/* We assume there can be only one match */ /* We assume there can be only one match */
...@@ -967,7 +998,9 @@ regtypein(PG_FUNCTION_ARGS) ...@@ -967,7 +998,9 @@ regtypein(PG_FUNCTION_ARGS)
if (HeapTupleIsValid(tuple = systable_getnext(sysscan))) if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))
result = HeapTupleGetOid(tuple); result = HeapTupleGetOid(tuple);
else else
elog(ERROR, "No type with name %s", typ_name_or_oid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("no type with name %s", typ_name_or_oid)));
/* We assume there can be only one match */ /* We assume there can be only one match */
...@@ -1072,10 +1105,14 @@ stringToQualifiedNameList(const char *string, const char *caller) ...@@ -1072,10 +1105,14 @@ stringToQualifiedNameList(const char *string, const char *caller)
rawname = pstrdup(string); rawname = pstrdup(string);
if (!SplitIdentifierString(rawname, '.', &namelist)) if (!SplitIdentifierString(rawname, '.', &namelist))
elog(ERROR, "%s: invalid name syntax", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
if (namelist == NIL) if (namelist == NIL)
elog(ERROR, "%s: invalid name syntax", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
foreach(l, namelist) foreach(l, namelist)
{ {
...@@ -1132,7 +1169,9 @@ parseNameAndArgTypes(const char *string, const char *caller, ...@@ -1132,7 +1169,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
break; break;
} }
if (*ptr == '\0') if (*ptr == '\0')
elog(ERROR, "%s: expected a left parenthesis", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a left parenthesis")));
/* Separate the name and parse it into a list */ /* Separate the name and parse it into a list */
*ptr++ = '\0'; *ptr++ = '\0';
...@@ -1146,7 +1185,10 @@ parseNameAndArgTypes(const char *string, const char *caller, ...@@ -1146,7 +1185,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
break; break;
} }
if (*ptr2 != ')') if (*ptr2 != ')')
elog(ERROR, "%s: expected a right parenthesis", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a right parenthesis")));
*ptr2 = '\0'; *ptr2 = '\0';
/* Separate the remaining string into comma-separated type names */ /* Separate the remaining string into comma-separated type names */
...@@ -1162,7 +1204,9 @@ parseNameAndArgTypes(const char *string, const char *caller, ...@@ -1162,7 +1204,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
{ {
/* End of string. Okay unless we had a comma before. */ /* End of string. Okay unless we had a comma before. */
if (had_comma) if (had_comma)
elog(ERROR, "%s: expected a type name", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a type name")));
break; break;
} }
typename = ptr; typename = ptr;
...@@ -1192,7 +1236,10 @@ parseNameAndArgTypes(const char *string, const char *caller, ...@@ -1192,7 +1236,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
} }
} }
if (in_quote || paren_count != 0) if (in_quote || paren_count != 0)
elog(ERROR, "%s: improper type name", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("improper type name")));
ptr2 = ptr; ptr2 = ptr;
if (*ptr == ',') if (*ptr == ',')
{ {
...@@ -1224,7 +1271,10 @@ parseNameAndArgTypes(const char *string, const char *caller, ...@@ -1224,7 +1271,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
parseTypeString(typename, &typeid, &typmod); parseTypeString(typename, &typeid, &typmod);
} }
if (*nargs >= FUNC_MAX_ARGS) if (*nargs >= FUNC_MAX_ARGS)
elog(ERROR, "%s: too many argument datatypes", caller); ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("too many argument datatypes")));
argtypes[*nargs] = typeid; argtypes[*nargs] = typeid;
(*nargs)++; (*nargs)++;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* back to source text * back to source text
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.145 2003/07/04 02:51:34 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.146 2003/07/27 04:53:09 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -197,7 +197,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS) ...@@ -197,7 +197,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
* Connect to SPI manager * Connect to SPI manager
*/ */
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "get_ruledef: cannot connect to SPI manager"); elog(ERROR, "SPI_connect failed");
/* /*
* On the first call prepare the plan to lookup pg_rewrite. We read * On the first call prepare the plan to lookup pg_rewrite. We read
...@@ -212,7 +212,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS) ...@@ -212,7 +212,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
argtypes[0] = OIDOID; argtypes[0] = OIDOID;
plan = SPI_prepare(query_getrulebyoid, 1, argtypes); plan = SPI_prepare(query_getrulebyoid, 1, argtypes);
if (plan == NULL) if (plan == NULL)
elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getrulebyoid); elog(ERROR, "SPI_prepare failed for \"%s\"", query_getrulebyoid);
plan_getrulebyoid = SPI_saveplan(plan); plan_getrulebyoid = SPI_saveplan(plan);
} }
...@@ -223,11 +223,11 @@ pg_get_ruledef(PG_FUNCTION_ARGS) ...@@ -223,11 +223,11 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
nulls[0] = ' '; nulls[0] = ' ';
spirc = SPI_execp(plan_getrulebyoid, args, nulls, 1); spirc = SPI_execp(plan_getrulebyoid, args, nulls, 1);
if (spirc != SPI_OK_SELECT) if (spirc != SPI_OK_SELECT)
elog(ERROR, "failed to get pg_rewrite tuple for %u", ruleoid); elog(ERROR, "failed to get pg_rewrite tuple for rule %u", ruleoid);
if (SPI_processed != 1) if (SPI_processed != 1)
{ {
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_ruledef: SPI_finish() failed"); elog(ERROR, "SPI_finish failed");
ruledef = palloc(VARHDRSZ + 1); ruledef = palloc(VARHDRSZ + 1);
VARATT_SIZEP(ruledef) = VARHDRSZ + 1; VARATT_SIZEP(ruledef) = VARHDRSZ + 1;
VARDATA(ruledef)[0] = '-'; VARDATA(ruledef)[0] = '-';
...@@ -252,7 +252,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS) ...@@ -252,7 +252,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
* Disconnect from SPI manager * Disconnect from SPI manager
*/ */
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_ruledef: SPI_finish() failed"); elog(ERROR, "SPI_finish failed");
/* /*
* Easy - isn't it? * Easy - isn't it?
...@@ -313,7 +313,7 @@ pg_do_getviewdef(Oid viewoid) ...@@ -313,7 +313,7 @@ pg_do_getviewdef(Oid viewoid)
* Connect to SPI manager * Connect to SPI manager
*/ */
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "get_viewdef: cannot connect to SPI manager"); elog(ERROR, "SPI_connect failed");
/* /*
* On the first call prepare the plan to lookup pg_rewrite. We read * On the first call prepare the plan to lookup pg_rewrite. We read
...@@ -329,7 +329,7 @@ pg_do_getviewdef(Oid viewoid) ...@@ -329,7 +329,7 @@ pg_do_getviewdef(Oid viewoid)
argtypes[1] = NAMEOID; argtypes[1] = NAMEOID;
plan = SPI_prepare(query_getviewrule, 2, argtypes); plan = SPI_prepare(query_getviewrule, 2, argtypes);
if (plan == NULL) if (plan == NULL)
elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getviewrule); elog(ERROR, "SPI_prepare failed for \"%s\"", query_getviewrule);
plan_getviewrule = SPI_saveplan(plan); plan_getviewrule = SPI_saveplan(plan);
} }
...@@ -365,7 +365,7 @@ pg_do_getviewdef(Oid viewoid) ...@@ -365,7 +365,7 @@ pg_do_getviewdef(Oid viewoid)
* Disconnect from SPI manager * Disconnect from SPI manager
*/ */
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_viewdef: SPI_finish() failed"); elog(ERROR, "SPI_finish failed");
return ruledef; return ruledef;
} }
...@@ -404,8 +404,7 @@ pg_get_triggerdef(PG_FUNCTION_ARGS) ...@@ -404,8 +404,7 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
ht_trig = systable_getnext(tgscan); ht_trig = systable_getnext(tgscan);
if (!HeapTupleIsValid(ht_trig)) if (!HeapTupleIsValid(ht_trig))
elog(ERROR, "pg_get_triggerdef: there is no trigger with oid %u", elog(ERROR, "could not find tuple for trigger %u", trigid);
trigid);
trigrec = (Form_pg_trigger) GETSTRUCT(ht_trig); trigrec = (Form_pg_trigger) GETSTRUCT(ht_trig);
...@@ -552,7 +551,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS) ...@@ -552,7 +551,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
ObjectIdGetDatum(indexrelid), ObjectIdGetDatum(indexrelid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(ht_idx)) if (!HeapTupleIsValid(ht_idx))
elog(ERROR, "syscache lookup for index %u failed", indexrelid); elog(ERROR, "cache lookup failed for index %u", indexrelid);
idxrec = (Form_pg_index) GETSTRUCT(ht_idx); idxrec = (Form_pg_index) GETSTRUCT(ht_idx);
indrelid = idxrec->indrelid; indrelid = idxrec->indrelid;
...@@ -565,7 +564,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS) ...@@ -565,7 +564,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
ObjectIdGetDatum(indexrelid), ObjectIdGetDatum(indexrelid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(ht_idxrel)) if (!HeapTupleIsValid(ht_idxrel))
elog(ERROR, "syscache lookup for relid %u failed", indexrelid); elog(ERROR, "cache lookup failed for relation %u", indexrelid);
idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel); idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel);
/* /*
...@@ -575,7 +574,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS) ...@@ -575,7 +574,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
ObjectIdGetDatum(idxrelrec->relam), ObjectIdGetDatum(idxrelrec->relam),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(ht_am)) if (!HeapTupleIsValid(ht_am))
elog(ERROR, "syscache lookup for AM %u failed", idxrelrec->relam); elog(ERROR, "cache lookup failed for access method %u",
idxrelrec->relam);
amrec = (Form_pg_am) GETSTRUCT(ht_am); amrec = (Form_pg_am) GETSTRUCT(ht_am);
/* /*
...@@ -745,7 +745,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -745,7 +745,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
tup = systable_getnext(conscan); tup = systable_getnext(conscan);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "Failed to find constraint with OID %u", constraintId); elog(ERROR, "could not find tuple for constraint %u", constraintId);
conForm = (Form_pg_constraint) GETSTRUCT(tup); conForm = (Form_pg_constraint) GETSTRUCT(tup);
initStringInfo(&buf); initStringInfo(&buf);
...@@ -765,7 +765,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -765,7 +765,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
val = heap_getattr(tup, Anum_pg_constraint_conkey, val = heap_getattr(tup, Anum_pg_constraint_conkey,
RelationGetDescr(conDesc), &isnull); RelationGetDescr(conDesc), &isnull);
if (isnull) if (isnull)
elog(ERROR, "pg_get_constraintdef: Null conkey for constraint %u", elog(ERROR, "null conkey for constraint %u",
constraintId); constraintId);
decompile_column_index_array(val, conForm->conrelid, &buf); decompile_column_index_array(val, conForm->conrelid, &buf);
...@@ -778,7 +778,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -778,7 +778,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
val = heap_getattr(tup, Anum_pg_constraint_confkey, val = heap_getattr(tup, Anum_pg_constraint_confkey,
RelationGetDescr(conDesc), &isnull); RelationGetDescr(conDesc), &isnull);
if (isnull) if (isnull)
elog(ERROR, "pg_get_constraintdef: Null confkey for constraint %u", elog(ERROR, "null confkey for constraint %u",
constraintId); constraintId);
decompile_column_index_array(val, conForm->confrelid, &buf); decompile_column_index_array(val, conForm->confrelid, &buf);
...@@ -798,8 +798,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -798,8 +798,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
string = ""; string = "";
break; break;
default: default:
elog(ERROR, "pg_get_constraintdef: Unknown confmatchtype '%c' for constraint %u", elog(ERROR, "unrecognized confmatchtype: %d",
conForm->confmatchtype, constraintId); conForm->confmatchtype);
string = ""; /* keep compiler quiet */ string = ""; /* keep compiler quiet */
break; break;
} }
...@@ -824,8 +824,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -824,8 +824,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
string = "SET DEFAULT"; string = "SET DEFAULT";
break; break;
default: default:
elog(ERROR, "pg_get_constraintdef: Unknown confupdtype '%c' for constraint %u", elog(ERROR, "unrecognized confupdtype: %d",
conForm->confupdtype, constraintId); conForm->confupdtype);
string = NULL; /* keep compiler quiet */ string = NULL; /* keep compiler quiet */
break; break;
} }
...@@ -850,8 +850,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -850,8 +850,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
string = "SET DEFAULT"; string = "SET DEFAULT";
break; break;
default: default:
elog(ERROR, "pg_get_constraintdef: Unknown confdeltype '%c' for constraint %u", elog(ERROR, "unrecognized confdeltype: %d",
conForm->confdeltype, constraintId); conForm->confdeltype);
string = NULL; /* keep compiler quiet */ string = NULL; /* keep compiler quiet */
break; break;
} }
...@@ -881,7 +881,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -881,7 +881,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
val = heap_getattr(tup, Anum_pg_constraint_conkey, val = heap_getattr(tup, Anum_pg_constraint_conkey,
RelationGetDescr(conDesc), &isnull); RelationGetDescr(conDesc), &isnull);
if (isnull) if (isnull)
elog(ERROR, "pg_get_constraintdef: Null conkey for constraint %u", elog(ERROR, "null conkey for constraint %u",
constraintId); constraintId);
decompile_column_index_array(val, conForm->conrelid, &buf); decompile_column_index_array(val, conForm->conrelid, &buf);
...@@ -908,7 +908,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -908,7 +908,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
val = heap_getattr(tup, Anum_pg_constraint_conbin, val = heap_getattr(tup, Anum_pg_constraint_conbin,
RelationGetDescr(conDesc), &isnull); RelationGetDescr(conDesc), &isnull);
if (isnull) if (isnull)
elog(ERROR, "pg_get_constraintdef: Null consrc for constraint %u", elog(ERROR, "null consrc for constraint %u",
constraintId); constraintId);
conbin = DatumGetCString(DirectFunctionCall1(textout, val)); conbin = DatumGetCString(DirectFunctionCall1(textout, val));
...@@ -942,8 +942,10 @@ pg_get_constraintdef(PG_FUNCTION_ARGS) ...@@ -942,8 +942,10 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
break; break;
} }
default: default:
elog(ERROR, "pg_get_constraintdef: unsupported constraint type '%c'", ereport(ERROR,
conForm->contype); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unsupported constraint type \"%c\"",
conForm->contype)));
break; break;
} }
...@@ -1344,8 +1346,10 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc) ...@@ -1344,8 +1346,10 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
break; break;
default: default:
elog(ERROR, "get_ruledef: rule %s has unsupported event type %d", ereport(ERROR,
rulename, ev_type); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("rule \"%s\" has unsupported event type %d",
rulename, ev_type)));
break; break;
} }
...@@ -1546,7 +1550,7 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace, ...@@ -1546,7 +1550,7 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
break; break;
default: default:
elog(ERROR, "get_query_def: unknown query command type %d", elog(ERROR, "unrecognized query command type: %d",
query->commandType); query->commandType);
break; break;
} }
...@@ -1781,7 +1785,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, ...@@ -1781,7 +1785,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
appendStringInfo(buf, ") EXCEPT "); appendStringInfo(buf, ") EXCEPT ");
break; break;
default: default:
elog(ERROR, "get_setop_query: unexpected set op %d", elog(ERROR, "unrecognized set op: %d",
(int) op->op); (int) op->op);
} }
if (op->all) if (op->all)
...@@ -1793,7 +1797,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, ...@@ -1793,7 +1797,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
} }
else else
{ {
elog(ERROR, "get_setop_query: unexpected node %d", elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(setOp)); (int) nodeTag(setOp));
} }
} }
...@@ -1853,7 +1857,7 @@ get_insert_query_def(Query *query, deparse_context *context) ...@@ -1853,7 +1857,7 @@ get_insert_query_def(Query *query, deparse_context *context)
if (rte->rtekind != RTE_SUBQUERY) if (rte->rtekind != RTE_SUBQUERY)
continue; continue;
if (select_rte) if (select_rte)
elog(ERROR, "get_insert_query_def: too many RTEs in INSERT!"); elog(ERROR, "too many RTEs in INSERT");
select_rte = rte; select_rte = rte;
} }
...@@ -2005,7 +2009,10 @@ get_utility_query_def(Query *query, deparse_context *context) ...@@ -2005,7 +2009,10 @@ get_utility_query_def(Query *query, deparse_context *context)
stmt->relation->relname)); stmt->relation->relname));
} }
else else
elog(ERROR, "get_utility_query_def: unexpected statement type"); {
/* Currently only NOTIFY utility commands can appear in rules */
elog(ERROR, "unexpected utility statement type");
}
} }
...@@ -2036,8 +2043,7 @@ get_names_for_var(Var *var, deparse_context *context, ...@@ -2036,8 +2043,7 @@ get_names_for_var(Var *var, deparse_context *context,
while (sup-- > 0 && nslist != NIL) while (sup-- > 0 && nslist != NIL)
nslist = lnext(nslist); nslist = lnext(nslist);
if (nslist == NIL) if (nslist == NIL)
elog(ERROR, "get_names_for_var: bogus varlevelsup %d", elog(ERROR, "bogus varlevelsup: %d", var->varlevelsup);
var->varlevelsup);
dpns = (deparse_namespace *) lfirst(nslist); dpns = (deparse_namespace *) lfirst(nslist);
/* Find the relevant RTE */ /* Find the relevant RTE */
...@@ -2050,8 +2056,7 @@ get_names_for_var(Var *var, deparse_context *context, ...@@ -2050,8 +2056,7 @@ get_names_for_var(Var *var, deparse_context *context,
else else
rte = NULL; rte = NULL;
if (rte == NULL) if (rte == NULL)
elog(ERROR, "get_names_for_var: bogus varno %d", elog(ERROR, "bogus varno: %d", var->varno);
var->varno);
/* Emit results */ /* Emit results */
*schemaname = NULL; /* default assumptions */ *schemaname = NULL; /* default assumptions */
...@@ -2360,7 +2365,7 @@ get_rule_expr(Node *node, deparse_context *context, ...@@ -2360,7 +2365,7 @@ get_rule_expr(Node *node, deparse_context *context,
break; break;
default: default:
elog(ERROR, "get_rule_expr: unknown boolop %d", elog(ERROR, "unrecognized boolop: %d",
(int) expr->boolop); (int) expr->boolop);
} }
} }
...@@ -2394,7 +2399,7 @@ get_rule_expr(Node *node, deparse_context *context, ...@@ -2394,7 +2399,7 @@ get_rule_expr(Node *node, deparse_context *context,
/* lookup arg type and get the field name */ /* lookup arg type and get the field name */
typrelid = get_typ_typrelid(argType); typrelid = get_typ_typrelid(argType);
if (!OidIsValid(typrelid)) if (!OidIsValid(typrelid))
elog(ERROR, "Argument type %s of FieldSelect is not a tuple type", elog(ERROR, "argument type %s of FieldSelect is not a tuple type",
format_type_be(argType)); format_type_be(argType));
fieldname = get_relid_attribute_name(typrelid, fieldname = get_relid_attribute_name(typrelid,
fselect->fieldnum); fselect->fieldnum);
...@@ -2536,7 +2541,7 @@ get_rule_expr(Node *node, deparse_context *context, ...@@ -2536,7 +2541,7 @@ get_rule_expr(Node *node, deparse_context *context,
appendStringInfo(buf, " IS NOT NULL)"); appendStringInfo(buf, " IS NOT NULL)");
break; break;
default: default:
elog(ERROR, "get_rule_expr: unexpected nulltesttype %d", elog(ERROR, "unrecognized nulltesttype: %d",
(int) ntest->nulltesttype); (int) ntest->nulltesttype);
} }
} }
...@@ -2569,7 +2574,7 @@ get_rule_expr(Node *node, deparse_context *context, ...@@ -2569,7 +2574,7 @@ get_rule_expr(Node *node, deparse_context *context,
appendStringInfo(buf, " IS NOT UNKNOWN)"); appendStringInfo(buf, " IS NOT UNKNOWN)");
break; break;
default: default:
elog(ERROR, "get_rule_expr: unexpected booltesttype %d", elog(ERROR, "unrecognized booltesttype: %d",
(int) btest->booltesttype); (int) btest->booltesttype);
} }
} }
...@@ -2611,7 +2616,7 @@ get_rule_expr(Node *node, deparse_context *context, ...@@ -2611,7 +2616,7 @@ get_rule_expr(Node *node, deparse_context *context,
break; break;
default: default:
elog(ERROR, "get_rule_expr: unknown node type %d", nodeTag(node)); elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
break; break;
} }
} }
...@@ -2652,7 +2657,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context) ...@@ -2652,7 +2657,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tp)) if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup for operator %u failed", opno); elog(ERROR, "cache lookup failed for operator %u", opno);
optup = (Form_pg_operator) GETSTRUCT(tp); optup = (Form_pg_operator) GETSTRUCT(tp);
switch (optup->oprkind) switch (optup->oprkind)
{ {
...@@ -2671,7 +2676,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context) ...@@ -2671,7 +2676,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
InvalidOid)); InvalidOid));
break; break;
default: default:
elog(ERROR, "get_rule_expr: bogus oprkind"); elog(ERROR, "bogus oprkind: %d", optup->oprkind);
} }
ReleaseSysCache(tp); ReleaseSysCache(tp);
} }
...@@ -2849,7 +2854,7 @@ get_const_expr(Const *constval, deparse_context *context) ...@@ -2849,7 +2854,7 @@ get_const_expr(Const *constval, deparse_context *context)
ObjectIdGetDatum(constval->consttype), ObjectIdGetDatum(constval->consttype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup of type %u failed", constval->consttype); elog(ERROR, "cache lookup failed for type %u", constval->consttype);
typeStruct = (Form_pg_type) GETSTRUCT(typetup); typeStruct = (Form_pg_type) GETSTRUCT(typetup);
...@@ -3039,8 +3044,8 @@ get_sublink_expr(SubLink *sublink, deparse_context *context) ...@@ -3039,8 +3044,8 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
break; break;
default: default:
elog(ERROR, "get_sublink_expr: unsupported sublink type %d", elog(ERROR, "unrecognized sublink type: %d",
sublink->subLinkType); (int) sublink->subLinkType);
break; break;
} }
...@@ -3132,7 +3137,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) ...@@ -3132,7 +3137,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
coldeflist = rte->coldeflist; coldeflist = rte->coldeflist;
break; break;
default: default:
elog(ERROR, "unexpected rte kind %d", (int) rte->rtekind); elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
break; break;
} }
if (rte->alias != NULL) if (rte->alias != NULL)
...@@ -3204,7 +3209,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) ...@@ -3204,7 +3209,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
appendStringInfo(buf, " UNION JOIN "); appendStringInfo(buf, " UNION JOIN ");
break; break;
default: default:
elog(ERROR, "get_from_clause_item: unknown join type %d", elog(ERROR, "unrecognized join type: %d",
(int) j->jointype); (int) j->jointype);
} }
get_from_clause_item(j->rarg, query, context); get_from_clause_item(j->rarg, query, context);
...@@ -3254,8 +3259,8 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) ...@@ -3254,8 +3259,8 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
} }
} }
else else
elog(ERROR, "get_from_clause_item: unexpected node type %d", elog(ERROR, "unrecognized node type: %d",
nodeTag(jtnode)); (int) nodeTag(jtnode));
} }
/* /*
...@@ -3361,7 +3366,8 @@ tleIsArrayAssign(TargetEntry *tle) ...@@ -3361,7 +3366,8 @@ tleIsArrayAssign(TargetEntry *tle)
*/ */
if (aref->refexpr == NULL || !IsA(aref->refexpr, Var) || if (aref->refexpr == NULL || !IsA(aref->refexpr, Var) ||
((Var *) aref->refexpr)->varattno != tle->resdom->resno) ((Var *) aref->refexpr)->varattno != tle->resdom->resno)
elog(WARNING, "tleIsArrayAssign: I'm confused ..."); elog(ERROR, "unrecognized situation in array assignment");
return true; return true;
} }
...@@ -3483,7 +3489,7 @@ generate_relation_name(Oid relid) ...@@ -3483,7 +3489,7 @@ generate_relation_name(Oid relid)
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tp)) if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup of relation %u failed", relid); elog(ERROR, "cache lookup failed for relation %u", relid);
reltup = (Form_pg_class) GETSTRUCT(tp); reltup = (Form_pg_class) GETSTRUCT(tp);
/* Qualify the name if not visible in search path */ /* Qualify the name if not visible in search path */
...@@ -3525,7 +3531,7 @@ generate_function_name(Oid funcid, int nargs, Oid *argtypes) ...@@ -3525,7 +3531,7 @@ generate_function_name(Oid funcid, int nargs, Oid *argtypes)
ObjectIdGetDatum(funcid), ObjectIdGetDatum(funcid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(proctup)) if (!HeapTupleIsValid(proctup))
elog(ERROR, "cache lookup of function %u failed", funcid); elog(ERROR, "cache lookup failed for function %u", funcid);
procform = (Form_pg_proc) GETSTRUCT(proctup); procform = (Form_pg_proc) GETSTRUCT(proctup);
proname = NameStr(procform->proname); proname = NameStr(procform->proname);
Assert(nargs == procform->pronargs); Assert(nargs == procform->pronargs);
...@@ -3579,7 +3585,7 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2) ...@@ -3579,7 +3585,7 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2)
ObjectIdGetDatum(operid), ObjectIdGetDatum(operid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(opertup)) if (!HeapTupleIsValid(opertup))
elog(ERROR, "cache lookup of operator %u failed", operid); elog(ERROR, "cache lookup failed for operator %u", operid);
operform = (Form_pg_operator) GETSTRUCT(opertup); operform = (Form_pg_operator) GETSTRUCT(opertup);
oprname = NameStr(operform->oprname); oprname = NameStr(operform->oprname);
...@@ -3600,8 +3606,7 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2) ...@@ -3600,8 +3606,7 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2)
p_result = right_oper(makeList1(makeString(oprname)), arg1, true); p_result = right_oper(makeList1(makeString(oprname)), arg1, true);
break; break;
default: default:
elog(ERROR, "unexpected oprkind %c for operator %u", elog(ERROR, "unrecognized oprkind: %d", operform->oprkind);
operform->oprkind, operid);
p_result = NULL; /* keep compiler quiet */ p_result = NULL; /* keep compiler quiet */
break; break;
} }
...@@ -3664,7 +3669,7 @@ get_relid_attribute_name(Oid relid, AttrNumber attnum) ...@@ -3664,7 +3669,7 @@ get_relid_attribute_name(Oid relid, AttrNumber attnum)
attname = get_attname(relid, attnum); attname = get_attname(relid, attnum);
if (attname == NULL) if (attname == NULL)
elog(ERROR, "cache lookup of attribute %d in relation %u failed", elog(ERROR, "cache lookup failed for attribute %d of relation %u",
attnum, relid); attnum, relid);
return attname; return attname;
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.141 2003/07/17 22:20:14 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.142 2003/07/27 04:53:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -939,7 +939,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) ...@@ -939,7 +939,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
prefix->constvalue)); prefix->constvalue));
break; break;
default: default:
elog(ERROR, "patternsel: unexpected consttype %u", elog(ERROR, "unrecognized consttype: %u",
prefix->consttype); prefix->consttype);
return DEFAULT_MATCH_SEL; return DEFAULT_MATCH_SEL;
} }
...@@ -956,7 +956,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) ...@@ -956,7 +956,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
List *eqargs; List *eqargs;
if (eqopr == InvalidOid) if (eqopr == InvalidOid)
elog(ERROR, "patternsel: no = operator for opclass %u", opclass); elog(ERROR, "no = operator for opclass %u", opclass);
eqargs = makeList2(var, prefix); eqargs = makeList2(var, prefix);
result = DatumGetFloat8(DirectFunctionCall4(eqsel, result = DatumGetFloat8(DirectFunctionCall4(eqsel,
PointerGetDatum(root), PointerGetDatum(root),
...@@ -1136,7 +1136,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg, ...@@ -1136,7 +1136,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
varRelid, jointype); varRelid, jointype);
break; break;
default: default:
elog(ERROR, "booltestsel: unexpected booltesttype %d", elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype); (int) booltesttype);
selec = 0.0; /* Keep compiler quiet */ selec = 0.0; /* Keep compiler quiet */
break; break;
...@@ -1213,7 +1213,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg, ...@@ -1213,7 +1213,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
selec = 1.0 - freq_false; selec = 1.0 - freq_false;
break; break;
default: default:
elog(ERROR, "booltestsel: unexpected booltesttype %d", elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype); (int) booltesttype);
selec = 0.0; /* Keep compiler quiet */ selec = 0.0; /* Keep compiler quiet */
break; break;
...@@ -1254,7 +1254,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg, ...@@ -1254,7 +1254,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
selec = (1.0 - freq_null) / 2.0; selec = (1.0 - freq_null) / 2.0;
break; break;
default: default:
elog(ERROR, "booltestsel: unexpected booltesttype %d", elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype); (int) booltesttype);
selec = 0.0; /* Keep compiler quiet */ selec = 0.0; /* Keep compiler quiet */
break; break;
...@@ -1284,7 +1284,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg, ...@@ -1284,7 +1284,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
selec = DEFAULT_BOOL_SEL; selec = DEFAULT_BOOL_SEL;
break; break;
default: default:
elog(ERROR, "booltestsel: unexpected booltesttype %d", elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype); (int) booltesttype);
selec = 0.0; /* Keep compiler quiet */ selec = 0.0; /* Keep compiler quiet */
break; break;
...@@ -1319,7 +1319,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid) ...@@ -1319,7 +1319,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
defselec = DEFAULT_NOT_UNK_SEL; defselec = DEFAULT_NOT_UNK_SEL;
break; break;
default: default:
elog(ERROR, "nulltestsel: unexpected nulltesttype %d", elog(ERROR, "unrecognized nulltesttype: %d",
(int) nulltesttype); (int) nulltesttype);
return (Selectivity) 0; /* keep compiler quiet */ return (Selectivity) 0; /* keep compiler quiet */
} }
...@@ -1373,7 +1373,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid) ...@@ -1373,7 +1373,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
selec = 1.0 - freq_null; selec = 1.0 - freq_null;
break; break;
default: default:
elog(ERROR, "nulltestsel: unexpected nulltesttype %d", elog(ERROR, "unrecognized nulltesttype: %d",
(int) nulltesttype); (int) nulltesttype);
return (Selectivity) 0; /* keep compiler quiet */ return (Selectivity) 0; /* keep compiler quiet */
} }
...@@ -2500,7 +2500,7 @@ convert_numeric_to_scalar(Datum value, Oid typid) ...@@ -2500,7 +2500,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel/scalargtsel * Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one numeric and one non-numeric operand. * on an operator with one numeric and one non-numeric operand.
*/ */
elog(ERROR, "convert_numeric_to_scalar: unsupported type %u", typid); elog(ERROR, "unsupported type: %u", typid);
return 0; return 0;
} }
...@@ -2684,7 +2684,7 @@ convert_string_datum(Datum value, Oid typid) ...@@ -2684,7 +2684,7 @@ convert_string_datum(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel on * Can't get here unless someone tries to use scalarltsel on
* an operator with one string and one non-string operand. * an operator with one string and one non-string operand.
*/ */
elog(ERROR, "convert_string_datum: unsupported type %u", typid); elog(ERROR, "unsupported type: %u", typid);
return NULL; return NULL;
} }
...@@ -2882,7 +2882,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2882,7 +2882,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel/scalargtsel * Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one timevalue and one non-timevalue operand. * on an operator with one timevalue and one non-timevalue operand.
*/ */
elog(ERROR, "convert_timevalue_to_scalar: unsupported type %u", typid); elog(ERROR, "unsupported type: %u", typid);
return 0; return 0;
} }
...@@ -3111,7 +3111,9 @@ like_fixed_prefix(Const *patt_const, bool case_insensitive, ...@@ -3111,7 +3111,9 @@ like_fixed_prefix(Const *patt_const, bool case_insensitive,
Assert(typeid == BYTEAOID || typeid == TEXTOID); Assert(typeid == BYTEAOID || typeid == TEXTOID);
if (typeid == BYTEAOID && case_insensitive) if (typeid == BYTEAOID && case_insensitive)
elog(ERROR, "Cannot perform case insensitive matching on type BYTEA"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("case insensitive matching not supported on type bytea")));
if (typeid != BYTEAOID) if (typeid != BYTEAOID)
{ {
...@@ -3194,7 +3196,9 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive, ...@@ -3194,7 +3196,9 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive,
* been made safe for binary (possibly NULL containing) strings. * been made safe for binary (possibly NULL containing) strings.
*/ */
if (typeid == BYTEAOID) if (typeid == BYTEAOID)
elog(ERROR, "Regex matching not supported on type BYTEA"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("regex matching not supported on type bytea")));
/* the right-hand const is type text for all of these */ /* the right-hand const is type text for all of these */
patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue)); patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue));
...@@ -3337,7 +3341,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype, ...@@ -3337,7 +3341,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype,
result = regex_fixed_prefix(patt, true, prefix, rest); result = regex_fixed_prefix(patt, true, prefix, rest);
break; break;
default: default:
elog(ERROR, "pattern_fixed_prefix: bogus ptype"); elog(ERROR, "unrecognized ptype: %d", (int) ptype);
result = Pattern_Prefix_None; /* keep compiler quiet */ result = Pattern_Prefix_None; /* keep compiler quiet */
break; break;
} }
...@@ -3368,8 +3372,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon) ...@@ -3368,8 +3372,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon)
cmpopr = get_opclass_member(opclass, BTGreaterEqualStrategyNumber); cmpopr = get_opclass_member(opclass, BTGreaterEqualStrategyNumber);
if (cmpopr == InvalidOid) if (cmpopr == InvalidOid)
elog(ERROR, "prefix_selectivity: no >= operator for opclass %u", elog(ERROR, "no >= operator for opclass %u", opclass);
opclass);
cmpargs = makeList2(var, prefixcon); cmpargs = makeList2(var, prefixcon);
/* Assume scalargtsel is appropriate for all supported types */ /* Assume scalargtsel is appropriate for all supported types */
prefixsel = DatumGetFloat8(DirectFunctionCall4(scalargtsel, prefixsel = DatumGetFloat8(DirectFunctionCall4(scalargtsel,
...@@ -3390,8 +3393,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon) ...@@ -3390,8 +3393,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon)
cmpopr = get_opclass_member(opclass, BTLessStrategyNumber); cmpopr = get_opclass_member(opclass, BTLessStrategyNumber);
if (cmpopr == InvalidOid) if (cmpopr == InvalidOid)
elog(ERROR, "prefix_selectivity: no < operator for opclass %u", elog(ERROR, "no < operator for opclass %u", opclass);
opclass);
cmpargs = makeList2(var, greaterstrcon); cmpargs = makeList2(var, greaterstrcon);
/* Assume scalarltsel is appropriate for all supported types */ /* Assume scalarltsel is appropriate for all supported types */
topsel = DatumGetFloat8(DirectFunctionCall4(scalarltsel, topsel = DatumGetFloat8(DirectFunctionCall4(scalarltsel,
...@@ -3472,7 +3474,9 @@ like_selectivity(Const *patt_const, bool case_insensitive) ...@@ -3472,7 +3474,9 @@ like_selectivity(Const *patt_const, bool case_insensitive)
Assert(typeid == BYTEAOID || typeid == TEXTOID); Assert(typeid == BYTEAOID || typeid == TEXTOID);
if (typeid == BYTEAOID && case_insensitive) if (typeid == BYTEAOID && case_insensitive)
elog(ERROR, "Cannot perform case insensitive matching on type BYTEA"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("case insensitive matching not supported on type bytea")));
if (typeid != BYTEAOID) if (typeid != BYTEAOID)
{ {
...@@ -3618,7 +3622,9 @@ regex_selectivity(Const *patt_const, bool case_insensitive) ...@@ -3618,7 +3622,9 @@ regex_selectivity(Const *patt_const, bool case_insensitive)
* been made safe for binary (possibly NULL containing) strings. * been made safe for binary (possibly NULL containing) strings.
*/ */
if (typeid == BYTEAOID) if (typeid == BYTEAOID)
elog(ERROR, "Regex matching not supported on type BYTEA"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("regex matching not supported on type bytea")));
/* the right-hand const is type text for all of these */ /* the right-hand const is type text for all of these */
patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue)); patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue));
...@@ -3662,7 +3668,7 @@ pattern_selectivity(Const *patt, Pattern_Type ptype) ...@@ -3662,7 +3668,7 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
result = regex_selectivity(patt, true); result = regex_selectivity(patt, true);
break; break;
default: default:
elog(ERROR, "pattern_selectivity: bogus ptype"); elog(ERROR, "unrecognized ptype: %d", (int) ptype);
result = 1.0; /* keep compiler quiet */ result = 1.0; /* keep compiler quiet */
break; break;
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.55 2002/12/13 19:45:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.56 2003/07/27 04:53:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -83,7 +83,7 @@ SetDefine(char *querystr, Oid elemType) ...@@ -83,7 +83,7 @@ SetDefine(char *querystr, Oid elemType)
ObjectIdGetDatum(setoid), ObjectIdGetDatum(setoid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "SetDefine: unable to define set %s", querystr); elog(ERROR, "cache lookup failed for function %u", setoid);
/* /*
* We can tell whether the set was already defined by checking the * We can tell whether the set was already defined by checking the
...@@ -201,7 +201,10 @@ seteval(PG_FUNCTION_ARGS) ...@@ -201,7 +201,10 @@ seteval(PG_FUNCTION_ARGS)
if (rsi && IsA(rsi, ReturnSetInfo)) if (rsi && IsA(rsi, ReturnSetInfo))
rsi->isDone = isDone; rsi->isDone = isDone;
else else
elog(ERROR, "Set-valued function called in context that cannot accept a set"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that "
"cannot accept a set")));
} }
PG_RETURN_DATUM(result); PG_RETURN_DATUM(result);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.37 2003/05/12 23:08:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.38 2003/07/27 04:53:10 tgl Exp $
* *
* NOTES * NOTES
* input routine largely stolen from boxin(). * input routine largely stolen from boxin().
...@@ -61,17 +61,27 @@ tidin(PG_FUNCTION_ARGS) ...@@ -61,17 +61,27 @@ tidin(PG_FUNCTION_ARGS)
coord[i++] = p + 1; coord[i++] = p + 1;
if (i < NTIDARGS) if (i < NTIDARGS)
elog(ERROR, "invalid tid format: '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for tid: \"%s\"",
str)));
errno = 0; errno = 0;
blockNumber = strtoul(coord[0], &badp, 10); blockNumber = strtoul(coord[0], &badp, 10);
if (errno || *badp != DELIM) if (errno || *badp != DELIM)
elog(ERROR, "tidin: invalid value."); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for tid: \"%s\"",
str)));
hold_offset = strtol(coord[1], &badp, 10); hold_offset = strtol(coord[1], &badp, 10);
if (errno || *badp != RDELIM || if (errno || *badp != RDELIM ||
hold_offset > USHRT_MAX || hold_offset < 0) hold_offset > USHRT_MAX || hold_offset < 0)
elog(ERROR, "tidin: invalid value."); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for tid: \"%s\"",
str)));
offsetNumber = hold_offset; offsetNumber = hold_offset;
result = (ItemPointer) palloc(sizeof(ItemPointerData)); result = (ItemPointer) palloc(sizeof(ItemPointerData));
...@@ -216,8 +226,9 @@ currtid_for_view(Relation viewrel, ItemPointer tid) ...@@ -216,8 +226,9 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
} }
} }
if (tididx < 0) if (tididx < 0)
elog(ERROR, "currtid can't handle views with no CTID"); elog(ERROR, "currtid cannot handle views with no CTID");
if (rulelock = viewrel->rd_rules, !rulelock) rulelock = viewrel->rd_rules;
if (!rulelock)
elog(ERROR, "the view has no rules"); elog(ERROR, "the view has no rules");
for (i = 0; i < rulelock->numLocks; i++) for (i = 0; i < rulelock->numLocks; i++)
{ {
...@@ -231,12 +242,13 @@ currtid_for_view(Relation viewrel, ItemPointer tid) ...@@ -231,12 +242,13 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
elog(ERROR, "only one select rule is allowed in views"); elog(ERROR, "only one select rule is allowed in views");
query = (Query *) lfirst(rewrite->actions); query = (Query *) lfirst(rewrite->actions);
tle = (TargetEntry *) nth(tididx, query->targetList); tle = (TargetEntry *) nth(tididx, query->targetList);
if (tle && tle->expr && nodeTag(tle->expr) == T_Var) if (tle && tle->expr && IsA(tle->expr, Var))
{ {
Var *var = (Var *) tle->expr; Var *var = (Var *) tle->expr;
RangeTblEntry *rte; RangeTblEntry *rte;
if (var->varno > 0 && var->varno < INNER && var->varattno == SelfItemPointerAttributeNumber) if (var->varno > 0 && var->varno < INNER &&
var->varattno == SelfItemPointerAttributeNumber)
{ {
rte = (RangeTblEntry *) nth(var->varno - 1, query->rtable); rte = (RangeTblEntry *) nth(var->varno - 1, query->rtable);
if (rte) if (rte)
...@@ -249,7 +261,7 @@ currtid_for_view(Relation viewrel, ItemPointer tid) ...@@ -249,7 +261,7 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
break; break;
} }
} }
elog(ERROR, "currtid can't handle this view"); elog(ERROR, "currtid cannot handle this view");
return (Datum) 0; return (Datum) 0;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.87 2003/07/26 15:17:36 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.88 2003/07/27 04:53:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -78,17 +78,25 @@ timestamp_in(PG_FUNCTION_ARGS) ...@@ -78,17 +78,25 @@ timestamp_in(PG_FUNCTION_ARGS)
char lowstr[MAXDATELEN + MAXDATEFIELDS]; char lowstr[MAXDATELEN + MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad timestamp external representation (too long) '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for timestamp: \"%s\"",
str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad timestamp external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for timestamp: \"%s\"",
str)));
switch (dtype) switch (dtype)
{ {
case DTK_DATE: case DTK_DATE:
if (tm2timestamp(tm, fsec, NULL, &result) != 0) if (tm2timestamp(tm, fsec, NULL, &result) != 0)
elog(ERROR, "TIMESTAMP out of range '%s'", str); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range: \"%s\"", str)));
break; break;
case DTK_EPOCH: case DTK_EPOCH:
...@@ -104,12 +112,16 @@ timestamp_in(PG_FUNCTION_ARGS) ...@@ -104,12 +112,16 @@ timestamp_in(PG_FUNCTION_ARGS)
break; break;
case DTK_INVALID: case DTK_INVALID:
elog(ERROR, "TIMESTAMP '%s' no longer supported", str); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"%s\" is no longer supported", str)));
TIMESTAMP_NOEND(result); TIMESTAMP_NOEND(result);
break; break;
default: default:
elog(ERROR, "TIMESTAMP '%s' not parsed; internal coding error", str); elog(ERROR, "unexpected dtype %d while parsing timestamp \"%s\"",
dtype, str);
TIMESTAMP_NOEND(result); TIMESTAMP_NOEND(result);
} }
...@@ -137,7 +149,9 @@ timestamp_out(PG_FUNCTION_ARGS) ...@@ -137,7 +149,9 @@ timestamp_out(PG_FUNCTION_ARGS)
else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0) else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0)
EncodeDateTime(tm, fsec, NULL, &tzn, DateStyle, buf); EncodeDateTime(tm, fsec, NULL, &tzn, DateStyle, buf);
else else
elog(ERROR, "Unable to format timestamp; internal coding error"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = pstrdup(buf); result = pstrdup(buf);
PG_RETURN_CSTRING(result); PG_RETURN_CSTRING(result);
...@@ -238,8 +252,10 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod) ...@@ -238,8 +252,10 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
&& (typmod != -1) && (typmod != MAX_TIMESTAMP_PRECISION)) && (typmod != -1) && (typmod != MAX_TIMESTAMP_PRECISION))
{ {
if ((typmod < 0) || (typmod > MAX_TIMESTAMP_PRECISION)) if ((typmod < 0) || (typmod > MAX_TIMESTAMP_PRECISION))
elog(ERROR, "TIMESTAMP(%d) precision must be between %d and %d", ereport(ERROR,
typmod, 0, MAX_TIMESTAMP_PRECISION); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp(%d) precision must be between %d and %d",
typmod, 0, MAX_TIMESTAMP_PRECISION)));
/* /*
* Note: this round-to-nearest code is not completely consistent * Note: this round-to-nearest code is not completely consistent
...@@ -291,18 +307,25 @@ timestamptz_in(PG_FUNCTION_ARGS) ...@@ -291,18 +307,25 @@ timestamptz_in(PG_FUNCTION_ARGS)
char lowstr[MAXDATELEN + MAXDATEFIELDS]; char lowstr[MAXDATELEN + MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad timestamp with time zone" ereport(ERROR,
" external representation (too long) '%s'", str); (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for timestamp with time zone: \"%s\"",
str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad timestamp external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for timestamp with time zone: \"%s\"",
str)));
switch (dtype) switch (dtype)
{ {
case DTK_DATE: case DTK_DATE:
if (tm2timestamp(tm, fsec, &tz, &result) != 0) if (tm2timestamp(tm, fsec, &tz, &result) != 0)
elog(ERROR, "TIMESTAMP WITH TIME ZONE out of range '%s'", str); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range: \"%s\"", str)));
break; break;
case DTK_EPOCH: case DTK_EPOCH:
...@@ -318,12 +341,16 @@ timestamptz_in(PG_FUNCTION_ARGS) ...@@ -318,12 +341,16 @@ timestamptz_in(PG_FUNCTION_ARGS)
break; break;
case DTK_INVALID: case DTK_INVALID:
elog(ERROR, "TIMESTAMP WITH TIME ZONE '%s' no longer supported", str); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"%s\" is no longer supported", str)));
TIMESTAMP_NOEND(result); TIMESTAMP_NOEND(result);
break; break;
default: default:
elog(ERROR, "TIMESTAMP WITH TIME ZONE '%s' not parsed; internal coding error", str); elog(ERROR, "unexpected dtype %d while parsing timestamptz \"%s\"",
dtype, str);
TIMESTAMP_NOEND(result); TIMESTAMP_NOEND(result);
} }
...@@ -352,7 +379,9 @@ timestamptz_out(PG_FUNCTION_ARGS) ...@@ -352,7 +379,9 @@ timestamptz_out(PG_FUNCTION_ARGS)
else if (timestamp2tm(dt, &tz, tm, &fsec, &tzn) == 0) else if (timestamp2tm(dt, &tz, tm, &fsec, &tzn) == 0)
EncodeDateTime(tm, fsec, &tz, &tzn, DateStyle, buf); EncodeDateTime(tm, fsec, &tz, &tzn, DateStyle, buf);
else else
elog(ERROR, "Unable to format timestamp with time zone; internal coding error"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = pstrdup(buf); result = pstrdup(buf);
PG_RETURN_CSTRING(result); PG_RETURN_CSTRING(result);
...@@ -448,11 +477,17 @@ interval_in(PG_FUNCTION_ARGS) ...@@ -448,11 +477,17 @@ interval_in(PG_FUNCTION_ARGS)
fsec = 0; fsec = 0;
if (strlen(str) >= sizeof(lowstr)) if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad interval external representation (too long) '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for interval: \"%s\"",
str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0)) || (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(ERROR, "Bad interval external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for interval: \"%s\"",
str)));
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
...@@ -460,16 +495,21 @@ interval_in(PG_FUNCTION_ARGS) ...@@ -460,16 +495,21 @@ interval_in(PG_FUNCTION_ARGS)
{ {
case DTK_DELTA: case DTK_DELTA:
if (tm2interval(tm, fsec, result) != 0) if (tm2interval(tm, fsec, result) != 0)
elog(ERROR, "Bad interval external representation '%s'", str); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));
AdjustIntervalForTypmod(result, typmod); AdjustIntervalForTypmod(result, typmod);
break; break;
case DTK_INVALID: case DTK_INVALID:
elog(ERROR, "Interval '%s' no longer supported", str); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"%s\" is no longer supported", str)));
break; break;
default: default:
elog(ERROR, "Interval '%s' not parsed; internal coding error", str); elog(ERROR, "unexpected dtype %d while parsing interval \"%s\"",
dtype, str);
} }
PG_RETURN_INTERVAL_P(result); PG_RETURN_INTERVAL_P(result);
...@@ -489,10 +529,10 @@ interval_out(PG_FUNCTION_ARGS) ...@@ -489,10 +529,10 @@ interval_out(PG_FUNCTION_ARGS)
char buf[MAXDATELEN + 1]; char buf[MAXDATELEN + 1];
if (interval2tm(*span, tm, &fsec) != 0) if (interval2tm(*span, tm, &fsec) != 0)
elog(ERROR, "Unable to encode interval; internal coding error"); elog(ERROR, "could not convert interval to tm");
if (EncodeInterval(tm, fsec, DateStyle, buf) != 0) if (EncodeInterval(tm, fsec, DateStyle, buf) != 0)
elog(ERROR, "Unable to format interval; internal coding error"); elog(ERROR, "could not format interval");
result = pstrdup(buf); result = pstrdup(buf);
PG_RETURN_CSTRING(result); PG_RETURN_CSTRING(result);
...@@ -781,14 +821,16 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod) ...@@ -781,14 +821,16 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
#endif #endif
} }
else else
elog(ERROR, "AdjustIntervalForTypmod(): internal coding error"); elog(ERROR, "unrecognized interval typmod: %d", typmod);
/* Need to adjust precision? If not, don't even try! */ /* Need to adjust precision? If not, don't even try! */
if (precision != INTERVAL_FULL_PRECISION) if (precision != INTERVAL_FULL_PRECISION)
{ {
if ((precision < 0) || (precision > MAX_INTERVAL_PRECISION)) if ((precision < 0) || (precision > MAX_INTERVAL_PRECISION))
elog(ERROR, "INTERVAL(%d) precision must be between %d and %d", ereport(ERROR,
precision, 0, MAX_INTERVAL_PRECISION); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval(%d) precision must be between %d and %d",
precision, 0, MAX_INTERVAL_PRECISION)));
/* /*
* Note: this round-to-nearest code is not completely consistent * Note: this round-to-nearest code is not completely consistent
...@@ -1045,7 +1087,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn) ...@@ -1045,7 +1087,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
} }
return 0; return 0;
} /* timestamp2tm() */ }
/* tm2timestamp() /* tm2timestamp()
...@@ -1053,7 +1095,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn) ...@@ -1053,7 +1095,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
* Note that year is _not_ 1900-based, but is an explicit full value. * Note that year is _not_ 1900-based, but is an explicit full value.
* Also, month is one-based, _not_ zero-based. * Also, month is one-based, _not_ zero-based.
* *
* Returns -1 on failure (overflow). * Returns -1 on failure (value out of range).
*/ */
int int
tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result) tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
...@@ -1088,7 +1130,7 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result) ...@@ -1088,7 +1130,7 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
*result = dt2local(*result, -(*tzp)); *result = dt2local(*result, -(*tzp));
return 0; return 0;
} /* tm2timestamp() */ }
/* interval2tm() /* interval2tm()
...@@ -1136,7 +1178,7 @@ interval2tm(Interval span, struct tm * tm, fsec_t *fsec) ...@@ -1136,7 +1178,7 @@ interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
#endif #endif
return 0; return 0;
} /* interval2tm() */ }
int int
tm2interval(struct tm * tm, fsec_t fsec, Interval *span) tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
...@@ -1156,7 +1198,7 @@ tm2interval(struct tm * tm, fsec_t fsec, Interval *span) ...@@ -1156,7 +1198,7 @@ tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
#endif #endif
return 0; return 0;
} /* tm2interval() */ }
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
static int64 static int64
...@@ -1240,6 +1282,7 @@ SetEpochTimestamp(void) ...@@ -1240,6 +1282,7 @@ SetEpochTimestamp(void)
*tm = &tt; *tm = &tt;
GetEpochTime(tm); GetEpochTime(tm);
/* we don't bother to test for failure ... */
tm2timestamp(tm, 0, NULL, &dt); tm2timestamp(tm, 0, NULL, &dt);
return dt; return dt;
...@@ -1605,7 +1648,10 @@ timestamp_mi(PG_FUNCTION_ARGS) ...@@ -1605,7 +1648,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(dt1) || TIMESTAMP_NOT_FINITE(dt2)) if (TIMESTAMP_NOT_FINITE(dt1) || TIMESTAMP_NOT_FINITE(dt2))
{ {
elog(ERROR, "Unable to subtract non-finite timestamps"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("cannot subtract non-finite timestamps")));
result->time = 0; result->time = 0;
} }
else else
...@@ -1647,8 +1693,11 @@ timestamp_pl_span(PG_FUNCTION_ARGS) ...@@ -1647,8 +1693,11 @@ timestamp_pl_span(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
fsec_t fsec; fsec_t fsec;
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
{ ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
tm->tm_mon += span->month; tm->tm_mon += span->month;
if (tm->tm_mon > 12) if (tm->tm_mon > 12)
{ {
...@@ -1666,18 +1715,9 @@ timestamp_pl_span(PG_FUNCTION_ARGS) ...@@ -1666,18 +1715,9 @@ timestamp_pl_span(PG_FUNCTION_ARGS)
tm->tm_mday = (day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]); tm->tm_mday = (day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]);
if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0) if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
{ ereport(ERROR,
elog(ERROR, "Unable to add TIMESTAMP and INTERVAL" (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
"\n\ttimestamp_pl_span() internal error encoding timestamp"); errmsg("timestamp out of range")));
PG_RETURN_NULL();
}
}
else
{
elog(ERROR, "Unable to add TIMESTAMP and INTERVAL"
"\n\ttimestamp_pl_span() internal error decoding timestamp");
PG_RETURN_NULL();
}
} }
timestamp += span->time; timestamp += span->time;
...@@ -1731,8 +1771,11 @@ timestamptz_pl_span(PG_FUNCTION_ARGS) ...@@ -1731,8 +1771,11 @@ timestamptz_pl_span(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
fsec_t fsec; fsec_t fsec;
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
{ ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
tm->tm_mon += span->month; tm->tm_mon += span->month;
if (tm->tm_mon > 12) if (tm->tm_mon > 12)
{ {
...@@ -1752,14 +1795,9 @@ timestamptz_pl_span(PG_FUNCTION_ARGS) ...@@ -1752,14 +1795,9 @@ timestamptz_pl_span(PG_FUNCTION_ARGS)
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0) if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
elog(ERROR, "Unable to add TIMESTAMP and INTERVAL" ereport(ERROR,
"\n\ttimestamptz_pl_span() internal error encoding timestamp"); (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
} errmsg("timestamp out of range")));
else
{
elog(ERROR, "Unable to add TIMESTAMP and INTERVAL"
"\n\ttimestamptz_pl_span() internal error decoding timestamp");
}
} }
timestamp += span->time; timestamp += span->time;
...@@ -1986,7 +2024,9 @@ interval_div(PG_FUNCTION_ARGS) ...@@ -1986,7 +2024,9 @@ interval_div(PG_FUNCTION_ARGS)
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
if (factor == 0.0) if (factor == 0.0)
elog(ERROR, "division by zero"); ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->month = (span->month / factor); result->month = (span->month / factor);
...@@ -2031,7 +2071,7 @@ interval_accum(PG_FUNCTION_ARGS) ...@@ -2031,7 +2071,7 @@ interval_accum(PG_FUNCTION_ARGS)
INTERVALOID, 12, false, 'd', INTERVALOID, 12, false, 'd',
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 2) if (ndatums != 2)
elog(ERROR, "interval_accum: expected 2-element interval array"); elog(ERROR, "expected 2-element interval array");
/* /*
* XXX memcpy, instead of just extracting a pointer, to work around * XXX memcpy, instead of just extracting a pointer, to work around
...@@ -2073,7 +2113,7 @@ interval_avg(PG_FUNCTION_ARGS) ...@@ -2073,7 +2113,7 @@ interval_avg(PG_FUNCTION_ARGS)
INTERVALOID, 12, false, 'd', INTERVALOID, 12, false, 'd',
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 2) if (ndatums != 2)
elog(ERROR, "interval_avg: expected 2-element interval array"); elog(ERROR, "expected 2-element interval array");
/* /*
* XXX memcpy, instead of just extracting a pointer, to work around * XXX memcpy, instead of just extracting a pointer, to work around
...@@ -2195,12 +2235,14 @@ timestamp_age(PG_FUNCTION_ARGS) ...@@ -2195,12 +2235,14 @@ timestamp_age(PG_FUNCTION_ARGS)
} }
if (tm2interval(tm, fsec, result) != 0) if (tm2interval(tm, fsec, result) != 0)
elog(ERROR, "Unable to encode INTERVAL" ereport(ERROR,
"\n\ttimestamp_age() internal coding error"); (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));
} }
else else
elog(ERROR, "Unable to decode TIMESTAMP" ereport(ERROR,
"\n\ttimestamp_age() internal coding error"); (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
PG_RETURN_INTERVAL_P(result); PG_RETURN_INTERVAL_P(result);
} }
...@@ -2304,10 +2346,14 @@ timestamptz_age(PG_FUNCTION_ARGS) ...@@ -2304,10 +2346,14 @@ timestamptz_age(PG_FUNCTION_ARGS)
} }
if (tm2interval(tm, fsec, result) != 0) if (tm2interval(tm, fsec, result) != 0)
elog(ERROR, "Unable to decode TIMESTAMP"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));
} }
else else
elog(ERROR, "Unable to decode TIMESTAMP"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
PG_RETURN_INTERVAL_P(result); PG_RETURN_INTERVAL_P(result);
} }
...@@ -2360,7 +2406,11 @@ text_timestamp(PG_FUNCTION_ARGS) ...@@ -2360,7 +2406,11 @@ text_timestamp(PG_FUNCTION_ARGS)
dstr[MAXDATELEN + 1]; dstr[MAXDATELEN + 1];
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN) if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMESTAMP bad external representation (too long)"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for timestamp: \"%s\"",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(str))))));
sp = VARDATA(str); sp = VARDATA(str);
dp = dstr; dp = dstr;
...@@ -2416,7 +2466,11 @@ text_timestamptz(PG_FUNCTION_ARGS) ...@@ -2416,7 +2466,11 @@ text_timestamptz(PG_FUNCTION_ARGS)
dstr[MAXDATELEN + 1]; dstr[MAXDATELEN + 1];
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN) if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMESTAMP WITH TIME ZONE bad external representation (too long)"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for timestamp with time zone: \"%s\"",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(str))))));
sp = VARDATA(str); sp = VARDATA(str);
dp = dstr; dp = dstr;
...@@ -2473,7 +2527,12 @@ text_interval(PG_FUNCTION_ARGS) ...@@ -2473,7 +2527,12 @@ text_interval(PG_FUNCTION_ARGS)
dstr[MAXDATELEN + 1]; dstr[MAXDATELEN + 1];
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN) if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "INTERVAL bad external representation (too long)"); ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for interval: \"%s\"",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(str))))));
sp = VARDATA(str); sp = VARDATA(str);
dp = dstr; dp = dstr;
for (i = 0; i < (VARSIZE(str) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(str) - VARHDRSZ); i++)
...@@ -2506,9 +2565,12 @@ timestamp_trunc(PG_FUNCTION_ARGS) ...@@ -2506,9 +2565,12 @@ timestamp_trunc(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMESTAMP units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -2520,8 +2582,13 @@ timestamp_trunc(PG_FUNCTION_ARGS) ...@@ -2520,8 +2582,13 @@ timestamp_trunc(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_TIMESTAMP(timestamp); PG_RETURN_TIMESTAMP(timestamp);
if ((type == UNITS) && (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0)) if (type == UNITS)
{ {
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
switch (val) switch (val)
{ {
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
...@@ -2561,16 +2628,24 @@ timestamp_trunc(PG_FUNCTION_ARGS) ...@@ -2561,16 +2628,24 @@ timestamp_trunc(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "TIMESTAMP units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("timestamp units \"%s\" not supported",
lowunits)));
result = 0; result = 0;
} }
if (tm2timestamp(tm, fsec, NULL, &result) != 0) if (tm2timestamp(tm, fsec, NULL, &result) != 0)
elog(ERROR, "Unable to truncate TIMESTAMP to '%s'", lowunits); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
} }
else else
{ {
elog(ERROR, "TIMESTAMP units '%s' not recognized", lowunits); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp units \"%s\" not recognized",
lowunits)));
result = 0; result = 0;
} }
...@@ -2599,9 +2674,11 @@ timestamptz_trunc(PG_FUNCTION_ARGS) ...@@ -2599,9 +2674,11 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp with time zone units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -2613,8 +2690,13 @@ timestamptz_trunc(PG_FUNCTION_ARGS) ...@@ -2613,8 +2690,13 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_TIMESTAMPTZ(timestamp); PG_RETURN_TIMESTAMPTZ(timestamp);
if ((type == UNITS) && (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0)) if (type == UNITS)
{ {
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
switch (val) switch (val)
{ {
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
...@@ -2653,19 +2735,27 @@ timestamptz_trunc(PG_FUNCTION_ARGS) ...@@ -2653,19 +2735,27 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("timestamp with time zone units \"%s\" not "
"supported", lowunits)));
result = 0; result = 0;
} }
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
if (tm2timestamp(tm, fsec, &tz, &result) != 0) if (tm2timestamp(tm, fsec, &tz, &result) != 0)
elog(ERROR, "Unable to truncate TIMESTAMP WITH TIME ZONE to '%s'", lowunits); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
} }
else else
{ {
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized", lowunits); ereport(ERROR,
PG_RETURN_NULL(); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp with time zone units \"%s\" not recognized",
lowunits)));
result = 0;
} }
PG_RETURN_TIMESTAMPTZ(result); PG_RETURN_TIMESTAMPTZ(result);
...@@ -2693,9 +2783,11 @@ interval_trunc(PG_FUNCTION_ARGS) ...@@ -2693,9 +2783,11 @@ interval_trunc(PG_FUNCTION_ARGS)
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "INTERVAL units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -2746,24 +2838,29 @@ interval_trunc(PG_FUNCTION_ARGS) ...@@ -2746,24 +2838,29 @@ interval_trunc(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "INTERVAL units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("interval units \"%s\" not supported",
lowunits)));
} }
if (tm2interval(tm, fsec, result) != 0) if (tm2interval(tm, fsec, result) != 0)
elog(ERROR, "Unable to truncate INTERVAL to '%s'", lowunits); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));
} }
else else
{ {
elog(WARNING, "Unable to decode INTERVAL; internal coding error"); elog(ERROR, "could not convert interval to tm");
*result = *interval;
} }
} }
else else
{ {
elog(ERROR, "INTERVAL units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
*result = *interval; *result = *interval;
} }
...@@ -2783,7 +2880,9 @@ isoweek2date(int woy, int *year, int *mon, int *mday) ...@@ -2783,7 +2880,9 @@ isoweek2date(int woy, int *year, int *mon, int *mday)
dayn; dayn;
if (!*year) if (!*year)
elog(ERROR, "isoweek2date(): can't convert without year information"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot convert week number without year information")));
/* fourth day of current year */ /* fourth day of current year */
day4 = date2j(*year, 1, 4); day4 = date2j(*year, 1, 4);
...@@ -2870,9 +2969,11 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -2870,9 +2969,11 @@ timestamp_part(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMESTAMP units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -2889,9 +2990,13 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -2889,9 +2990,13 @@ timestamp_part(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
} }
if ((type == UNITS) if (type == UNITS)
&& (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0))
{ {
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
switch (val) switch (val)
{ {
case DTK_MICROSEC: case DTK_MICROSEC:
...@@ -2973,7 +3078,10 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -2973,7 +3078,10 @@ timestamp_part(PG_FUNCTION_ARGS)
case DTK_TZ_MINUTE: case DTK_TZ_MINUTE:
case DTK_TZ_HOUR: case DTK_TZ_HOUR:
default: default:
elog(ERROR, "TIMESTAMP units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("timestamp units \"%s\" not supported",
lowunits)));
result = 0; result = 0;
} }
} }
...@@ -2988,12 +3096,16 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -2988,12 +3096,16 @@ timestamp_part(PG_FUNCTION_ARGS)
/* convert to timestamptz to produce consistent results */ /* convert to timestamptz to produce consistent results */
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE (tm)"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
if (tm2timestamp(tm, fsec, &tz, &timestamptz) != 0) if (tm2timestamp(tm, fsec, &tz, &timestamptz) != 0)
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result = ((timestamptz - SetEpochTimestamp()) / 1000000e0); result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);
...@@ -3004,28 +3116,35 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3004,28 +3116,35 @@ timestamp_part(PG_FUNCTION_ARGS)
} }
case DTK_DOW: case DTK_DOW:
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to encode TIMESTAMP"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)); result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
break; break;
case DTK_DOY: case DTK_DOY:
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to encode TIMESTAMP"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
- date2j(tm->tm_year, 1, 1) + 1); - date2j(tm->tm_year, 1, 1) + 1);
break; break;
default: default:
elog(ERROR, "TIMESTAMP units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("timestamp units \"%s\" not supported",
lowunits)));
result = 0; result = 0;
} }
} }
else else
{ {
elog(ERROR, "TIMESTAMP units '%s' not recognized", lowunits); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp units \"%s\" not recognized", lowunits)));
result = 0; result = 0;
} }
...@@ -3055,9 +3174,11 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3055,9 +3174,11 @@ timestamptz_part(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp with time zone units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -3074,9 +3195,13 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3074,9 +3195,13 @@ timestamptz_part(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
} }
if ((type == UNITS) if (type == UNITS)
&& (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0))
{ {
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
switch (val) switch (val)
{ {
case DTK_TZ: case DTK_TZ:
...@@ -3170,7 +3295,10 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3170,7 +3295,10 @@ timestamptz_part(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("timestamp with time zone units \"%s\" not supported",
lowunits)));
result = 0; result = 0;
} }
...@@ -3189,27 +3317,36 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3189,27 +3317,36 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_DOW: case DTK_DOW:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to encode TIMESTAMP WITH TIME ZONE"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)); result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
break; break;
case DTK_DOY: case DTK_DOY:
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to encode TIMESTAMP WITH TIME ZONE"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
- date2j(tm->tm_year, 1, 1) + 1); - date2j(tm->tm_year, 1, 1) + 1);
break; break;
default: default:
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not supported", lowunits); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("timestamp with time zone units \"%s\" not supported",
lowunits)));
result = 0; result = 0;
} }
} }
else else
{ {
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized", lowunits); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp with time zone units \"%s\" not recognized",
lowunits)));
result = 0; result = 0;
} }
...@@ -3237,9 +3374,11 @@ interval_part(PG_FUNCTION_ARGS) ...@@ -3237,9 +3374,11 @@ interval_part(PG_FUNCTION_ARGS)
*tm = &tt; *tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "INTERVAL units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
...@@ -3317,17 +3456,18 @@ interval_part(PG_FUNCTION_ARGS) ...@@ -3317,17 +3456,18 @@ interval_part(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "INTERVAL units '%s' not supported", ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("interval units \"%s\" not supported",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
result = 0; result = 0;
} }
} }
else else
{ {
elog(WARNING, "Unable to decode INTERVAL" elog(ERROR, "could not convert interval to tm");
"\n\tinterval_part() internal coding error");
result = 0; result = 0;
} }
} }
...@@ -3346,9 +3486,11 @@ interval_part(PG_FUNCTION_ARGS) ...@@ -3346,9 +3486,11 @@ interval_part(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "INTERVAL units '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval units \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(units)))); PointerGetDatum(units))))));
result = 0; result = 0;
} }
...@@ -3376,9 +3518,11 @@ timestamp_zone(PG_FUNCTION_ARGS) ...@@ -3376,9 +3518,11 @@ timestamp_zone(PG_FUNCTION_ARGS)
lowzone[MAXDATELEN + 1]; lowzone[MAXDATELEN + 1];
if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN) if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "Time zone '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("time zone \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(zone)))); PointerGetDatum(zone))))));
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_TIMESTAMPTZ(timestamp); PG_RETURN_TIMESTAMPTZ(timestamp);
...@@ -3399,7 +3543,11 @@ timestamp_zone(PG_FUNCTION_ARGS) ...@@ -3399,7 +3543,11 @@ timestamp_zone(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "Time zone '%s' not recognized", lowzone); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("time zone \"%s\" not recognized",
lowzone)));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -3421,9 +3569,11 @@ timestamp_izone(PG_FUNCTION_ARGS) ...@@ -3421,9 +3569,11 @@ timestamp_izone(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(timestamp); PG_RETURN_TIMESTAMPTZ(timestamp);
if (zone->month != 0) if (zone->month != 0)
elog(ERROR, "INTERVAL time zone '%s' not legal (month specified)", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval time zone \"%s\" must not specify month",
DatumGetCString(DirectFunctionCall1(interval_out, DatumGetCString(DirectFunctionCall1(interval_out,
PointerGetDatum(zone)))); PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
tz = (zone->time / INT64CONST(1000000)); tz = (zone->time / INT64CONST(1000000));
...@@ -3454,12 +3604,16 @@ timestamp_timestamptz(PG_FUNCTION_ARGS) ...@@ -3454,12 +3604,16 @@ timestamp_timestamptz(PG_FUNCTION_ARGS)
else else
{ {
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0) if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE (tm)"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
tz = DetermineLocalTimeZone(tm); tz = DetermineLocalTimeZone(tm);
if (tm2timestamp(tm, fsec, &tz, &result) != 0) if (tm2timestamp(tm, fsec, &tz, &result) != 0)
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
} }
PG_RETURN_TIMESTAMPTZ(result); PG_RETURN_TIMESTAMPTZ(result);
...@@ -3484,10 +3638,13 @@ timestamptz_timestamp(PG_FUNCTION_ARGS) ...@@ -3484,10 +3638,13 @@ timestamptz_timestamp(PG_FUNCTION_ARGS)
else else
{ {
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to convert TIMESTAMP WITH TIME ZONE to TIMESTAMP (tm)"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
if (tm2timestamp(tm, fsec, NULL, &result) != 0) if (tm2timestamp(tm, fsec, NULL, &result) != 0)
elog(ERROR, "Unable to convert TIMESTAMP WITH TIME ZONE to TIMESTAMP"); ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
} }
PG_RETURN_TIMESTAMP(result); PG_RETURN_TIMESTAMP(result);
...@@ -3513,9 +3670,11 @@ timestamptz_zone(PG_FUNCTION_ARGS) ...@@ -3513,9 +3670,11 @@ timestamptz_zone(PG_FUNCTION_ARGS)
lowzone[MAXDATELEN + 1]; lowzone[MAXDATELEN + 1];
if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN) if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
elog(ERROR, "Time zone '%s' not recognized", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("time zone \"%s\" not recognized",
DatumGetCString(DirectFunctionCall1(textout, DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(zone)))); PointerGetDatum(zone))))));
up = VARDATA(zone); up = VARDATA(zone);
lp = lowzone; lp = lowzone;
for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++) for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
...@@ -3535,7 +3694,10 @@ timestamptz_zone(PG_FUNCTION_ARGS) ...@@ -3535,7 +3694,10 @@ timestamptz_zone(PG_FUNCTION_ARGS)
} }
else else
{ {
elog(ERROR, "Time zone '%s' not recognized", lowzone); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("time zone \"%s\" not recognized", lowzone)));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -3558,9 +3720,11 @@ timestamptz_izone(PG_FUNCTION_ARGS) ...@@ -3558,9 +3720,11 @@ timestamptz_izone(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); PG_RETURN_NULL();
if (zone->month != 0) if (zone->month != 0)
elog(ERROR, "INTERVAL time zone '%s' not legal (month specified)", ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval time zone \"%s\" must not specify month",
DatumGetCString(DirectFunctionCall1(interval_out, DatumGetCString(DirectFunctionCall1(interval_out,
PointerGetDatum(zone)))); PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
tz = -(zone->time / INT64CONST(1000000)); tz = -(zone->time / INT64CONST(1000000));
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.31 2003/05/27 17:49:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.32 2003/07/27 04:53:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -104,8 +104,10 @@ bit_in(PG_FUNCTION_ARGS) ...@@ -104,8 +104,10 @@ bit_in(PG_FUNCTION_ARGS)
if (atttypmod <= 0) if (atttypmod <= 0)
atttypmod = bitlen; atttypmod = bitlen;
else if (bitlen != atttypmod) else if (bitlen != atttypmod)
elog(ERROR, "Bit string length %d does not match type BIT(%d)", ereport(ERROR,
bitlen, atttypmod); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("bit string length %d does not match type bit(%d)",
bitlen, atttypmod)));
len = VARBITTOTALLEN(atttypmod); len = VARBITTOTALLEN(atttypmod);
/* set to 0 so that *r is always initialised and string is zero-padded */ /* set to 0 so that *r is always initialised and string is zero-padded */
...@@ -124,7 +126,11 @@ bit_in(PG_FUNCTION_ARGS) ...@@ -124,7 +126,11 @@ bit_in(PG_FUNCTION_ARGS)
if (*sp == '1') if (*sp == '1')
*r |= x; *r |= x;
else if (*sp != '0') else if (*sp != '0')
elog(ERROR, "Cannot parse '%c' as a binary digit", *sp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%c\" is not a valid binary digit",
*sp)));
x >>= 1; x >>= 1;
if (x == 0) if (x == 0)
{ {
...@@ -145,7 +151,11 @@ bit_in(PG_FUNCTION_ARGS) ...@@ -145,7 +151,11 @@ bit_in(PG_FUNCTION_ARGS)
else if (*sp >= 'a' && *sp <= 'f') else if (*sp >= 'a' && *sp <= 'f')
x = (bits8) (*sp - 'a') + 10; x = (bits8) (*sp - 'a') + 10;
else else
elog(ERROR, "Cannot parse '%c' as a hex digit", *sp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%c\" is not a valid hex digit",
*sp)));
if (bc) if (bc)
{ {
*r++ |= x; *r++ |= x;
...@@ -248,8 +258,10 @@ bit(PG_FUNCTION_ARGS) ...@@ -248,8 +258,10 @@ bit(PG_FUNCTION_ARGS)
PG_RETURN_VARBIT_P(arg); PG_RETURN_VARBIT_P(arg);
if (!isExplicit) if (!isExplicit)
elog(ERROR, "Bit string length %d does not match type BIT(%d)", ereport(ERROR,
VARBITLEN(arg), len); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("bit string length %d does not match type bit(%d)",
VARBITLEN(arg), len)));
rlen = VARBITTOTALLEN(len); rlen = VARBITTOTALLEN(len);
/* set to 0 so that string is zero-padded */ /* set to 0 so that string is zero-padded */
...@@ -331,8 +343,10 @@ varbit_in(PG_FUNCTION_ARGS) ...@@ -331,8 +343,10 @@ varbit_in(PG_FUNCTION_ARGS)
if (atttypmod <= 0) if (atttypmod <= 0)
atttypmod = bitlen; atttypmod = bitlen;
else if (bitlen > atttypmod) else if (bitlen > atttypmod)
elog(ERROR, "Bit string too long for type BIT VARYING(%d)", ereport(ERROR,
atttypmod); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("bit string too long for type bit varying(%d)",
atttypmod)));
len = VARBITTOTALLEN(bitlen); len = VARBITTOTALLEN(bitlen);
/* set to 0 so that *r is always initialised and string is zero-padded */ /* set to 0 so that *r is always initialised and string is zero-padded */
...@@ -351,7 +365,11 @@ varbit_in(PG_FUNCTION_ARGS) ...@@ -351,7 +365,11 @@ varbit_in(PG_FUNCTION_ARGS)
if (*sp == '1') if (*sp == '1')
*r |= x; *r |= x;
else if (*sp != '0') else if (*sp != '0')
elog(ERROR, "Cannot parse '%c' as a binary digit", *sp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%c\" is not a valid binary digit",
*sp)));
x >>= 1; x >>= 1;
if (x == 0) if (x == 0)
{ {
...@@ -372,7 +390,11 @@ varbit_in(PG_FUNCTION_ARGS) ...@@ -372,7 +390,11 @@ varbit_in(PG_FUNCTION_ARGS)
else if (*sp >= 'a' && *sp <= 'f') else if (*sp >= 'a' && *sp <= 'f')
x = (bits8) (*sp - 'a') + 10; x = (bits8) (*sp - 'a') + 10;
else else
elog(ERROR, "Cannot parse '%c' as a hex digit", *sp); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("\"%c\" is not a valid hex digit",
*sp)));
if (bc) if (bc)
{ {
*r++ |= x; *r++ |= x;
...@@ -445,7 +467,9 @@ varbit_recv(PG_FUNCTION_ARGS) ...@@ -445,7 +467,9 @@ varbit_recv(PG_FUNCTION_ARGS)
bitlen = pq_getmsgint(buf, sizeof(int32)); bitlen = pq_getmsgint(buf, sizeof(int32));
if (bitlen < 0) if (bitlen < 0)
elog(ERROR, "Invalid length in external bit string"); ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid length in external bit string")));
len = VARBITTOTALLEN(bitlen); len = VARBITTOTALLEN(bitlen);
result = (VarBit *) palloc(len); result = (VarBit *) palloc(len);
...@@ -503,7 +527,10 @@ varbit(PG_FUNCTION_ARGS) ...@@ -503,7 +527,10 @@ varbit(PG_FUNCTION_ARGS)
PG_RETURN_VARBIT_P(arg); PG_RETURN_VARBIT_P(arg);
if (!isExplicit) if (!isExplicit)
elog(ERROR, "Bit string too long for type BIT VARYING(%d)", len); ereport(ERROR,
(errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("bit string too long for type bit varying(%d)",
len)));
rlen = VARBITTOTALLEN(len); rlen = VARBITTOTALLEN(len);
result = (VarBit *) palloc(rlen); result = (VarBit *) palloc(rlen);
...@@ -873,7 +900,10 @@ bitand(PG_FUNCTION_ARGS) ...@@ -873,7 +900,10 @@ bitand(PG_FUNCTION_ARGS)
bitlen1 = VARBITLEN(arg1); bitlen1 = VARBITLEN(arg1);
bitlen2 = VARBITLEN(arg2); bitlen2 = VARBITLEN(arg2);
if (bitlen1 != bitlen2) if (bitlen1 != bitlen2)
elog(ERROR, "Cannot AND bit strings of different sizes"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot AND bit strings of different sizes")));
len = VARSIZE(arg1); len = VARSIZE(arg1);
result = (VarBit *) palloc(len); result = (VarBit *) palloc(len);
VARATT_SIZEP(result) = len; VARATT_SIZEP(result) = len;
...@@ -911,7 +941,9 @@ bitor(PG_FUNCTION_ARGS) ...@@ -911,7 +941,9 @@ bitor(PG_FUNCTION_ARGS)
bitlen1 = VARBITLEN(arg1); bitlen1 = VARBITLEN(arg1);
bitlen2 = VARBITLEN(arg2); bitlen2 = VARBITLEN(arg2);
if (bitlen1 != bitlen2) if (bitlen1 != bitlen2)
elog(ERROR, "Cannot OR bit strings of different sizes"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot OR bit strings of different sizes")));
len = VARSIZE(arg1); len = VARSIZE(arg1);
result = (VarBit *) palloc(len); result = (VarBit *) palloc(len);
VARATT_SIZEP(result) = len; VARATT_SIZEP(result) = len;
...@@ -955,7 +987,10 @@ bitxor(PG_FUNCTION_ARGS) ...@@ -955,7 +987,10 @@ bitxor(PG_FUNCTION_ARGS)
bitlen1 = VARBITLEN(arg1); bitlen1 = VARBITLEN(arg1);
bitlen2 = VARBITLEN(arg2); bitlen2 = VARBITLEN(arg2);
if (bitlen1 != bitlen2) if (bitlen1 != bitlen2)
elog(ERROR, "Cannot XOR bit strings of different sizes"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot XOR bit strings of different sizes")));
len = VARSIZE(arg1); len = VARSIZE(arg1);
result = (VarBit *) palloc(len); result = (VarBit *) palloc(len);
VARATT_SIZEP(result) = len; VARATT_SIZEP(result) = len;
...@@ -1170,7 +1205,10 @@ bittoint4(PG_FUNCTION_ARGS) ...@@ -1170,7 +1205,10 @@ bittoint4(PG_FUNCTION_ARGS)
/* Check that the bit string is not too long */ /* Check that the bit string is not too long */
if (VARBITLEN(arg) > sizeof(int4) * BITS_PER_BYTE) if (VARBITLEN(arg) > sizeof(int4) * BITS_PER_BYTE)
elog(ERROR, "Bit string is too large to fit in type integer"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = 0; result = 0;
for (r = VARBITS(arg); r < VARBITEND(arg); r++) for (r = VARBITS(arg); r < VARBITEND(arg); r++)
{ {
...@@ -1214,7 +1252,10 @@ bitfromint8(PG_FUNCTION_ARGS) ...@@ -1214,7 +1252,10 @@ bitfromint8(PG_FUNCTION_ARGS)
PG_RETURN_VARBIT_P(result); PG_RETURN_VARBIT_P(result);
#else #else
elog(ERROR, "INT64 is not supported on this platform"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("int64 is not supported on this platform")));
PG_RETURN_NULL(); PG_RETURN_NULL();
#endif #endif
} }
...@@ -1229,7 +1270,10 @@ bittoint8(PG_FUNCTION_ARGS) ...@@ -1229,7 +1270,10 @@ bittoint8(PG_FUNCTION_ARGS)
/* Check that the bit string is not too long */ /* Check that the bit string is not too long */
if (VARBITLEN(arg) > sizeof(result) * BITS_PER_BYTE) if (VARBITLEN(arg) > sizeof(result) * BITS_PER_BYTE)
elog(ERROR, "Bit string is too large to fit in type int64"); ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = 0; result = 0;
for (r = VARBITS(arg); r < VARBITEND(arg); r++) for (r = VARBITS(arg); r < VARBITEND(arg); r++)
{ {
...@@ -1241,7 +1285,10 @@ bittoint8(PG_FUNCTION_ARGS) ...@@ -1241,7 +1285,10 @@ bittoint8(PG_FUNCTION_ARGS)
PG_RETURN_INT64(result); PG_RETURN_INT64(result);
#else #else
elog(ERROR, "INT64 is not supported on this platform"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("int64 is not supported on this platform")));
PG_RETURN_NULL(); PG_RETURN_NULL();
#endif #endif
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.98 2003/06/22 22:04:54 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.99 2003/07/27 04:53:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -73,18 +73,14 @@ bpcharin(PG_FUNCTION_ARGS) ...@@ -73,18 +73,14 @@ bpcharin(PG_FUNCTION_ARGS)
size_t len, size_t len,
maxlen; maxlen;
int i; int i;
int charlen; /* number of charcters in the input string */ int charlen; /* number of charcters in the input string */
char *ermsg;
/* verify encoding */
len = strlen(s); len = strlen(s);
pg_verifymbstr(s, len, false);
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
charlen = pg_mbstrlen(s); charlen = pg_mbstrlen(s);
/* If typmod is -1 (or invalid), use the actual string length */ /* If typmod is -1 (or invalid), use the actual string length */
if (atttypmod < (int32) VARHDRSZ) if (atttypmod < (int32) VARHDRSZ)
maxlen = charlen; maxlen = charlen;
...@@ -104,8 +100,10 @@ bpcharin(PG_FUNCTION_ARGS) ...@@ -104,8 +100,10 @@ bpcharin(PG_FUNCTION_ARGS)
if (strspn(s + mbmaxlen, " ") == len - mbmaxlen) if (strspn(s + mbmaxlen, " ") == len - mbmaxlen)
len = mbmaxlen; len = mbmaxlen;
else else
elog(ERROR, "value too long for type character(%d)", ereport(ERROR,
(int) maxlen); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("value too long for type character(%d)",
(int) maxlen)));
/* /*
* XXX: at this point, maxlen is the necessary byte length, not * XXX: at this point, maxlen is the necessary byte length, not
...@@ -230,8 +228,10 @@ bpchar(PG_FUNCTION_ARGS) ...@@ -230,8 +228,10 @@ bpchar(PG_FUNCTION_ARGS)
{ {
for (i = maxmblen - VARHDRSZ; i < len - VARHDRSZ; i++) for (i = maxmblen - VARHDRSZ; i < len - VARHDRSZ; i++)
if (*(VARDATA(source) + i) != ' ') if (*(VARDATA(source) + i) != ' ')
elog(ERROR, "value too long for type character(%d)", ereport(ERROR,
maxlen - VARHDRSZ); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("value too long for type character(%d)",
maxlen - VARHDRSZ)));
} }
len = maxmblen; len = maxmblen;
...@@ -372,12 +372,9 @@ varcharin(PG_FUNCTION_ARGS) ...@@ -372,12 +372,9 @@ varcharin(PG_FUNCTION_ARGS)
size_t len, size_t len,
maxlen; maxlen;
char *ermsg; /* verify encoding */
len = strlen(s); len = strlen(s);
pg_verifymbstr(s, len, false);
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
maxlen = atttypmod - VARHDRSZ; maxlen = atttypmod - VARHDRSZ;
...@@ -389,8 +386,10 @@ varcharin(PG_FUNCTION_ARGS) ...@@ -389,8 +386,10 @@ varcharin(PG_FUNCTION_ARGS)
if (strspn(s + mbmaxlen, " ") == len - mbmaxlen) if (strspn(s + mbmaxlen, " ") == len - mbmaxlen)
len = mbmaxlen; len = mbmaxlen;
else else
elog(ERROR, "value too long for type character varying(%d)", ereport(ERROR,
(int) maxlen); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("value too long for type character varying(%d)",
(int) maxlen)));
} }
result = palloc(len + VARHDRSZ); result = palloc(len + VARHDRSZ);
...@@ -487,8 +486,10 @@ varchar(PG_FUNCTION_ARGS) ...@@ -487,8 +486,10 @@ varchar(PG_FUNCTION_ARGS)
{ {
for (i = maxmblen; i < len - VARHDRSZ; i++) for (i = maxmblen; i < len - VARHDRSZ; i++)
if (*(VARDATA(source) + i) != ' ') if (*(VARDATA(source) + i) != ' ')
elog(ERROR, "value too long for type character varying(%d)", ereport(ERROR,
maxlen - VARHDRSZ); (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
errmsg("value too long for type character varying(%d)",
maxlen - VARHDRSZ)));
} }
len = maxmblen + VARHDRSZ; len = maxmblen + VARHDRSZ;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.101 2003/06/27 00:33:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.102 2003/07/27 04:53:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -80,7 +80,7 @@ static text *text_substring(Datum str, ...@@ -80,7 +80,7 @@ static text *text_substring(Datum str,
* *
* Non-printable characters must be passed as '\nnn' (octal) and are * Non-printable characters must be passed as '\nnn' (octal) and are
* converted to internal form. '\' must be passed as '\\'. * converted to internal form. '\' must be passed as '\\'.
* elog(ERROR, ...) if bad form. * ereport(ERROR, ...) if bad form.
* *
* BUGS: * BUGS:
* The input is scaned twice. * The input is scaned twice.
...@@ -112,7 +112,9 @@ byteain(PG_FUNCTION_ARGS) ...@@ -112,7 +112,9 @@ byteain(PG_FUNCTION_ARGS)
/* /*
* one backslash, not followed by 0 or ### valid octal * one backslash, not followed by 0 or ### valid octal
*/ */
elog(ERROR, "Bad input string for type bytea"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for bytea")));
} }
} }
...@@ -150,7 +152,9 @@ byteain(PG_FUNCTION_ARGS) ...@@ -150,7 +152,9 @@ byteain(PG_FUNCTION_ARGS)
* We should never get here. The first pass should not allow * We should never get here. The first pass should not allow
* it. * it.
*/ */
elog(ERROR, "Bad input string for type bytea"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for bytea")));
} }
} }
...@@ -255,20 +259,17 @@ textin(PG_FUNCTION_ARGS) ...@@ -255,20 +259,17 @@ textin(PG_FUNCTION_ARGS)
text *result; text *result;
int len; int len;
char *ermsg; /* verify encoding */
len = strlen(inputText);
pg_verifymbstr(inputText, len, false);
len = strlen(inputText) + VARHDRSZ; result = (text *) palloc(len + VARHDRSZ);
VARATT_SIZEP(result) = len + VARHDRSZ;
if ((ermsg = pg_verifymbstr(inputText, len - VARHDRSZ))) memcpy(VARDATA(result), inputText, len);
elog(ERROR, "%s", ermsg);
result = (text *) palloc(len);
VARATT_SIZEP(result) = len;
memcpy(VARDATA(result), inputText, len - VARHDRSZ);
#ifdef CYR_RECODE #ifdef CYR_RECODE
convertstr(VARDATA(result), len - VARHDRSZ, 0); convertstr(VARDATA(result), len, 0);
#endif #endif
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
...@@ -435,8 +436,7 @@ text_length(Datum str) ...@@ -435,8 +436,7 @@ text_length(Datum str)
} }
/* should never get here */ /* should never get here */
elog(ERROR, "Invalid backend encoding; encoding max length " elog(ERROR, "invalid backend encoding: encoding max length < 1");
"is less than one.");
/* not reached: suppress compiler warning */ /* not reached: suppress compiler warning */
return 0; return 0;
...@@ -582,7 +582,9 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified) ...@@ -582,7 +582,9 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
* to be before the start. SQL99 says to throw an error. * to be before the start. SQL99 says to throw an error.
*/ */
if (E < S) if (E < S)
elog(ERROR, "negative substring length not allowed"); ereport(ERROR,
(errcode(ERRCODE_SUBSTRING_ERROR),
errmsg("negative substring length not allowed")));
/* /*
* A zero or negative value for the end position can happen if * A zero or negative value for the end position can happen if
...@@ -644,7 +646,9 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified) ...@@ -644,7 +646,9 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
* to be before the start. SQL99 says to throw an error. * to be before the start. SQL99 says to throw an error.
*/ */
if (E < S) if (E < S)
elog(ERROR, "negative substring length not allowed"); ereport(ERROR,
(errcode(ERRCODE_SUBSTRING_ERROR),
errmsg("negative substring length not allowed")));
/* /*
* A zero or negative value for the end position can happen if * A zero or negative value for the end position can happen if
...@@ -718,8 +722,7 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified) ...@@ -718,8 +722,7 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
return ret; return ret;
} }
else else
elog(ERROR, "Invalid backend encoding; encoding max length " elog(ERROR, "invalid backend encoding: encoding max length < 1");
"is less than one.");
/* not reached: suppress compiler warning */ /* not reached: suppress compiler warning */
return PG_STR_GET_TEXT(""); return PG_STR_GET_TEXT("");
...@@ -821,8 +824,7 @@ text_position(Datum str, Datum search_str, int matchnum) ...@@ -821,8 +824,7 @@ text_position(Datum str, Datum search_str, int matchnum)
pfree(ps2); pfree(ps2);
} }
else else
elog(ERROR, "Invalid backend encoding; encoding max length " elog(ERROR, "invalid backend encoding: encoding max length < 1");
"is less than one.");
PG_RETURN_INT32(pos); PG_RETURN_INT32(pos);
} }
...@@ -1295,7 +1297,9 @@ bytea_substr(PG_FUNCTION_ARGS) ...@@ -1295,7 +1297,9 @@ bytea_substr(PG_FUNCTION_ARGS)
* be before the start. SQL99 says to throw an error. * be before the start. SQL99 says to throw an error.
*/ */
if (E < S) if (E < S)
elog(ERROR, "negative substring length not allowed"); ereport(ERROR,
(errcode(ERRCODE_SUBSTRING_ERROR),
errmsg("negative substring length not allowed")));
/* /*
* A zero or negative value for the end position can happen if the * A zero or negative value for the end position can happen if the
...@@ -1388,8 +1392,10 @@ byteaGetByte(PG_FUNCTION_ARGS) ...@@ -1388,8 +1392,10 @@ byteaGetByte(PG_FUNCTION_ARGS)
len = VARSIZE(v) - VARHDRSZ; len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len) if (n < 0 || n >= len)
elog(ERROR, "byteaGetByte: index %d out of range [0..%d]", ereport(ERROR,
n, len - 1); (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("index %d out of valid range, 0..%d",
n, len - 1)));
byte = ((unsigned char *) VARDATA(v))[n]; byte = ((unsigned char *) VARDATA(v))[n];
...@@ -1417,8 +1423,10 @@ byteaGetBit(PG_FUNCTION_ARGS) ...@@ -1417,8 +1423,10 @@ byteaGetBit(PG_FUNCTION_ARGS)
len = VARSIZE(v) - VARHDRSZ; len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len * 8) if (n < 0 || n >= len * 8)
elog(ERROR, "byteaGetBit: index %d out of range [0..%d]", ereport(ERROR,
n, len * 8 - 1); (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("index %d out of valid range, 0..%d",
n, len * 8 - 1)));
byteNo = n / 8; byteNo = n / 8;
bitNo = n % 8; bitNo = n % 8;
...@@ -1451,8 +1459,10 @@ byteaSetByte(PG_FUNCTION_ARGS) ...@@ -1451,8 +1459,10 @@ byteaSetByte(PG_FUNCTION_ARGS)
len = VARSIZE(v) - VARHDRSZ; len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len) if (n < 0 || n >= len)
elog(ERROR, "byteaSetByte: index %d out of range [0..%d]", ereport(ERROR,
n, len - 1); (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("index %d out of valid range, 0..%d",
n, len - 1)));
/* /*
* Make a copy of the original varlena. * Make a copy of the original varlena.
...@@ -1492,8 +1502,10 @@ byteaSetBit(PG_FUNCTION_ARGS) ...@@ -1492,8 +1502,10 @@ byteaSetBit(PG_FUNCTION_ARGS)
len = VARSIZE(v) - VARHDRSZ; len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len * 8) if (n < 0 || n >= len * 8)
elog(ERROR, "byteaSetBit: index %d out of range [0..%d]", ereport(ERROR,
n, len * 8 - 1); (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("index %d out of valid range, 0..%d",
n, len * 8 - 1)));
byteNo = n / 8; byteNo = n / 8;
bitNo = n % 8; bitNo = n % 8;
...@@ -1502,7 +1514,9 @@ byteaSetBit(PG_FUNCTION_ARGS) ...@@ -1502,7 +1514,9 @@ byteaSetBit(PG_FUNCTION_ARGS)
* sanity check! * sanity check!
*/ */
if (newBit != 0 && newBit != 1) if (newBit != 0 && newBit != 1)
elog(ERROR, "byteaSetBit: new bit must be 0 or 1"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("new bit must be 0 or 1")));
/* /*
* Make a copy of the original varlena. * Make a copy of the original varlena.
...@@ -1607,10 +1621,14 @@ textToQualifiedNameList(text *textval, const char *caller) ...@@ -1607,10 +1621,14 @@ textToQualifiedNameList(text *textval, const char *caller)
PointerGetDatum(textval))); PointerGetDatum(textval)));
if (!SplitIdentifierString(rawname, '.', &namelist)) if (!SplitIdentifierString(rawname, '.', &namelist))
elog(ERROR, "%s: invalid name syntax", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
if (namelist == NIL) if (namelist == NIL)
elog(ERROR, "%s: invalid name syntax", caller); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
foreach(l, namelist) foreach(l, namelist)
{ {
...@@ -1992,7 +2010,9 @@ split_text(PG_FUNCTION_ARGS) ...@@ -1992,7 +2010,9 @@ split_text(PG_FUNCTION_ARGS)
/* field number is 1 based */ /* field number is 1 based */
if (fldnum < 1) if (fldnum < 1)
elog(ERROR, "field position must be > 0"); ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("field position must be greater than zero")));
start_posn = text_position(PointerGetDatum(inputstring), start_posn = text_position(PointerGetDatum(inputstring),
PointerGetDatum(fldsep), PointerGetDatum(fldsep),
......
/* /*
* conversion functions between pg_wchar and multibyte streams. * conversion functions between pg_wchar and multibyte streams.
* Tatsuo Ishii * Tatsuo Ishii
* $Id: wchar.c,v 1.31 2003/01/11 06:55:11 ishii Exp $ * $Id: wchar.c,v 1.32 2003/07/27 04:53:11 tgl Exp $
* *
* WIN1250 client encoding updated by Pavel Behal * WIN1250 client encoding updated by Pavel Behal
* *
...@@ -606,78 +606,78 @@ pg_encoding_max_length(int encoding) ...@@ -606,78 +606,78 @@ pg_encoding_max_length(int encoding)
} }
#ifndef FRONTEND #ifndef FRONTEND
/* /*
* Verify mbstr to make sure that it has a valid character sequence. * Verify mbstr to make sure that it has a valid character sequence.
* mbstr is not necessarily NULL terminated. length of mbstr is * mbstr is not necessarily NULL terminated; length of mbstr is
* specified by len. If an error was found, returns an error message. * specified by len.
* Note that the message is kept in a static buffer, the next invocation *
* might break the message. * If OK, return TRUE. If a problem is found, return FALSE when noError is
* If no error was found, this function returns NULL. * true; when noError is false, ereport() a descriptive message.
*/ */
char * bool
pg_verifymbstr(const unsigned char *mbstr, int len) pg_verifymbstr(const unsigned char *mbstr, int len, bool noError)
{ {
int l; int l;
int i, int i;
j; int encoding;
static char buf[256];
int slen = 0;
/* we do not check single byte encodings */ /* we do not need any check in single-byte encodings */
if (pg_database_encoding_max_length() <= 1) if (pg_database_encoding_max_length() <= 1)
return NULL; return true;
encoding = GetDatabaseEncoding();
while (len > 0 && *mbstr) while (len > 0 && *mbstr)
{ {
/* special UTF-8 check */ /* special UTF-8 check */
if (GetDatabaseEncoding() == PG_UTF8 && if (encoding == PG_UTF8 && (*mbstr & 0xf8) == 0xf0)
(*mbstr & 0xf8) == 0xf0)
{ {
snprintf(buf, sizeof(buf), "Unicode >= 0x10000 is not supported"); if (noError)
return (buf); return false;
ereport(ERROR,
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
errmsg("UNICODE characters >= 0x10000 are not supported")));
} }
l = pg_mblen(mbstr); l = pg_mblen(mbstr);
/* multibyte letter? */
if (l > 1)
{
for (i = 1; i < l; i++) for (i = 1; i < l; i++)
{ {
if (i > len || *(mbstr + i) == '\0' ||
/* /*
* we assume that every multibyte letter consists of bytes * we expect that every multibyte char consists of bytes
* being the 8th bit set * having the 8th bit set
*/ */
((*(mbstr + i) & 0x80) == 0)) if (i >= len || (mbstr[i] & 0x80) == 0)
{ {
int remains = sizeof(buf); char buf[8 * 2 + 1];
char *p = buf; char *p = buf;
int j,
jlimit;
slen = snprintf(p, remains, "Invalid %s character sequence found (0x", if (noError)
GetDatabaseEncodingName()); return false;
p += slen;
remains -= slen;
i = ((*(mbstr + i) & 0x80) == 0) ? l : i; jlimit = Min(l, len);
jlimit = Min(jlimit, 8); /* prevent buffer overrun */
for (j = 0; j < i; j++) for (j = 0; j < jlimit; j++)
{ {
slen = snprintf(p, remains, "%02x", p += sprintf(p, "%02x", mbstr[j]);
*(mbstr + j));
p += slen;
remains -= slen;
}
snprintf(p, remains, ")");
return (buf);
} }
ereport(ERROR,
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
errmsg("invalid %s character sequence: 0x%s",
GetDatabaseEncodingName(), buf)));
} }
} }
len -= l; len -= l;
mbstr += l; mbstr += l;
} }
return NULL;
return true;
} }
/* /*
......
/* $Id: pg_wchar.h,v 1.46 2003/06/02 18:59:25 momjian Exp $ */ /* $Id: pg_wchar.h,v 1.47 2003/07/27 04:53:11 tgl Exp $ */
#ifndef PG_WCHAR_H #ifndef PG_WCHAR_H
#define PG_WCHAR_H #define PG_WCHAR_H
...@@ -323,7 +323,7 @@ extern void LocalToUtf(unsigned char *iso, unsigned char *utf, ...@@ -323,7 +323,7 @@ extern void LocalToUtf(unsigned char *iso, unsigned char *utf,
extern void UtfToLocal(unsigned char *utf, unsigned char *iso, extern void UtfToLocal(unsigned char *utf, unsigned char *iso,
pg_utf_to_local *map, int size, int len); pg_utf_to_local *map, int size, int len);
extern char *pg_verifymbstr(const unsigned char *mbstr, int len); extern bool pg_verifymbstr(const unsigned char *mbstr, int len, bool noError);
extern void pg_ascii2mic(unsigned char *src, unsigned char *dest, int len); extern void pg_ascii2mic(unsigned char *src, unsigned char *dest, int len);
extern void pg_mic2ascii(unsigned char *src, unsigned char *dest, int len); extern void pg_mic2ascii(unsigned char *src, unsigned char *dest, int len);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: elog.h,v 1.58 2003/07/25 20:18:00 tgl Exp $ * $Id: elog.h,v 1.59 2003/07/27 04:53:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -131,6 +131,7 @@ ...@@ -131,6 +131,7 @@
#define ERRCODE_ARRAY_SUBSCRIPT_ERROR ERRCODE_ARRAY_ELEMENT_ERROR #define ERRCODE_ARRAY_SUBSCRIPT_ERROR ERRCODE_ARRAY_ELEMENT_ERROR
#define ERRCODE_CHARACTER_NOT_IN_REPERTOIRE MAKE_SQLSTATE('2','2', '0','2','1') #define ERRCODE_CHARACTER_NOT_IN_REPERTOIRE MAKE_SQLSTATE('2','2', '0','2','1')
#define ERRCODE_DATETIME_FIELD_OVERFLOW MAKE_SQLSTATE('2','2', '0','0','8') #define ERRCODE_DATETIME_FIELD_OVERFLOW MAKE_SQLSTATE('2','2', '0','0','8')
#define ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ERRCODE_DATETIME_FIELD_OVERFLOW
#define ERRCODE_DIVISION_BY_ZERO MAKE_SQLSTATE('2','2', '0','1','2') #define ERRCODE_DIVISION_BY_ZERO MAKE_SQLSTATE('2','2', '0','1','2')
#define ERRCODE_ERROR_IN_ASSIGNMENT MAKE_SQLSTATE('2','2', '0','0','5') #define ERRCODE_ERROR_IN_ASSIGNMENT MAKE_SQLSTATE('2','2', '0','0','5')
#define ERRCODE_ESCAPE_CHARACTER_CONFLICT MAKE_SQLSTATE('2','2', '0','0','B') #define ERRCODE_ESCAPE_CHARACTER_CONFLICT MAKE_SQLSTATE('2','2', '0','0','B')
...@@ -157,10 +158,11 @@ ...@@ -157,10 +158,11 @@
#define ERRCODE_TRIM_ERROR MAKE_SQLSTATE('2','2', '0','2','7') #define ERRCODE_TRIM_ERROR MAKE_SQLSTATE('2','2', '0','2','7')
#define ERRCODE_UNTERMINATED_C_STRING MAKE_SQLSTATE('2','2', '0','2','4') #define ERRCODE_UNTERMINATED_C_STRING MAKE_SQLSTATE('2','2', '0','2','4')
#define ERRCODE_ZERO_LENGTH_CHARACTER_STRING MAKE_SQLSTATE('2','2', '0','0','F') #define ERRCODE_ZERO_LENGTH_CHARACTER_STRING MAKE_SQLSTATE('2','2', '0','0','F')
#define ERRCODE_BAD_COPY_FILE_FORMAT MAKE_SQLSTATE('2','2', 'P','0','1') #define ERRCODE_FLOATING_POINT_EXCEPTION MAKE_SQLSTATE('2','2', 'P','0','1')
#define ERRCODE_INVALID_BINARY_REPRESENTATION MAKE_SQLSTATE('2','2', 'P','0','2') #define ERRCODE_INVALID_TEXT_REPRESENTATION MAKE_SQLSTATE('2','2', 'P','0','2')
#define ERRCODE_FLOATING_POINT_EXCEPTION MAKE_SQLSTATE('2','2', 'P','0','3') #define ERRCODE_INVALID_BINARY_REPRESENTATION MAKE_SQLSTATE('2','2', 'P','0','3')
#define ERRCODE_UNTRANSLATABLE_CHARACTER MAKE_SQLSTATE('2','2', 'P','0','4') #define ERRCODE_BAD_COPY_FILE_FORMAT MAKE_SQLSTATE('2','2', 'P','0','4')
#define ERRCODE_UNTRANSLATABLE_CHARACTER MAKE_SQLSTATE('2','2', 'P','0','5')
/* Class 23 - Integrity Constraint Violation */ /* Class 23 - Integrity Constraint Violation */
#define ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('2','3', '0','0','0') #define ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('2','3', '0','0','0')
......
...@@ -28,12 +28,12 @@ INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity'); ...@@ -28,12 +28,12 @@ INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity');
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12'); INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
-- what happens if we specify slightly misformatted abstime? -- what happens if we specify slightly misformatted abstime?
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'); INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00');
ERROR: Bad abstime external representation 'Feb 35, 1946 10:00:00' ERROR: invalid input syntax for abstime: "Feb 35, 1946 10:00:00"
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'); INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
ERROR: Bad abstime external representation 'Feb 28, 1984 25:08:10' ERROR: invalid input syntax for abstime: "Feb 28, 1984 25:08:10"
-- badly formatted abstimes: these should result in invalid abstimes -- badly formatted abstimes: these should result in invalid abstimes
INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format'); INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
ERROR: Bad abstime external representation 'bad date format' ERROR: invalid input syntax for abstime: "bad date format"
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843'); INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
-- test abstime operators -- test abstime operators
SELECT '' AS eight, ABSTIME_TBL.*; SELECT '' AS eight, ABSTIME_TBL.*;
......
...@@ -28,12 +28,12 @@ INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity'); ...@@ -28,12 +28,12 @@ INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity');
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12'); INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
-- what happens if we specify slightly misformatted abstime? -- what happens if we specify slightly misformatted abstime?
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'); INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00');
ERROR: Bad abstime external representation 'Feb 35, 1946 10:00:00' ERROR: invalid input syntax for abstime: "Feb 35, 1946 10:00:00"
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'); INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
ERROR: Bad abstime external representation 'Feb 28, 1984 25:08:10' ERROR: invalid input syntax for abstime: "Feb 28, 1984 25:08:10"
-- badly formatted abstimes: these should result in invalid abstimes -- badly formatted abstimes: these should result in invalid abstimes
INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format'); INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
ERROR: Bad abstime external representation 'bad date format' ERROR: invalid input syntax for abstime: "bad date format"
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843'); INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
-- test abstime operators -- test abstime operators
SELECT '' AS eight, ABSTIME_TBL.*; SELECT '' AS eight, ABSTIME_TBL.*;
......
...@@ -709,7 +709,7 @@ select * from def_test; ...@@ -709,7 +709,7 @@ select * from def_test;
-- set defaults to an incorrect type: this should fail -- set defaults to an incorrect type: this should fail
alter table def_test alter column c1 set default 'wrong_datatype'; alter table def_test alter column c1 set default 'wrong_datatype';
ERROR: pg_atoi: error in "wrong_datatype": can't parse "wrong_datatype" ERROR: invalid input syntax for integer: "wrong_datatype"
alter table def_test alter column c2 set default 20; alter table def_test alter column c2 set default 20;
-- set defaults on a non-existent column: this should fail -- set defaults on a non-existent column: this should fail
alter table def_test alter column c3 set default 30; alter table def_test alter column c3 set default 30;
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
-- --
CREATE TABLE BIT_TABLE(b BIT(11)); CREATE TABLE BIT_TABLE(b BIT(11));
INSERT INTO BIT_TABLE VALUES (B'10'); -- too short INSERT INTO BIT_TABLE VALUES (B'10'); -- too short
ERROR: Bit string length 2 does not match type BIT(11) ERROR: bit string length 2 does not match type bit(11)
INSERT INTO BIT_TABLE VALUES (B'00000000000'); INSERT INTO BIT_TABLE VALUES (B'00000000000');
INSERT INTO BIT_TABLE VALUES (B'11011000000'); INSERT INTO BIT_TABLE VALUES (B'11011000000');
INSERT INTO BIT_TABLE VALUES (B'01010101010'); INSERT INTO BIT_TABLE VALUES (B'01010101010');
INSERT INTO BIT_TABLE VALUES (B'101011111010'); -- too long INSERT INTO BIT_TABLE VALUES (B'101011111010'); -- too long
ERROR: Bit string length 12 does not match type BIT(11) ERROR: bit string length 12 does not match type bit(11)
--INSERT INTO BIT_TABLE VALUES ('X554'); --INSERT INTO BIT_TABLE VALUES ('X554');
--INSERT INTO BIT_TABLE VALUES ('X555'); --INSERT INTO BIT_TABLE VALUES ('X555');
SELECT * FROM BIT_TABLE; SELECT * FROM BIT_TABLE;
...@@ -28,7 +28,7 @@ INSERT INTO VARBIT_TABLE VALUES (B'0'); ...@@ -28,7 +28,7 @@ INSERT INTO VARBIT_TABLE VALUES (B'0');
INSERT INTO VARBIT_TABLE VALUES (B'010101'); INSERT INTO VARBIT_TABLE VALUES (B'010101');
INSERT INTO VARBIT_TABLE VALUES (B'01010101010'); INSERT INTO VARBIT_TABLE VALUES (B'01010101010');
INSERT INTO VARBIT_TABLE VALUES (B'101011111010'); -- too long INSERT INTO VARBIT_TABLE VALUES (B'101011111010'); -- too long
ERROR: Bit string too long for type BIT VARYING(11) ERROR: bit string too long for type bit varying(11)
--INSERT INTO VARBIT_TABLE VALUES ('X554'); --INSERT INTO VARBIT_TABLE VALUES ('X554');
--INSERT INTO VARBIT_TABLE VALUES ('X555'); --INSERT INTO VARBIT_TABLE VALUES ('X555');
SELECT * FROM VARBIT_TABLE; SELECT * FROM VARBIT_TABLE;
...@@ -212,11 +212,11 @@ SELECT a,a<<4 AS "a<<4",b,b>>2 AS "b>>2" FROM bit_table; ...@@ -212,11 +212,11 @@ SELECT a,a<<4 AS "a<<4",b,b>>2 AS "b>>2" FROM bit_table;
DROP TABLE bit_table; DROP TABLE bit_table;
-- The following should fail -- The following should fail
select B'001' & B'10'; select B'001' & B'10';
ERROR: Cannot AND bit strings of different sizes ERROR: cannot AND bit strings of different sizes
select B'0111' | B'011'; select B'0111' | B'011';
ERROR: Cannot OR bit strings of different sizes ERROR: cannot OR bit strings of different sizes
select B'0010' # B'011101'; select B'0010' # B'011101';
ERROR: Cannot XOR bit strings of different sizes ERROR: cannot XOR bit strings of different sizes
-- More position tests, checking all the boundary cases -- More position tests, checking all the boundary cases
SELECT POSITION(B'1010' IN B'0000101'); -- 0 SELECT POSITION(B'1010' IN B'0000101'); -- 0
position position
......
...@@ -112,7 +112,7 @@ INSERT INTO BOOLTBL2 (f1) VALUES (bool 'FALSE'); ...@@ -112,7 +112,7 @@ INSERT INTO BOOLTBL2 (f1) VALUES (bool 'FALSE');
-- For pre-v6.3 this evaluated to false - thomas 1997-10-23 -- For pre-v6.3 this evaluated to false - thomas 1997-10-23
INSERT INTO BOOLTBL2 (f1) INSERT INTO BOOLTBL2 (f1)
VALUES (bool 'XXX'); VALUES (bool 'XXX');
ERROR: Bad boolean external representation 'XXX' ERROR: invalid input syntax for boolean: "XXX"
-- BOOLTBL2 should be full of false's at this point -- BOOLTBL2 should be full of false's at this point
SELECT '' AS f_4, BOOLTBL2.*; SELECT '' AS f_4, BOOLTBL2.*;
f_4 | f1 f_4 | f1
......
...@@ -24,9 +24,9 @@ INSERT INTO BOX_TBL (f1) VALUES ('(2.5, 2.5, 2.5,3.5)'); ...@@ -24,9 +24,9 @@ INSERT INTO BOX_TBL (f1) VALUES ('(2.5, 2.5, 2.5,3.5)');
INSERT INTO BOX_TBL (f1) VALUES ('(3.0, 3.0,3.0,3.0)'); INSERT INTO BOX_TBL (f1) VALUES ('(3.0, 3.0,3.0,3.0)');
-- badly formatted box inputs -- badly formatted box inputs
INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)'); INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
ERROR: Bad box external representation '(2.3, 4.5)' ERROR: invalid input syntax for box: "(2.3, 4.5)"
INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad'); INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
ERROR: Bad box external representation 'asdfasdf(ad' ERROR: invalid input syntax for box: "asdfasdf(ad"
SELECT '' AS four, BOX_TBL.*; SELECT '' AS four, BOX_TBL.*;
four | f1 four | f1
------+--------------------- ------+---------------------
......
...@@ -10,11 +10,11 @@ INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>'); ...@@ -10,11 +10,11 @@ INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>'); INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
-- bad values -- bad values
INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>'); INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
ERROR: Bad circle external representation '<(-100,0),-100>' ERROR: invalid input syntax for circle: "<(-100,0),-100>"
INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5'); INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5');
ERROR: Bad circle external representation '1abc,3,5' ERROR: invalid input syntax for circle: "1abc,3,5"
INSERT INTO CIRCLE_TBL VALUES ('(3,(1,2),3)'); INSERT INTO CIRCLE_TBL VALUES ('(3,(1,2),3)');
ERROR: Bad circle external representation '(3,(1,2),3)' ERROR: invalid input syntax for circle: "(3,(1,2),3)"
SELECT * FROM CIRCLE_TBL; SELECT * FROM CIRCLE_TBL;
f1 f1
---------------- ----------------
......
...@@ -34,7 +34,7 @@ COPY x (a, b, c, d, e, d, c) from stdin; ...@@ -34,7 +34,7 @@ COPY x (a, b, c, d, e, d, c) from stdin;
ERROR: attribute "d" specified more than once ERROR: attribute "d" specified more than once
-- missing data: should fail -- missing data: should fail
COPY x from stdin; COPY x from stdin;
ERROR: pg_atoi: zero-length string ERROR: invalid input syntax for integer: ""
CONTEXT: COPY FROM, line 1 CONTEXT: COPY FROM, line 1
COPY x from stdin; COPY x from stdin;
ERROR: missing data for column "e" ERROR: missing data for column "e"
......
...@@ -10,7 +10,7 @@ INSERT INTO DATE_TBL VALUES ('1996-03-01'); ...@@ -10,7 +10,7 @@ INSERT INTO DATE_TBL VALUES ('1996-03-01');
INSERT INTO DATE_TBL VALUES ('1996-03-02'); INSERT INTO DATE_TBL VALUES ('1996-03-02');
INSERT INTO DATE_TBL VALUES ('1997-02-28'); INSERT INTO DATE_TBL VALUES ('1997-02-28');
INSERT INTO DATE_TBL VALUES ('1997-02-29'); INSERT INTO DATE_TBL VALUES ('1997-02-29');
ERROR: Bad date external representation '1997-02-29' ERROR: invalid input syntax for date: "1997-02-29"
INSERT INTO DATE_TBL VALUES ('1997-03-01'); INSERT INTO DATE_TBL VALUES ('1997-03-01');
INSERT INTO DATE_TBL VALUES ('1997-03-02'); INSERT INTO DATE_TBL VALUES ('1997-03-02');
INSERT INTO DATE_TBL VALUES ('2000-04-01'); INSERT INTO DATE_TBL VALUES ('2000-04-01');
......
...@@ -9,13 +9,13 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20'); ...@@ -9,13 +9,13 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20'); INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow -- test for over and under flow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40');
ERROR: Bad float4 input format -- overflow ERROR: float4 value out of range: overflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40');
ERROR: Bad float4 input format -- overflow ERROR: float4 value out of range: overflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
ERROR: Bad float4 input format -- underflow ERROR: float4 value out of range: underflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
ERROR: Bad float4 input format -- underflow ERROR: float4 value out of range: underflow
SELECT '' AS five, FLOAT4_TBL.*; SELECT '' AS five, FLOAT4_TBL.*;
five | f1 five | f1
------+-------------- ------+--------------
......
...@@ -9,13 +9,13 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20'); ...@@ -9,13 +9,13 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20'); INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow -- test for over and under flow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40');
ERROR: Bad float4 input format -- overflow ERROR: float4 value out of range: overflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40');
ERROR: Bad float4 input format -- overflow ERROR: float4 value out of range: overflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
ERROR: Bad float4 input format -- underflow ERROR: float4 value out of range: underflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40'); INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
ERROR: Bad float4 input format -- underflow ERROR: float4 value out of range: underflow
SELECT '' AS five, FLOAT4_TBL.*; SELECT '' AS five, FLOAT4_TBL.*;
five | f1 five | f1
------+------------- ------+-------------
......
...@@ -247,15 +247,15 @@ UPDATE FLOAT8_TBL ...@@ -247,15 +247,15 @@ UPDATE FLOAT8_TBL
SET f1 = FLOAT8_TBL.f1 * '-1' SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0'; WHERE FLOAT8_TBL.f1 > '0.0';
SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
ERROR: Bad float8 input format -- overflow ERROR: float8 value out of range: overflow
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
ERROR: pow() result is out of range ERROR: result is out of range
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
ERROR: can't take log of zero ERROR: cannot take log of zero
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
ERROR: can't take log of a negative number ERROR: cannot take log of a negative number
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*; SELECT '' AS five, FLOAT8_TBL.*;
...@@ -270,13 +270,13 @@ SELECT '' AS five, FLOAT8_TBL.*; ...@@ -270,13 +270,13 @@ SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow -- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: Input '10e400' is out of range for float8 ERROR: "10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
ERROR: Input '-10e400' is out of range for float8 ERROR: "-10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
ERROR: Input '10e-400' is out of range for float8 ERROR: "10e-400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
ERROR: Input '-10e-400' is out of range for float8 ERROR: "-10e-400" is out of range for float8
-- maintain external table consistency across platforms -- maintain external table consistency across platforms
-- delete all values and reinsert well-behaved ones -- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL; DELETE FROM FLOAT8_TBL;
......
...@@ -247,15 +247,16 @@ UPDATE FLOAT8_TBL ...@@ -247,15 +247,16 @@ UPDATE FLOAT8_TBL
SET f1 = FLOAT8_TBL.f1 * '-1' SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0'; WHERE FLOAT8_TBL.f1 > '0.0';
SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
ERROR: floating point exception! The last floating point operation either exceeded legal ranges or was a divide by zero ERROR: floating-point exception
DETAIL: An invalid floating-point operation was signaled. This probably means an out-of-range result or an invalid operation, such as division by zero.
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
ERROR: pow() result is out of range ERROR: result is out of range
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
ERROR: can't take log of zero ERROR: cannot take log of zero
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
ERROR: can't take log of a negative number ERROR: cannot take log of a negative number
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*; SELECT '' AS five, FLOAT8_TBL.*;
...@@ -270,13 +271,13 @@ SELECT '' AS five, FLOAT8_TBL.*; ...@@ -270,13 +271,13 @@ SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow -- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: Input '10e400' is out of range for float8 ERROR: "10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
ERROR: Input '-10e400' is out of range for float8 ERROR: "-10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
ERROR: Input '10e-400' is out of range for float8 ERROR: "10e-400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
ERROR: Input '-10e-400' is out of range for float8 ERROR: "-10e-400" is out of range for float8
-- maintain external table consistency across platforms -- maintain external table consistency across platforms
-- delete all values and reinsert well-behaved ones -- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL; DELETE FROM FLOAT8_TBL;
......
...@@ -247,15 +247,15 @@ UPDATE FLOAT8_TBL ...@@ -247,15 +247,15 @@ UPDATE FLOAT8_TBL
SET f1 = FLOAT8_TBL.f1 * '-1' SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0'; WHERE FLOAT8_TBL.f1 > '0.0';
SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
ERROR: Bad float8 input format -- overflow ERROR: float8 value out of range: overflow
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
ERROR: pow() result is out of range ERROR: result is out of range
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
ERROR: can't take log of zero ERROR: cannot take log of zero
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
ERROR: can't take log of a negative number ERROR: cannot take log of a negative number
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*; SELECT '' AS five, FLOAT8_TBL.*;
...@@ -270,9 +270,9 @@ SELECT '' AS five, FLOAT8_TBL.*; ...@@ -270,9 +270,9 @@ SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow -- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: Input '10e400' is out of range for float8 ERROR: "10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
ERROR: Input '-10e400' is out of range for float8 ERROR: "-10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
-- maintain external table consistency across platforms -- maintain external table consistency across platforms
......
...@@ -247,15 +247,15 @@ UPDATE FLOAT8_TBL ...@@ -247,15 +247,15 @@ UPDATE FLOAT8_TBL
SET f1 = FLOAT8_TBL.f1 * '-1' SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0'; WHERE FLOAT8_TBL.f1 > '0.0';
SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
ERROR: Bad float8 input format -- overflow ERROR: float8 value out of range: overflow
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
ERROR: pow() result is out of range ERROR: result is out of range
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
ERROR: can't take log of zero ERROR: cannot take log of zero
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ; SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
ERROR: can't take log of a negative number ERROR: cannot take log of a negative number
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*; SELECT '' AS five, FLOAT8_TBL.*;
...@@ -270,13 +270,13 @@ SELECT '' AS five, FLOAT8_TBL.*; ...@@ -270,13 +270,13 @@ SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow -- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: Input '10e400' is out of range for float8 ERROR: "10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
ERROR: Input '-10e400' is out of range for float8 ERROR: "-10e400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
ERROR: Input '10e-400' is out of range for float8 ERROR: "10e-400" is out of range for float8
INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400'); INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
ERROR: Input '-10e-400' is out of range for float8 ERROR: "-10e-400" is out of range for float8
-- maintain external table consistency across platforms -- maintain external table consistency across platforms
-- delete all values and reinsert well-behaved ones -- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL; DELETE FROM FLOAT8_TBL;
......
...@@ -2350,7 +2350,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime ...@@ -2350,7 +2350,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp" SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
FROM ABSTIME_TBL WHERE NOT isfinite(f1); FROM ABSTIME_TBL WHERE NOT isfinite(f1);
ERROR: Unable to convert abstime 'invalid' to timestamp ERROR: cannot convert "invalid" abstime to timestamp
SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
FROM INTERVAL_TBL; FROM INTERVAL_TBL;
ten | interval | reltime ten | interval | reltime
......
...@@ -2350,7 +2350,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime ...@@ -2350,7 +2350,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp" SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
FROM ABSTIME_TBL WHERE NOT isfinite(f1); FROM ABSTIME_TBL WHERE NOT isfinite(f1);
ERROR: Unable to convert abstime 'invalid' to timestamp ERROR: cannot convert "invalid" abstime to timestamp
SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
FROM INTERVAL_TBL; FROM INTERVAL_TBL;
ten | interval | reltime ten | interval | reltime
......
...@@ -2350,7 +2350,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime ...@@ -2350,7 +2350,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp" SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
FROM ABSTIME_TBL WHERE NOT isfinite(f1); FROM ABSTIME_TBL WHERE NOT isfinite(f1);
ERROR: Unable to convert abstime 'invalid' to timestamp ERROR: cannot convert "invalid" abstime to timestamp
SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime
FROM INTERVAL_TBL; FROM INTERVAL_TBL;
ten | interval | reltime ten | interval | reltime
......
...@@ -24,14 +24,17 @@ INSERT INTO INET_TBL (c, i) VALUES ('10:23::8000/113', '10:23::ffff'); ...@@ -24,14 +24,17 @@ INSERT INTO INET_TBL (c, i) VALUES ('10:23::8000/113', '10:23::ffff');
INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24'); INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24');
-- check that CIDR rejects invalid input: -- check that CIDR rejects invalid input:
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/24', '192.168.1.226'); INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/24', '192.168.1.226');
ERROR: invalid CIDR value '192.168.1.2/24': has bits set to right of mask ERROR: invalid cidr value: "192.168.1.2/24"
DETAIL: Value has bits set to right of mask.
INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4'); INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4');
ERROR: invalid CIDR value '1234::1234::1234' ERROR: invalid input syntax for cidr: "1234::1234::1234"
-- check that CIDR rejects invalid input when converting from text: -- check that CIDR rejects invalid input when converting from text:
INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/24'), '192.168.1.226'); INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/24'), '192.168.1.226');
ERROR: invalid CIDR value '192.168.1.2/24': has bits set to right of mask ERROR: invalid cidr value: "192.168.1.2/24"
DETAIL: Value has bits set to right of mask.
INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226'); INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226');
ERROR: invalid CIDR value 'ffff:ffff:ffff:ffff::/24': has bits set to right of mask ERROR: invalid cidr value: "ffff:ffff:ffff:ffff::/24"
DETAIL: Value has bits set to right of mask.
SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL; SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
ten | cidr | inet ten | cidr | inet
-----+--------------------+------------------ -----+--------------------+------------------
......
...@@ -8,15 +8,15 @@ INSERT INTO INT2_TBL(f1) VALUES ('0'); ...@@ -8,15 +8,15 @@ INSERT INTO INT2_TBL(f1) VALUES ('0');
INSERT INTO INT2_TBL(f1) VALUES ('1234'); INSERT INTO INT2_TBL(f1) VALUES ('1234');
INSERT INTO INT2_TBL(f1) VALUES ('-1234'); INSERT INTO INT2_TBL(f1) VALUES ('-1234');
INSERT INTO INT2_TBL(f1) VALUES ('34.5'); INSERT INTO INT2_TBL(f1) VALUES ('34.5');
ERROR: pg_atoi: error in "34.5": can't parse ".5" ERROR: invalid input syntax for integer: "34.5"
-- largest and smallest values -- largest and smallest values
INSERT INTO INT2_TBL(f1) VALUES ('32767'); INSERT INTO INT2_TBL(f1) VALUES ('32767');
INSERT INTO INT2_TBL(f1) VALUES ('-32767'); INSERT INTO INT2_TBL(f1) VALUES ('-32767');
-- bad input values -- should give warnings -- bad input values -- should give warnings
INSERT INTO INT2_TBL(f1) VALUES ('100000'); INSERT INTO INT2_TBL(f1) VALUES ('100000');
ERROR: pg_atoi: error reading "100000": Numerical result out of range ERROR: 100000 is out of range for int2
INSERT INTO INT2_TBL(f1) VALUES ('asdf'); INSERT INTO INT2_TBL(f1) VALUES ('asdf');
ERROR: pg_atoi: error in "asdf": can't parse "asdf" ERROR: invalid input syntax for integer: "asdf"
SELECT '' AS five, INT2_TBL.*; SELECT '' AS five, INT2_TBL.*;
five | f1 five | f1
------+-------- ------+--------
......
...@@ -8,15 +8,15 @@ INSERT INTO INT4_TBL(f1) VALUES ('0'); ...@@ -8,15 +8,15 @@ INSERT INTO INT4_TBL(f1) VALUES ('0');
INSERT INTO INT4_TBL(f1) VALUES ('123456'); INSERT INTO INT4_TBL(f1) VALUES ('123456');
INSERT INTO INT4_TBL(f1) VALUES ('-123456'); INSERT INTO INT4_TBL(f1) VALUES ('-123456');
INSERT INTO INT4_TBL(f1) VALUES ('34.5'); INSERT INTO INT4_TBL(f1) VALUES ('34.5');
ERROR: pg_atoi: error in "34.5": can't parse ".5" ERROR: invalid input syntax for integer: "34.5"
-- largest and smallest values -- largest and smallest values
INSERT INTO INT4_TBL(f1) VALUES ('2147483647'); INSERT INTO INT4_TBL(f1) VALUES ('2147483647');
INSERT INTO INT4_TBL(f1) VALUES ('-2147483647'); INSERT INTO INT4_TBL(f1) VALUES ('-2147483647');
-- bad input values -- should give warnings -- bad input values -- should give warnings
INSERT INTO INT4_TBL(f1) VALUES ('1000000000000'); INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
ERROR: pg_atoi: error reading "1000000000000": Numerical result out of range ERROR: 1000000000000 is out of range for int4
INSERT INTO INT4_TBL(f1) VALUES ('asdf'); INSERT INTO INT4_TBL(f1) VALUES ('asdf');
ERROR: pg_atoi: error in "asdf": can't parse "asdf" ERROR: invalid input syntax for integer: "asdf"
SELECT '' AS five, INT4_TBL.*; SELECT '' AS five, INT4_TBL.*;
five | f1 five | f1
------+------------- ------+-------------
......
...@@ -58,9 +58,9 @@ INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months'); ...@@ -58,9 +58,9 @@ INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months');
INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours'); INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
-- badly formatted interval -- badly formatted interval
INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval'); INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
ERROR: Bad interval external representation 'badly formatted interval' ERROR: invalid input syntax for interval: "badly formatted interval"
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
ERROR: Bad interval external representation '@ 30 eons ago' ERROR: invalid input syntax for interval: "@ 30 eons ago"
-- test interval operators -- test interval operators
SELECT '' AS ten, INTERVAL_TBL.*; SELECT '' AS ten, INTERVAL_TBL.*;
ten | f1 ten | f1
......
...@@ -11,13 +11,13 @@ INSERT INTO LSEG_TBL VALUES ('[-1e6,2e2,3e5, -4e1]'); ...@@ -11,13 +11,13 @@ INSERT INTO LSEG_TBL VALUES ('[-1e6,2e2,3e5, -4e1]');
INSERT INTO LSEG_TBL VALUES ('(11,22,33,44)'); INSERT INTO LSEG_TBL VALUES ('(11,22,33,44)');
-- bad values for parser testing -- bad values for parser testing
INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)'); INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)');
ERROR: Bad lseg external representation '(3asdf,2 ,3,4r2)' ERROR: invalid input syntax for lseg: "(3asdf,2 ,3,4r2)"
INSERT INTO LSEG_TBL VALUES ('[1,2,3, 4'); INSERT INTO LSEG_TBL VALUES ('[1,2,3, 4');
ERROR: Bad lseg external representation '[1,2,3, 4' ERROR: invalid input syntax for lseg: "[1,2,3, 4"
INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]'); INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]');
ERROR: Bad lseg external representation '[(,2),(3,4)]' ERROR: invalid input syntax for lseg: "[(,2),(3,4)]"
INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)'); INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)');
ERROR: Bad lseg external representation '[(1,2),(3,4)' ERROR: invalid input syntax for lseg: "[(1,2),(3,4)"
select * from LSEG_TBL; select * from LSEG_TBL;
s s
------------------------------- -------------------------------
......
...@@ -675,11 +675,13 @@ CREATE TABLE fract_only (id int, val numeric(4,4)); ...@@ -675,11 +675,13 @@ CREATE TABLE fract_only (id int, val numeric(4,4));
INSERT INTO fract_only VALUES (1, '0.0'); INSERT INTO fract_only VALUES (1, '0.0');
INSERT INTO fract_only VALUES (2, '0.1'); INSERT INTO fract_only VALUES (2, '0.1');
INSERT INTO fract_only VALUES (3, '1.0'); -- should fail INSERT INTO fract_only VALUES (3, '1.0'); -- should fail
ERROR: overflow on numeric ABS(value) >= 10^0 for field with precision 4 scale 4 ERROR: numeric field overflow
DETAIL: ABS(value) >= 10^0 for field with precision 4, scale 4.
INSERT INTO fract_only VALUES (4, '-0.9999'); INSERT INTO fract_only VALUES (4, '-0.9999');
INSERT INTO fract_only VALUES (5, '0.99994'); INSERT INTO fract_only VALUES (5, '0.99994');
INSERT INTO fract_only VALUES (6, '0.99995'); -- should fail INSERT INTO fract_only VALUES (6, '0.99995'); -- should fail
ERROR: overflow on numeric ABS(value) >= 10^0 for field with precision 4 scale 4 ERROR: numeric field overflow
DETAIL: ABS(value) >= 10^0 for field with precision 4, scale 4.
INSERT INTO fract_only VALUES (7, '0.00001'); INSERT INTO fract_only VALUES (7, '0.00001');
INSERT INTO fract_only VALUES (8, '0.00017'); INSERT INTO fract_only VALUES (8, '0.00017');
SELECT * FROM fract_only; SELECT * FROM fract_only;
......
...@@ -10,9 +10,9 @@ INSERT INTO OID_TBL(f1) VALUES ('99999999'); ...@@ -10,9 +10,9 @@ INSERT INTO OID_TBL(f1) VALUES ('99999999');
INSERT INTO OID_TBL(f1) VALUES (''); INSERT INTO OID_TBL(f1) VALUES ('');
-- bad inputs -- bad inputs
INSERT INTO OID_TBL(f1) VALUES ('asdfasd'); INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
ERROR: oidin: error in "asdfasd": can't parse "asdfasd" ERROR: invalid input syntax for OID: "asdfasd"
INSERT INTO OID_TBL(f1) VALUES ('99asdfasd'); INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
ERROR: oidin: error in "99asdfasd": can't parse "asdfasd" ERROR: invalid input syntax for OID: "99asdfasd"
SELECT '' AS six, OID_TBL.*; SELECT '' AS six, OID_TBL.*;
six | f1 six | f1
-----+------------ -----+------------
......
...@@ -13,9 +13,9 @@ INSERT INTO PATH_TBL VALUES ('[11,12,13,14]'); ...@@ -13,9 +13,9 @@ INSERT INTO PATH_TBL VALUES ('[11,12,13,14]');
INSERT INTO PATH_TBL VALUES ('(11,12,13,14)'); INSERT INTO PATH_TBL VALUES ('(11,12,13,14)');
-- bad values for parser testing -- bad values for parser testing
INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]'); INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]');
ERROR: Bad path external representation '[(,2),(3,4)]' ERROR: invalid input syntax for path: "[(,2),(3,4)]"
INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)'); INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)');
ERROR: Bad path external representation '[(1,2),(3,4)' ERROR: invalid input syntax for path: "[(1,2),(3,4)"
SELECT f1 FROM PATH_TBL; SELECT f1 FROM PATH_TBL;
f1 f1
--------------------------- ---------------------------
......
...@@ -9,12 +9,12 @@ INSERT INTO POINT_TBL(f1) VALUES ('(5.1, 34.5)'); ...@@ -9,12 +9,12 @@ INSERT INTO POINT_TBL(f1) VALUES ('(5.1, 34.5)');
INSERT INTO POINT_TBL(f1) VALUES ('(-5.0,-12.0)'); INSERT INTO POINT_TBL(f1) VALUES ('(-5.0,-12.0)');
-- bad format points -- bad format points
INSERT INTO POINT_TBL(f1) VALUES ('asdfasdf'); INSERT INTO POINT_TBL(f1) VALUES ('asdfasdf');
ERROR: Bad point external representation 'asdfasdf' ERROR: invalid input syntax for point: "asdfasdf"
INSERT INTO POINT_TBL(f1) VALUES ('10.0,10.0'); INSERT INTO POINT_TBL(f1) VALUES ('10.0,10.0');
INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)'); INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
ERROR: Bad point external representation '(10.0 10.0)' ERROR: invalid input syntax for point: "(10.0 10.0)"
INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0'); INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
ERROR: Bad point external representation '(10.0,10.0' ERROR: invalid input syntax for point: "(10.0,10.0"
SELECT '' AS six, POINT_TBL.*; SELECT '' AS six, POINT_TBL.*;
six | f1 six | f1
-----+------------ -----+------------
......
...@@ -21,15 +21,15 @@ INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,0.0)'); ...@@ -21,15 +21,15 @@ INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,1.0),(0.0,1.0)'); INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,1.0),(0.0,1.0)');
-- bad polygon input strings -- bad polygon input strings
INSERT INTO POLYGON_TBL(f1) VALUES ('0.0'); INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
ERROR: Bad polygon external representation '0.0' ERROR: invalid input syntax for polygon: "0.0"
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0'); INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
ERROR: Bad polygon external representation '(0.0 0.0' ERROR: invalid input syntax for polygon: "(0.0 0.0"
INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)'); INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
ERROR: Bad polygon external representation '(0,1,2)' ERROR: invalid input syntax for polygon: "(0,1,2)"
INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3'); INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
ERROR: Bad polygon external representation '(0,1,2,3' ERROR: invalid input syntax for polygon: "(0,1,2,3"
INSERT INTO POLYGON_TBL(f1) VALUES ('asdf'); INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
ERROR: Bad polygon external representation 'asdf' ERROR: invalid input syntax for polygon: "asdf"
SELECT '' AS four, POLYGON_TBL.*; SELECT '' AS four, POLYGON_TBL.*;
four | f1 four | f1
------+--------------------- ------+---------------------
......
...@@ -286,7 +286,7 @@ ERROR: relation "pg_shad" does not exist ...@@ -286,7 +286,7 @@ ERROR: relation "pg_shad" does not exist
select has_table_privilege('nosuchuser','pg_shadow','select'); select has_table_privilege('nosuchuser','pg_shadow','select');
ERROR: user "nosuchuser" does not exist ERROR: user "nosuchuser" does not exist
select has_table_privilege('pg_shadow','sel'); select has_table_privilege('pg_shadow','sel');
ERROR: has_table_privilege: invalid privilege type sel ERROR: unrecognized privilege type: "sel"
select has_table_privilege(-999999,'pg_shadow','update'); select has_table_privilege(-999999,'pg_shadow','update');
ERROR: user with ID 4293967297 does not exist ERROR: user with ID 4293967297 does not exist
select has_table_privilege(1,'rule'); select has_table_privilege(1,'rule');
...@@ -561,7 +561,8 @@ SELECT has_table_privilege('regressuser3', 'atest4', 'SELECT'); -- true ...@@ -561,7 +561,8 @@ SELECT has_table_privilege('regressuser3', 'atest4', 'SELECT'); -- true
(1 row) (1 row)
REVOKE SELECT ON atest4 FROM regressuser2; -- fail REVOKE SELECT ON atest4 FROM regressuser2; -- fail
ERROR: dependent privileges exist (use CASCADE to revoke them too) ERROR: dependent privileges exist
HINT: Use CASCADE to revoke them too.
REVOKE GRANT OPTION FOR SELECT ON atest4 FROM regressuser2 CASCADE; -- ok REVOKE GRANT OPTION FOR SELECT ON atest4 FROM regressuser2 CASCADE; -- ok
SELECT has_table_privilege('regressuser2', 'atest4', 'SELECT'); -- true SELECT has_table_privilege('regressuser2', 'atest4', 'SELECT'); -- true
has_table_privilege has_table_privilege
......
...@@ -10,9 +10,9 @@ INSERT INTO RELTIME_TBL (f1) VALUES ('@ 3 months'); ...@@ -10,9 +10,9 @@ INSERT INTO RELTIME_TBL (f1) VALUES ('@ 3 months');
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 14 seconds ago'); INSERT INTO RELTIME_TBL (f1) VALUES ('@ 14 seconds ago');
-- badly formatted reltimes -- badly formatted reltimes
INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltime'); INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltime');
ERROR: Bad reltime external representation 'badly formatted reltime' ERROR: invalid input syntax for reltime: "badly formatted reltime"
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago'); INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago');
ERROR: Bad reltime external representation '@ 30 eons ago' ERROR: invalid input syntax for reltime: "@ 30 eons ago"
-- test reltime operators -- test reltime operators
SELECT '' AS six, RELTIME_TBL.*; SELECT '' AS six, RELTIME_TBL.*;
six | f1 six | f1
......
...@@ -737,7 +737,7 @@ SELECT replace('yabadoo', 'bad', '') AS "yaoo"; ...@@ -737,7 +737,7 @@ SELECT replace('yabadoo', 'bad', '') AS "yaoo";
-- test split_part -- test split_part
-- --
select split_part('joeuser@mydatabase','@',0) AS "an error"; select split_part('joeuser@mydatabase','@',0) AS "an error";
ERROR: field position must be > 0 ERROR: field position must be greater than zero
select split_part('joeuser@mydatabase','@',1) AS "joeuser"; select split_part('joeuser@mydatabase','@',1) AS "joeuser";
joeuser joeuser
--------- ---------
......
...@@ -11,7 +11,7 @@ CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) without time zone); ...@@ -11,7 +11,7 @@ CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) without time zone);
-- statements. -- statements.
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
INSERT INTO TIMESTAMP_TBL VALUES ('current'); INSERT INTO TIMESTAMP_TBL VALUES ('current');
ERROR: 'CURRENT' is no longer supported ERROR: "current" is no longer supported
INSERT INTO TIMESTAMP_TBL VALUES ('today'); INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
...@@ -60,13 +60,13 @@ INSERT INTO TIMESTAMP_TBL VALUES ('infinity'); ...@@ -60,13 +60,13 @@ INSERT INTO TIMESTAMP_TBL VALUES ('infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('epoch'); INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Obsolete special values -- Obsolete special values
INSERT INTO TIMESTAMP_TBL VALUES ('invalid'); INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
ERROR: TIMESTAMP 'invalid' no longer supported ERROR: "invalid" is no longer supported
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime'); INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime');
ERROR: TIMESTAMP 'Invalid Abstime' no longer supported ERROR: "Invalid Abstime" is no longer supported
INSERT INTO TIMESTAMP_TBL VALUES ('Undefined Abstime'); INSERT INTO TIMESTAMP_TBL VALUES ('Undefined Abstime');
ERROR: TIMESTAMP 'Undefined Abstime' no longer supported ERROR: "Undefined Abstime" is no longer supported
-- Variations on Postgres v6.1 standard output format -- Variations on Postgres v6.1 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');
...@@ -126,7 +126,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1996'); ...@@ -126,7 +126,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
ERROR: Bad timestamp external representation 'Feb 29 17:32:01 1997' ERROR: invalid input syntax for timestamp: "Feb 29 17:32:01 1997"
INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997');
...@@ -136,9 +136,9 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 2000'); ...@@ -136,9 +136,9 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 2000');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001'); INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges -- Currently unsupported syntax and ranges
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
ERROR: Bad timestamp external representation 'Feb 16 17:32:01 -0097' ERROR: invalid input syntax for timestamp: "Feb 16 17:32:01 -0097"
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');
ERROR: TIMESTAMP out of range 'Feb 16 17:32:01 5097 BC' ERROR: timestamp out of range: "Feb 16 17:32:01 5097 BC"
SELECT '' AS "64", d1 FROM TIMESTAMP_TBL; SELECT '' AS "64", d1 FROM TIMESTAMP_TBL;
64 | d1 64 | d1
----+----------------------------- ----+-----------------------------
...@@ -1370,7 +1370,7 @@ SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDF ...@@ -1370,7 +1370,7 @@ SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDF
(1 row) (1 row)
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD'); SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
ERROR: to_timestamp(): bad value for MON/Mon/mon ERROR: invalid value for MON/Mon/mon
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD'); SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
to_timestamp_10 | to_timestamp to_timestamp_10 | to_timestamp
-----------------+------------------------------ -----------------+------------------------------
......
...@@ -6,7 +6,7 @@ SET australian_timezones = 'off'; ...@@ -6,7 +6,7 @@ SET australian_timezones = 'off';
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone); CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone);
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
ERROR: 'CURRENT' is no longer supported ERROR: "current" is no longer supported
INSERT INTO TIMESTAMPTZ_TBL VALUES ('today'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('today');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow');
...@@ -55,13 +55,13 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('infinity'); ...@@ -55,13 +55,13 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('infinity');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch');
-- Obsolete special values -- Obsolete special values
INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid');
ERROR: TIMESTAMP WITH TIME ZONE 'invalid' no longer supported ERROR: "invalid" is no longer supported
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Invalid Abstime'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Invalid Abstime');
ERROR: TIMESTAMP WITH TIME ZONE 'Invalid Abstime' no longer supported ERROR: "Invalid Abstime" is no longer supported
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Undefined Abstime'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Undefined Abstime');
ERROR: TIMESTAMP WITH TIME ZONE 'Undefined Abstime' no longer supported ERROR: "Undefined Abstime" is no longer supported
-- Variations on Postgres v6.1 standard output format -- Variations on Postgres v6.1 standard output format
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');
...@@ -121,7 +121,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 1996'); ...@@ -121,7 +121,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 1996');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 1997'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 1997');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 28 17:32:01 1997'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 28 17:32:01 1997');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 29 17:32:01 1997'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 29 17:32:01 1997');
ERROR: Bad timestamp external representation 'Feb 29 17:32:01 1997' ERROR: invalid input syntax for timestamp with time zone: "Feb 29 17:32:01 1997"
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mar 01 17:32:01 1997'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mar 01 17:32:01 1997');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 30 17:32:01 1997'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 30 17:32:01 1997');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 1997'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 1997');
...@@ -131,9 +131,9 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 2000'); ...@@ -131,9 +131,9 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 2000');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 2001'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges -- Currently unsupported syntax and ranges
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097');
ERROR: Bad timestamp external representation 'Feb 16 17:32:01 -0097' ERROR: invalid input syntax for timestamp with time zone: "Feb 16 17:32:01 -0097"
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC');
ERROR: TIMESTAMP WITH TIME ZONE out of range 'Feb 16 17:32:01 5097 BC' ERROR: timestamp out of range: "Feb 16 17:32:01 5097 BC"
SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL; SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL;
64 | d1 64 | d1
----+--------------------------------- ----+---------------------------------
...@@ -1369,7 +1369,7 @@ SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDF ...@@ -1369,7 +1369,7 @@ SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDF
(1 row) (1 row)
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD'); SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
ERROR: to_timestamp(): bad value for MON/Mon/mon ERROR: invalid value for MON/Mon/mon
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD'); SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
to_timestamp_10 | to_timestamp to_timestamp_10 | to_timestamp
-----------------+------------------------------ -----------------+------------------------------
......
...@@ -17,10 +17,10 @@ INSERT INTO TINTERVAL_TBL (f1) ...@@ -17,10 +17,10 @@ INSERT INTO TINTERVAL_TBL (f1)
-- badly formatted tintervals -- badly formatted tintervals
INSERT INTO TINTERVAL_TBL (f1) INSERT INTO TINTERVAL_TBL (f1)
VALUES ('["bad time specifications" ""]'); VALUES ('["bad time specifications" ""]');
ERROR: Bad abstime external representation 'bad time specifications' ERROR: invalid input syntax for abstime: "bad time specifications"
INSERT INTO TINTERVAL_TBL (f1) INSERT INTO TINTERVAL_TBL (f1)
VALUES ('["" "infinity"]'); VALUES ('["" "infinity"]');
ERROR: Bad abstime external representation '' ERROR: invalid input syntax for abstime: ""
-- test tinterval operators -- test tinterval operators
SELECT '' AS five, TINTERVAL_TBL.*; SELECT '' AS five, TINTERVAL_TBL.*;
five | f1 five | f1
......
...@@ -17,10 +17,10 @@ INSERT INTO TINTERVAL_TBL (f1) ...@@ -17,10 +17,10 @@ INSERT INTO TINTERVAL_TBL (f1)
-- badly formatted tintervals -- badly formatted tintervals
INSERT INTO TINTERVAL_TBL (f1) INSERT INTO TINTERVAL_TBL (f1)
VALUES ('["bad time specifications" ""]'); VALUES ('["bad time specifications" ""]');
ERROR: Bad abstime external representation 'bad time specifications' ERROR: invalid input syntax for abstime: "bad time specifications"
INSERT INTO TINTERVAL_TBL (f1) INSERT INTO TINTERVAL_TBL (f1)
VALUES ('["" "infinity"]'); VALUES ('["" "infinity"]');
ERROR: Bad abstime external representation '' ERROR: invalid input syntax for abstime: ""
-- test tinterval operators -- test tinterval operators
SELECT '' AS five, TINTERVAL_TBL.*; SELECT '' AS five, TINTERVAL_TBL.*;
five | f1 five | f1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment