the bulk of the heavy lifting ...
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
else
{
if (len >= NAMEDATALEN-1)
- elog(ERROR, "identifier must be less than %d characters",
- NAMEDATALEN);
+ ereport(ERROR,
+ (errcode(ERRCODE_NAME_TOO_LONG),
+ errmsg("identifier too long"),
+ errdetail("Identifier must be less than %d characters.",
+ NAMEDATALEN)));
+
n[len++] = *s;
}
}
Assert(s && aip);
#ifdef ACLDEBUG
- elog(LOG, "aclparse: input = '%s'", s);
+ elog(LOG, "aclparse: input = \"%s\"", s);
#endif
idtype = ACL_IDTYPE_UID;
s = getid(s, name);
if (*s != '=')
{
/* 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;
- else if (strncmp(name, ACL_IDTYPE_UID_KEYWORD, sizeof(name)) != 0)
- elog(ERROR, "aclparse: bad keyword, must be [group|user]");
+ else if (strcmp(name, ACL_IDTYPE_UID_KEYWORD) != 0)
+ 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 */
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')
idtype = ACL_IDTYPE_WORLD;
if (*s != '=')
- elog(ERROR, "aclparse: expecting \"=\" sign");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("missing \"=\" sign")));
privs = goption = ACL_NO_RIGHTS;
read = ACL_CREATE_TEMP;
break;
default:
- elog(ERROR, "aclparse: mode flags must use \"%s\"",
- ACL_ALL_RIGHTS_STR);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid mode character: must be one of \"%s\"",
+ ACL_ALL_RIGHTS_STR)));
}
privs |= read;
{
s = getid(s + 1, name2);
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);
}
else
{
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);
Size size;
if (n < 0)
- elog(ERROR, "allocacl: invalid size: %d", n);
+ elog(ERROR, "invalid size: %d", n);
size = ACL_N_SIZE(n);
new_acl = (Acl *) palloc0(size);
new_acl->size = size;
while (isspace((unsigned char) *s))
++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);
}
case ACL_IDTYPE_WORLD:
break;
default:
- elog(ERROR, "aclitemout: bad idtype: %d",
- ACLITEM_GET_IDTYPE(*aip));
+ elog(ERROR, "unrecognized idtype: %d",
+ (int) ACLITEM_GET_IDTYPE(*aip));
break;
}
while (*p)
owner_default = ACL_ALL_RIGHTS_NAMESPACE;
break;
default:
- elog(ERROR, "acldefault: bogus objtype %d", (int) objtype);
+ elog(ERROR, "unrecognized objtype: %d", (int) objtype);
world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
owner_default = ACL_NO_RIGHTS;
break;
AclItem mod_acl;
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_grantee = aip[i].ai_grantee;
new_aip = ACL_DAT(new_acl);
if (dst == 0)
{ /* 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)
{ /* end */
}
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)
{
if (strcasecmp(priv_type, "TEMPORARY") == 0)
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 */
}
if (strcasecmp(priv_type, "TRIGGER WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_TRIGGER);
- elog(ERROR, "has_table_privilege: 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 */
}
oid = get_database_oid(dbname);
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;
}
if (strcasecmp(priv_type, "TEMP WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP);
- elog(ERROR, "has_database_privilege: 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 */
}
CStringGetDatum(funcname)));
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;
}
if (strcasecmp(priv_type, "EXECUTE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_EXECUTE);
- elog(ERROR, "has_function_privilege: 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 */
}
CStringGetDatum(langname),
0, 0, 0);
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;
}
if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE);
- elog(ERROR, "has_language_privilege: 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 */
}
CStringGetDatum(nspname),
0, 0, 0);
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;
}
if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE);
- elog(ERROR, "has_schema_privilege: 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 */
}
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "utils/array.h"
+#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
ArrayMetaState *my_extra;
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);
arg1_elemid = get_element_type(arg1_typeid);
else
{
/* 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 */
}
else if (ARR_NDIM(v) == 0)
indx = 1;
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
/* the rest fall into combo 2, 3, or 4 */
if (ndims1 != ndims2 && ndims1 != ndims2 - 1 && ndims1 != ndims2 + 1)
- elog(ERROR, "Cannot concatenate incompatible arrays of %d and "
- "%d dimensions", ndims1, ndims2);
+ ereport(ERROR,
+ (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_type2 = ARR_ELEMTYPE(v2);
/* Do we have a matching element types */
if (element_type1 != element_type2)
- elog(ERROR, "Cannot concatenate incompatible arrays with element "
- "type %u and %u", element_type1, element_type2);
+ ereport(ERROR,
+ (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 */
element_type = element_type1;
for (i = 0; i < ndims1; 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];
lbs[i + 1] = lbs1[i];
for (i = 0; i < ndims1; i++)
{
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) */
for (i = 0; i < ndims2; i++)
{
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.")));
}
}
ArrayMetaState *my_extra;
if (element_type == 0)
- elog(ERROR, "Invalid array element type: %u", element_type);
- if (ndims < 1 || ndims > MAXDIM)
- elog(ERROR, "Invalid number of dimensions %d", ndims);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ 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;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
break; /* no more dimension items */
p++;
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++);
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 == ':')
{
/* [m:n] format */
p = q + 1;
for (q = p; isdigit((unsigned char) *q); q++);
if (q == p) /* no digits? */
- elog(ERROR, "array_in: missing dimension value");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("missing dimension value")));
}
else
{
lBound[ndim] = 1;
}
if (*q != ']')
- elog(ERROR, "array_in: missing ']' in array declaration");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("missing \"]\" in array dimensions")));
+
*q = '\0';
ub = atoi(p);
p = q + 1;
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;
ndim++;
}
{
/* No array dimensions, so intuit dimensions from brace structure */
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);
for (i = 0; i < ndim; i++)
lBound[i] = 1;
{
/* If array dimensions are given, expect '=' operator */
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);
while (isspace((unsigned char) *p))
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,
typmod, typdelim, typlen, typbyval, typalign,
{
case '\0':
/* 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;
case '\\':
/* skip the escaped character */
if (*(ptr + 1))
ptr++;
else
- elog(ERROR, "malformed array constant: %s", str);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("malformed array literal: \"%s\"", str)));
break;
case '\"':
scanning_string = !scanning_string;
if (!scanning_string)
{
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;
nest_level++;
if (ndim < nest_level)
if (!scanning_string)
{
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--;
if (nest_level == 0)
eoArray = itemdone = true;
{
case '\0':
/* 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;
case '\\':
{
for (cptr = ptr; *cptr != '\0'; cptr++)
*cptr = *(cptr + 1);
if (*ptr == '\0')
- elog(ERROR, "malformed array constant: %s", arrayStr);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("malformed array literal: \"%s\"", arrayStr)));
break;
}
case '\"':
if (!scanning_string)
{
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++;
indx[nest_level - 1] = 0;
/* skip leading whitespace */
if (!scanning_string)
{
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)
i = ArrayGetOffset0(ndim, indx, prod);
indx[nest_level - 1] = 0;
}
*ptr++ = '\0';
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,
CStringGetDatum(itemstart),
ObjectIdGetDatum(typelem),
/* Get the array header information */
ndim = pq_getmsgint(buf, 4);
- if (ndim < 0 || ndim > MAXDIM)
- elog(ERROR, "array_recv: invalid number of dimensions");
+ if (ndim < 0) /* we do allow zero-dimension arrays */
+ 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);
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));
if (element_type != spec_element_type)
{
/* 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++)
&my_extra->typalign, &my_extra->typdelim,
&my_extra->typelem, &my_extra->typiofunc);
if (!OidIsValid(my_extra->typiofunc))
- elog(ERROR, "No binary input function available for type %s",
- format_type_be(element_type));
+ ereport(ERROR,
+ (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,
fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type;
/* Get and check the item length */
itemlen = pq_getmsgint(buf, 4);
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
/* Trouble if it didn't eat the whole buffer */
if (elem_buf.cursor != itemlen)
- elog(ERROR, "Improper binary format in array element %d",
- i + 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("improper binary format in array element %d",
+ i + 1)));
buf->data[buf->cursor] = csave;
}
&my_extra->typalign, &my_extra->typdelim,
&my_extra->typelem, &my_extra->typiofunc);
if (!OidIsValid(my_extra->typiofunc))
- elog(ERROR, "No binary output function available for type %s",
- format_type_be(element_type));
+ ereport(ERROR,
+ (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,
fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type;
* Code below shows how we could support it if the parser were
* 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
* cannot extend them, either.
*/
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)
- elog(ERROR, "Invalid array subscripts");
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("invalid array subscripts")));
+
newarray = (ArrayType *) palloc(arraylen);
memcpy(newarray, array, arraylen);
elt_ptr = (char *) newarray + indx[0] * elmlen;
}
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 */
memcpy(dim, ARR_DIMS(array), ndim * sizeof(int));
extendbefore = true;
}
else
- elog(ERROR, "Invalid array subscripts");
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("invalid array subscripts")));
}
if (indx[i] >= (dim[i] + lb[i]))
{
extendafter = true;
}
else
- elog(ERROR, "Invalid array subscripts");
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("invalid array subscripts")));
}
}
/*
* 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 */
}
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 */
memcpy(dim, ARR_DIMS(array), ndim * sizeof(int));
for (i = 0; i < nSubscripts; 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 (ndim == 1 && upperIndx[i] >= lb[i] - 1)
lb[i] = lowerIndx[i];
}
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 (ndim == 1 && lowerIndx[i] <= (dim[i] + lb[i]))
dim[i] = upperIndx[i] - lb[i] + 1;
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 */
lowerIndx[i] = lb[i];
upperIndx[i] = dim[i] + lb[i] - 1;
if (lowerIndx[i] > upperIndx[i])
- elog(ERROR, "Invalid array subscripts");
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("invalid array subscripts")));
}
/*
mda_get_range(ndim, span, lowerIndx, upperIndx);
nsrcitems = ArrayGetNItems(ndim, span);
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
/* Get input array */
if (fcinfo->nargs < 1)
- elog(ERROR, "array_map: invalid nargs: %d", fcinfo->nargs);
+ elog(ERROR, "invalid nargs: %d", fcinfo->nargs);
if (PG_ARGISNULL(0))
- elog(ERROR, "array_map: null input array");
+ elog(ERROR, "null input array");
v = PG_GETARG_ARRAYTYPE_P(0);
Assert(ARR_ELEMTYPE(v) == inpType);
fcinfo->isnull = false;
values[i] = FunctionCallInvoke(fcinfo);
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 */
if (typlen == -1)
int i;
int nelems;
- if (ndims < 1 || ndims > MAXDIM)
- elog(ERROR, "Number of array dimensions, %d, exceeds the maximum allowed (%d)",
- ndims, MAXDIM);
+ if (ndims < 0) /* we do allow zero-dimension arrays */
+ 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)));
+
+ /* 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);
FunctionCallInfoData locfcinfo;
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 */
if (nitems1 != nitems2)
element_type = ARR_ELEMTYPE(array1);
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
Oid funcId;
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);
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.
* check to the coercion.
*/
if (getBaseType(tgt_elem_type) != tgt_elem_type)
- elog(ERROR, "array coercion to domain type elements not " \
- "currently supported");
+ ereport(ERROR,
+ (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,
COERCION_EXPLICIT, &funcId))
}
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 */
astate->dvalues[astate->nelems++] =
* Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group
*
* 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 $
*
*-----------------------------------------------------------------------
*/
}
else
{
- elog(ERROR, "unsupported encoding conversion from %s to ASCII",
- pg_encoding_to_char(enc));
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unsupported encoding conversion from %s to ASCII",
+ pg_encoding_to_char(enc))));
return; /* keep compiler quiet */
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 */
PG_RETURN_BOOL(false);
* workings can be found in the book "Software Solutions in C" by
* 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"
s++;
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);
if (minus)
{
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 */
if (convention == 0)
else
{
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);
}
Cash result;
if (f == 0.0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = rint(c / f);
PG_RETURN_CASH(result);
Cash result;
if (f == 0.0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = rint(c / f);
PG_RETURN_CASH(result);
Cash result;
if (i == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = rint(c / i);
Cash result;
if (s == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = rint(c / s);
PG_RETURN_CASH(result);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
char arg2 = PG_GETARG_CHAR(1);
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);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
char lowstr[MAXDATELEN + 1];
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)
|| (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)
{
break;
case DTK_CURRENT:
- elog(ERROR, "Date CURRENT no longer supported"
- "\n\tdate_in() internal coding error");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("\"current\" is no longer supported")));
+
GetCurrentDateTime(tm);
break;
break;
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;
PG_RETURN_NULL();
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;
PG_RETURN_NULL();
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;
case INVALID_ABSTIME:
case NOSTART_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
dstr[MAXDATELEN + 1];
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);
dp = dstr;
int ftype[MAXDATEFIELDS];
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)
|| (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);
AdjustTimeForTypmod(&result, typmod);
PG_RETURN_NULL();
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
PG_RETURN_NULL();
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
dstr[MAXDATELEN + 1];
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);
dp = dstr;
lowunits[MAXDATELEN + 1];
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "TIME units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("TIME units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
+
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
case DTK_CENTURY:
case DTK_MILLENNIUM:
default:
- elog(ERROR, "TIME units '%s' not supported",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("TIME units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
+
result = 0;
}
}
}
else
{
- elog(ERROR, "TIME units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("TIME units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
result = 0;
}
int ftype[MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr))
- elog(ERROR, "Bad time with time zone"
- " external representation (too long) '%s'", str);
+ ereport(ERROR,
+ (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)
|| (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));
tm2timetz(tm, fsec, tz, result);
PG_RETURN_NULL();
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));
dstr[MAXDATELEN + 1];
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);
dp = dstr;
lowunits[MAXDATELEN + 1];
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "TIMETZ units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("TIMETZ units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
+
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
case DTK_CENTURY:
case DTK_MILLENNIUM:
default:
- elog(ERROR, "TIMETZ units '%s' not supported",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("TIMETZ units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
+
result = 0;
}
}
}
else
{
- elog(ERROR, "TIMETZ units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("TIMETZ units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
+
result = 0;
}
lowzone[MAXDATELEN + 1];
if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "Time zone '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(zone))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("time zone \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(zone))))));
+
up = VARDATA(zone);
lp = lowzone;
for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
}
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();
}
int tz;
if (zone->month != 0)
- elog(ERROR, "INTERVAL time zone '%s' not legal (month specified)",
- DatumGetCString(DirectFunctionCall1(interval_out,
- PointerGetDatum(zone))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("INTERVAL time zone \"%s\" not legal",
+ DatumGetCString(DirectFunctionCall1(interval_out,
+ PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
tz = -(zone->time / INT64CONST(1000000));
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
switch (val)
{
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;
break;
if (tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1);
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)
{
switch (val)
{
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;
break;
if (tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1);
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)
{
*
* 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
* use +1300 summer time.
*
* 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
DecodePosixTimezone(char *str, int *tzp)
* Implement a cache lookup since it is likely that dates
* will be related in format.
*
- * NB: this must *not* elog on failure;
+ * NB: this must *not* ereport on failure;
* see commands/variable.c.
*/
int
{
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,
TOKMAXLEN, base[i-1].token,
TOKMAXLEN, base[i].token);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
struct varlena *s = (struct varlena *) DatumGetPointer(value);
if (!PointerIsValid(s))
- elog(ERROR, "datumGetSize: Invalid Datum Pointer");
+ ereport(ERROR,
+ (errcode(ERRCODE_DATA_EXCEPTION),
+ errmsg("invalid Datum pointer")));
+
size = (Size) VARATT_SIZE(s);
}
else if (typLen == -2)
char *s = (char *) DatumGetPointer(value);
if (!PointerIsValid(s))
- elog(ERROR, "datumGetSize: Invalid Datum Pointer");
+ ereport(ERROR,
+ (errcode(ERRCODE_DATA_EXCEPTION),
+ errmsg("invalid Datum pointer")));
+
size = (Size) (strlen(s) + 1);
}
else
{
- elog(ERROR, "datumGetSize: Invalid typLen %d", typLen);
+ elog(ERROR, "invalid typLen: %d", typLen);
size = 0; /* keep compiler quiet */
}
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
enc = pg_find_encoding(namebuf);
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);
result = palloc(VARHDRSZ + resultlen);
/* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen)
- elog(FATAL, "Overflow - encode estimate too small");
+ elog(FATAL, "overflow - encode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res;
enc = pg_find_encoding(namebuf);
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);
result = palloc(VARHDRSZ + resultlen);
/* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen)
- elog(FATAL, "Overflow - decode estimate too small");
+ elog(FATAL, "overflow - decode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res;
res = hexlookup[c];
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;
}
}
v1 = get_hex(*s++) << 4;
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++);
*p++ = v1 | v2;
}
else if (pos == 3)
end = 2;
else
- elog(ERROR, "base64: unexpected '='");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unexpected \"=\"")));
}
b = 0;
}
if (c > 0 && c < 127)
b = b64lookup[c];
if (b < 0)
- elog(ERROR, "base64: Invalid symbol");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid symbol")));
}
/* add it to buffer */
buf = (buf << 6) + b;
}
if (pos != 0)
- elog(ERROR, "base64: invalid end sequence");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid end sequence")));
return p - dst;
}
* One backslash, not followed by ### valid octal. Should
* 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++;
/*
* 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++;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* check to see if a float4 val is outside of
* the FLOAT4_MIN, FLOAT4_MAX bounds.
*
- * raise an elog warning if it is
+ * raise an ereport warning if it is
*/
static void
CheckFloat4Val(double val)
return;
#else
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)
- elog(ERROR, "Bad float4 input format -- underflow");
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("float4 value out of range: underflow")));
+
return;
#endif /* UNSAFE_FLOATS */
}
* check to see if a float8 val is outside of
* the FLOAT8_MIN, FLOAT8_MAX bounds.
*
- * raise an elog error if it is
+ * raise an ereport error if it is
*/
static void
CheckFloat8Val(double val)
return;
#else
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)
- 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 */
}
if (strcasecmp(num, "NaN") == 0)
val = NAN;
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
{
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)));
}
/*
else if (strcasecmp(num, "-Infinity") == 0)
val = -HUGE_VAL;
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
{
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);
double result;
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 */
result = (float8) arg1 / (float8) arg2;
float8 result;
if (arg2 == 0.0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = arg1 / arg2;
int32 result;
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);
PG_RETURN_INT32(result);
int16 result;
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);
PG_RETURN_INT16(result);
int32 result;
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);
PG_RETURN_INT32(result);
int16 result;
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);
PG_RETURN_INT16(result);
float8 result;
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);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
float8 result;
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)
- 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);
float8 result;
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)
- 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);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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;
CheckFloat8Val(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
|| !finite(result)
#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);
PG_RETURN_FLOAT8(result);
float8 result;
if (arg2 == 0.0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = arg1 / arg2;
CheckFloat8Val(result);
float8 result;
if (arg2 == 0.0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = arg1 / arg2;
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
if (allow_invalid)
return pstrdup("???");
else
- elog(ERROR, "could not locate data type with oid %u in catalog",
- type_oid);
+ elog(ERROR, "cache lookup failed for type %u", type_oid);
}
typeform = (Form_pg_type) GETSTRUCT(tuple);
if (allow_invalid)
return pstrdup("???[]");
else
- elog(ERROR, "could not locate data type with oid %u in catalog",
- type_oid);
+ elog(ERROR, "cache lookup failed for type %u", type_oid);
}
typeform = (Form_pg_type) GETSTRUCT(tuple);
type_oid = array_base_type;
fieldstr = "";
break;
default:
- elog(LOG, "Invalid INTERVAL typmod 0x%x", typemod);
+ elog(ERROR, "invalid INTERVAL typmod: 0x%x", typemod);
fieldstr = "";
break;
}
/* -----------------------------------------------------------------------
* 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
if (IS_BRACKET(num))
{
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_BRACKET(num))
{
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_DECIMAL(num))
{
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))
{
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;
break;
if (IS_LSIGN(num))
{
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))
{
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_LSIGN(num))
{
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;
if (IS_DECIMAL(num))
if (IS_LSIGN(num))
{
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;
if (IS_DECIMAL(num))
if (IS_LSIGN(num))
{
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_PLUS;
if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num))
{
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;
break;
if (IS_DECIMAL(num))
{
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;
break;
case NUM_E:
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;
last = 0;
#ifdef DEBUG_TO_FROM_CHAR
- elog(DEBUG_elog_output, "to_char/number(): run parser.");
+ elog(DEBUG_elog_output, "to_char/number(): run parser");
#endif
n = node;
return;
}
else
- elog(DEBUG_elog_output, "%d:\t UnKnown NODE !!!", a);
+ elog(DEBUG_elog_output, "%d:\t unknown NODE!", a);
}
}
last = *(num + (len - 1));
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
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:
return siz - 1;
}
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;
}
#define CHECK_SEQ_SEARCH(_l, _s) \
do { \
- if (_l <= 0) { \
- elog(ERROR, "to_timestamp(): bad value for %s", _s); \
+ if ((_l) <= 0) { \
+ ereport(ERROR, \
+ (errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
+ errmsg("invalid value for %s", (_s)))); \
} \
} while (0)
DCHCacheEntry *old = DCHCache + 0;
#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
for (ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
{
text *fmt = PG_GETARG_TEXT_P(1),
*res;
TmToChar tmtc;
- int r = 0;
if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt))
PG_RETURN_NULL();
ZERO_tmtc(&tmtc);
- r = timestamp2tm(dt, NULL, tmtcTm(&tmtc), &tmtcFsec(&tmtc), NULL);
-
- if (r != 0)
- elog(ERROR, "to_char(): Unable to convert timestamp to tm");
+ if (timestamp2tm(dt, NULL, tmtcTm(&tmtc), &tmtcFsec(&tmtc), NULL) != 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
if (!(res = datetime_to_char_body(&tmtc, fmt)))
PG_RETURN_NULL();
text *fmt = PG_GETARG_TEXT_P(1),
*res;
TmToChar tmtc;
- int tz,
- r = 0;
+ int tz;
if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt))
PG_RETURN_NULL();
ZERO_tmtc(&tmtc);
- r = timestamp2tm(dt, &tz, tmtcTm(&tmtc), &tmtcFsec(&tmtc), &tmtcTzn(&tmtc));
-
- if (r != 0)
- elog(ERROR, "to_char(): Unable to convert timestamp to tm");
+ if (timestamp2tm(dt, &tz, tmtcTm(&tmtc), &tmtcFsec(&tmtc), &tmtcTzn(&tmtc)) != 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
if (!(res = datetime_to_char_body(&tmtc, fmt)))
PG_RETURN_NULL();
if (tmfc.pm || tmfc.am)
{
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)
tm.tm_hour += 12;
if (tm.tm_year > 0)
tm.tm_year = -(tm.tm_year - 1);
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)
{31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0}};
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)];
tz = DetermineLocalTimeZone(&tm);
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);
}
old = ent;
}
#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
StrNCpy(old->str, str, NUM_CACHE_SIZE + 1);
/* old->format fill parser */
*p = strchr(num, '.');
#ifdef DEBUG_TO_FROM_CHAR
- elog(DEBUG_elog_output, "CALL: get_last_relevant_decnum()");
+ elog(DEBUG_elog_output, "get_last_relevant_decnum()");
#endif
if (!p)
{
#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
/*
int x = strlen(Np->L_negative_sign);
#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
if (!strncmp(Np->inout_p, Np->L_negative_sign, x))
{
}
#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
/*
Np->read_post++;
#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
/*
{
#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
if (*Np->inout_p == '.')
{
int x = strlen(Np->decimal);
#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
if (!strncmp(Np->inout_p, Np->decimal, x))
{
* current position in inout!
*/
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->num_curr,
Np->number_p,
if (IS_ROMAN(Np->Num))
{
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->pre = Np->num_pre = Np->sign = 0;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/* Check for integer overflow */
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);
{
*cp++ = LDELIM;
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++ = RDELIM;
*cp++ = DELIM;
if ((!path_decode(FALSE, 2, str, &isopen, &s, &(box->high)))
|| (*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... */
if (box->high.x < box->low.x)
if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg.p[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_construct_pts(line, &lseg.p[0], &lseg.p[1]);
#else
- elog(ERROR, "line not yet implemented");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("line not yet implemented")));
+
line = NULL;
#endif
return path_encode(TRUE, 2, (Point *) &(ls->p[0]));
#else
- elog(ERROR, "line not yet implemented");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("line not yet implemented")));
result = NULL;
#endif
Datum
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;
}
Datum
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;
}
int depth = 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;
while (isspace((unsigned char) *s))
if ((!path_decode(TRUE, npts, s, &isopen, &s, &(path->p[0])))
&& (!((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);
closed = pq_getmsgbyte(buf);
npts = pq_getmsgint(buf, sizeof(int32));
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;
path = (PATH *) palloc(size);
char *s;
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));
if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg->p[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
lseg->m = point_sl(&lseg->p[0], &lseg->p[1]);
#endif
/* 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();
}
#endif
/* 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();
}
box_fill(&(poly->boundbox), x1, x2, y1, y2);
}
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")));
}
/*------------------------------------------------------------------
char *s;
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;
poly = (POLYGON *) palloc0(size); /* zero any holes */
if ((!path_decode(FALSE, npts, str, &isopen, &s, &(poly->p[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);
npts = pq_getmsgint(buf, sizeof(int32));
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;
poly = (POLYGON *) palloc0(size); /* zero any holes */
POLYGON *polyb = PG_GETARG_POLYGON_P(1);
#endif
- elog(ERROR, "poly_distance not implemented");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("poly_distance not implemented")));
PG_RETURN_NULL();
}
div = (p2->x * p2->x) + (p2->y * p2->y);
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->y = ((p2->x * p1->y) - (p2->y * p1->x)) / div;
/* Check for integer overflow */
if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) ||
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);
PATH *path = PG_GETARG_PATH_P(0);
#endif
- elog(ERROR, "path_center not implemented");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("path_center not implemented")));
PG_RETURN_NULL();
}
/* This is not very consistent --- other similar cases return NULL ... */
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;
poly = (POLYGON *) palloc(size);
}
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)
s++;
s++;
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)
{
s++;
}
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')
- 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);
}
*cp++ = LDELIM_C;
*cp++ = LDELIM;
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++ = RDELIM;
*cp++ = DELIM;
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++ = RDELIM_C;
circle->radius = pq_getmsgfloat8(buf);
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);
}
double angle;
double anglestep;
- if (FPzero(circle->radius) || (npts < 2))
- elog(ERROR, "Unable to convert circle to polygon");
+ if (FPzero(circle->radius))
+ 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;
size = offsetof(POLYGON, p[0]) +base_size;
/* Check for integer overflow */
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->size = size;
int i;
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->radius /= poly->npts;
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);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
while (*intString && isspace((unsigned char) *intString))
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)
result[slot++] = 0;
{
int32 arg1 = PG_GETARG_INT32(0);
- if (arg1 < SHRT_MIN)
- elog(ERROR, "i4toi2: '%d' causes int2 underflow", arg1);
- if (arg1 > SHRT_MAX)
- elog(ERROR, "i4toi2: '%d' causes int2 overflow", arg1);
+ if (arg1 < SHRT_MIN || arg1 > SHRT_MAX)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("integer out of range")));
PG_RETURN_INT16((int16) arg1);
}
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2);
}
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT16(arg1 / arg2);
}
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2);
}
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2);
}
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2);
}
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT16(arg1 % arg2);
}
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2);
}
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/*
* 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.
*/
bool
if (errorOK)
return false;
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 */
if (errorOK)
return false;
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;
}
if (errorOK)
return false;
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;
char buf[MAXINT8LEN + 1];
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val)) < 0)
- elog(ERROR, "Unable to format int8");
+ elog(ERROR, "could not format int8");
result = pstrdup(buf);
PG_RETURN_CSTRING(result);
int64 val2 = PG_GETARG_INT64(1);
if (val2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2);
}
int64 result;
if (val2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
result = val1 / val2;
result *= val2;
int32 val2 = PG_GETARG_INT32(1);
if (val2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2);
}
int64 val2 = PG_GETARG_INT64(1);
if (val2 == 0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2);
}
/* Test for overflow by reverse-conversion. */
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);
}
/* Test for overflow by reverse-conversion. */
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);
}
result = (int64) 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);
}
result = (int64) 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);
}
/* Test for overflow by reverse-conversion. */
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);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
BYTEA_NextChar(e, elen);
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);
/*
* Copyright (c) 1996-2002, PostgreSQL Global Development Group
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
NextChar(e, elen);
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);
/*
/*
* 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"
count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s",
&a, &b, &c, &d, &e, &f, junk);
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) ||
(c < 0) || (c > 255) || (d < 0) || (d > 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));
len = (VARSIZE(addr) - VARHDRSZ);
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);
*(str + len) = '\0';
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN)
- elog(WARNING, "Invalid timezone \'%s\'",
- tm->tm_zone);
+ ereport(WARNING,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid timezone name: \"%s\"",
+ tm->tm_zone)));
}
}
}
*/
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
- elog(WARNING, "Invalid timezone \'%s\'",
- tzname[tm->tm_isdst]);
+ ereport(WARNING,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid timezone name: \"%s\"",
+ tzname[tm->tm_isdst])));
}
}
}
ftype[MAXDATEFIELDS];
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)
|| (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)
{
break;
default:
- elog(ERROR, "Bad abstime (internal coding error) '%s'", str);
+ elog(ERROR, "unexpected dtype %d while parsing abstime \"%s\"",
+ dtype, str);
result = INVALID_ABSTIME;
break;
};
return -1; /* non-INVALID < INVALID */
#if 0
-/* CURRENT is no longer stored internally... */
+ /* CURRENT is no longer stored internally... */
/* XXX this is broken, should go away: */
if (a == CURRENT_ABSTIME)
a = GetCurrentTransactionStartTime();
}
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;
}
switch (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);
break;
default:
abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, NULL, &result) != 0)
- elog(ERROR, "Unable to convert ABSTIME to TIMESTAMP"
- "\n\tabstime_timestamp() internal error");
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
break;
};
result = tm2abstime(tm, 0);
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;
}
switch (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);
break;
default:
abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, &tz, &result) != 0)
- elog(ERROR, "Unable to convert ABSTIME to TIMESTAMP WITH TIME ZONE"
- "\n\tabstime_timestamptz() internal error");
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
break;
};
char lowstr[MAXDATELEN + 1];
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)
|| (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)
{
break;
default:
- elog(ERROR, "Bad reltime (internal coding error) '%s'", str);
+ elog(ERROR, "unexpected dtype %d while parsing reltime \"%s\"",
+ dtype, str);
result = INVALID_RELTIME;
break;
}
interval = (TimeInterval) palloc(sizeof(TimeIntervalData));
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)
interval->status = T_INTERVAL_INVAL; /* undefined */
interval->status = pq_getmsgint(buf, sizeof(interval->status));
if (!(interval->status == T_INTERVAL_INVAL ||
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[1] = pq_getmsgint(buf, sizeof(interval->data[1]));
switch (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->month = 0;
break;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
char *s = PG_GETARG_CSTRING(0);
NameData *result;
int len;
- char *ermsg;
/* verify encoding */
len = strlen(s);
- if ((ermsg = pg_verifymbstr(s, len)))
- elog(ERROR, "%s", ermsg);
+ pg_verifymbstr(s, len, false);
len = pg_mbcliplen(s, len, NAMEDATALEN - 1);
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
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);
memcpy(result, str, nbytes);
pfree(str);
/*
* 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
*/
bits = inet_net_pton(ip_family(dst), src, ip_addr(dst),
type ? ip_addrsize(dst) : -1);
if ((bits < 0) || (bits > ip_maxbits(dst)))
- elog(ERROR, "invalid %s value '%s'",
- type ? "CIDR" : "INET", src);
+ ereport(ERROR,
+ (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
* the masklen.
- */
- if (type)
+ */
+ if (type)
{
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
dst = inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
tmp, sizeof(tmp));
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 */
if (ip_type(src) && strchr(tmp, '/') == NULL)
{
ip_family(addr) = pq_getmsgbyte(buf);
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);
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_type(addr) = pq_getmsgbyte(buf);
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);
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
+ ((char *)ip_addr(addr) - (char *) VARDATA(addr))
+ ip_addrsize(addr);
if (ip_type(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);
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 */
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
/* force display of max bits, regardless of masklen... */
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
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) */
if ((ptr = strchr(tmp, '/')) != NULL)
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
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) */
if (strchr(tmp, '/') == NULL)
{
ip_bits(ip), tmp, sizeof(tmp));
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")));
/* Return string as a text datum */
len = strlen(tmp);
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* 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;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
names = textToQualifiedNameList(relation_and_attr, "int4notin");
nnames = length(names);
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));
names = ltruncate(nnames - 1, names);
relrv = makeRangeVarFromNameList(names);
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
*
* 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 $
*
*-------------------------------------------------------------------------
*/
len = (uint16) pq_getmsgint(buf, sizeof(uint16));
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);
if (!(value.sign == NUMERIC_POS ||
value.sign == NUMERIC_NEG ||
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));
for (i = 0; i < len; i++)
{
NumericDigit d = pq_getmsgint(buf, sizeof(NumericDigit));
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;
}
/* XXX would it be better to return NULL? */
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 */
init_var(&x);
set_var_from_num(num, &x);
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);
/* Test for overflow by reverse-conversion. */
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);
}
/* XXX would it be better to return NULL? */
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 */
init_var(&x);
set_var_from_num(num, &x);
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);
/* XXX would it be better to return NULL? */
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 */
init_var(&x);
set_var_from_num(num, &x);
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);
/* Test for overflow by reverse-conversion. */
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);
}
NUMERICOID, -1, false, 'i',
&transdatums, &ndatums);
if (ndatums != 3)
- elog(ERROR, "do_numeric_accum: expected 3-element numeric array");
+ elog(ERROR, "expected 3-element numeric array");
N = transdatums[0];
sumX = transdatums[1];
sumX2 = transdatums[2];
NUMERICOID, -1, false, 'i',
&transdatums, &ndatums);
if (ndatums != 3)
- elog(ERROR, "numeric_avg: expected 3-element numeric array");
+ elog(ERROR, "expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]);
sumX = DatumGetNumeric(transdatums[1]);
/* ignore sumX2 */
NUMERICOID, -1, false, 'i',
&transdatums, &ndatums);
if (ndatums != 3)
- elog(ERROR, "numeric_variance: expected 3-element numeric array");
+ elog(ERROR, "expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]);
sumX = DatumGetNumeric(transdatums[1]);
sumX2 = DatumGetNumeric(transdatums[2]);
NUMERICOID, -1, false, 'i',
&transdatums, &ndatums);
if (ndatums != 3)
- elog(ERROR, "numeric_stddev: expected 3-element numeric array");
+ elog(ERROR, "expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]);
sumX = DatumGetNumeric(transdatums[1]);
sumX2 = DatumGetNumeric(transdatums[2]);
* We copied the input array, so it's okay to scribble on it directly.
*/
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->count++;
* We copied the input array, so it's okay to scribble on it directly.
*/
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->count++;
sumd;
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);
/* SQL92 defines AVG of no values to be NULL */
}
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);
else if (*cp == '.')
{
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;
cp++;
}
cp++;
exponent = strtol(cp, &endptr, 10);
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;
if (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;
dscale -= (int) exponent;
if (dscale < 0)
while (*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++;
}
/* Check for overflow of int16 fields */
if (result->n_weight != weight ||
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);
return result;
#error unsupported NBASE
#endif
if (ddigits > maxdigits)
- elog(ERROR, "overflow on numeric "
- "ABS(value) >= 10^%d for field with precision %d scale %d",
- ddigits-1, precision, scale);
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("numeric field overflow"),
+ errdetail("ABS(value) >= 10^%d for field with precision %d, scale %d.",
+ ddigits-1, precision, scale)));
break;
}
ddigits -= DEC_DIGITS;
if (*endptr != '\0')
{
/* 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);
if (*endptr != '\0')
{
/* 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);
* unnormalized divisor.
*/
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
}
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_val);
x.weight--;
/* Guard against overflow */
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 */
int local_rscale;
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;
{
case 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);
result->dscale = rscale; /* no need to round */
return;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* c, if not 0, is the terminator character that may appear after the
* 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.
*/
int32
pg_atoi(char *s, int size, int c)
{
- long l = 0;
+ long l;
char *badp = NULL;
- errno = 0;
-
/*
* 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.
*/
-
if (s == (char *) NULL)
- elog(ERROR, "pg_atoi: NULL pointer");
- else if (*s == 0)
- elog(ERROR, "pg_atoi: zero-length string");
- else
- l = strtol(s, &badp, 10);
+ elog(ERROR, "NULL pointer");
+ if (*s == 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for integer: \"%s\"",
+ s)));
+
+ errno = 0;
+ l = strtol(s, &badp, 10);
/*
* strtol() normally only sets ERANGE. On some systems it also may
* set EINVAL, which simply means it couldn't parse the input string.
* This is handled by the second "if" consistent across platforms.
*/
- if (errno && errno != EINVAL)
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
+ if (errno && errno != ERANGE && errno != EINVAL)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for integer: \"%s\"",
+ s)));
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)
{
case sizeof(int32):
+ if (errno == ERANGE
#if defined(HAVE_LONG_INT_64)
- /* won't get ERANGE on these with 64-bit longs... */
- if (l < INT_MIN)
- {
- errno = ERANGE;
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
- }
- if (l > INT_MAX)
- {
- errno = ERANGE;
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
- }
-#endif /* HAVE_LONG_INT_64 */
+ /* won't get ERANGE on these with 64-bit longs... */
+ || l < INT_MIN || l > INT_MAX
+#endif
+ )
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("%s is out of range for int4", s)));
break;
case sizeof(int16):
- if (l < SHRT_MIN)
- {
- errno = ERANGE;
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
- }
- if (l > SHRT_MAX)
- {
- errno = ERANGE;
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
- }
+ if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("%s is out of range for int2", s)));
break;
case sizeof(int8):
- if (l < SCHAR_MIN)
- {
- errno = ERANGE;
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
- }
- if (l > SCHAR_MAX)
- {
- errno = ERANGE;
- elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
- }
+ if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("%s is out of range for int1", s)));
break;
default:
- elog(ERROR, "pg_atoi: invalid result size: %d", size);
+ elog(ERROR, "unsupported result size: %d", size);
}
return (int32) l;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
Oid result;
errno = 0;
-
cvt = strtoul(s, &endptr, 10);
/*
* Note that for historical reasons we accept an empty string as
* meaning 0.
*/
- if (errno && errno != EINVAL)
- elog(ERROR, "%s: error reading \"%s\": %m",
- funcname, s);
+ if (errno && errno != ERANGE && errno != EINVAL)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for OID: \"%s\"",
+ s)));
if (endptr == s && *endptr)
- elog(ERROR, "%s: error in \"%s\": can't parse \"%s\"",
- funcname, s, endptr);
+ ereport(ERROR,
+ (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)
{
while (*endptr && isspace((unsigned char) *endptr))
endptr++;
if (*endptr)
- elog(ERROR, "%s: error in \"%s\": can't parse \"%s\"",
- funcname, s, endptr);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for OID: \"%s\"",
+ s)));
}
result = (Oid) cvt;
#if OID_MAX != ULONG_MAX
if (cvt != (unsigned long) result &&
cvt != (unsigned long) ((int) result))
- elog(ERROR, "%s: error reading \"%s\": %s",
- funcname, s, strerror(ERANGE));
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("%s is out of range for OID", s)));
#endif
return result;
while (*oidString && isspace((unsigned char) *oidString))
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)
result[slot++] = InvalidOid;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/* check for integer overflow */
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);
/* Check for integer overflow */
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);
m = len - s1len;
int check2 = check + VARHDRSZ;
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);
*
* 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 $
*
*-----------------------------------------------------------------------
*/
return (bool) result;
localeptr = setlocale(LC_COLLATE, NULL);
if (!localeptr)
- elog(PANIC, "Invalid LC_COLLATE setting");
+ elog(ERROR, "invalid LC_COLLATE setting");
if (strcmp(localeptr, "C") == 0)
result = true;
if (fcinfo->resultinfo == NULL ||
!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_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,
2 * sizeof(int));
((int *) (fmgr_info->fn_extra))[0] = 0;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
Datum
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 */
}
*
*
* 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
* agc - cached the regular expressions used - there's a good chance
pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
/* 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)));
}
/*
if (re_temp.cre_pat == NULL)
{
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);
re_temp.cre_flags = cflags;
if (elen == 0)
e = NULL; /* no escape character */
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 */
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
heap_close(hdesc, AccessShareLock);
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)
- elog(ERROR, "There is more than one procedure named %s",
- pro_name_or_oid);
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
+ errmsg("more than one procedure named %s",
+ pro_name_or_oid)));
+
PG_RETURN_OID(result);
}
clist = FuncnameGetCandidates(names, -1);
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)
- elog(ERROR, "There is more than one procedure named %s",
- pro_name_or_oid);
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
+ errmsg("more than one procedure named %s",
+ pro_name_or_oid)));
result = clist->oid;
}
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;
heap_close(hdesc, AccessShareLock);
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)
- elog(ERROR, "There is more than one operator named %s",
- opr_name_or_oid);
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
+ errmsg("more than one operator named %s",
+ opr_name_or_oid)));
+
PG_RETURN_OID(result);
}
clist = OpernameGetCandidates(names, '\0');
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)
- elog(ERROR, "There is more than one operator named %s",
- opr_name_or_oid);
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
+ errmsg("more than one operator named %s",
+ opr_name_or_oid)));
result = clist->oid;
parseNameAndArgTypes(opr_name_or_oid, "regoperatorin", true,
&names, &nargs, argtypes);
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)
- 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)
oprkind = 'l';
}
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;
if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))
result = HeapTupleGetOid(tuple);
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 */
if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))
result = HeapTupleGetOid(tuple);
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 */
rawname = pstrdup(string);
if (!SplitIdentifierString(rawname, '.', &namelist))
- elog(ERROR, "%s: invalid name syntax", caller);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("invalid name syntax")));
if (namelist == NIL)
- elog(ERROR, "%s: invalid name syntax", caller);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("invalid name syntax")));
foreach(l, namelist)
{
break;
}
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 */
*ptr++ = '\0';
break;
}
if (*ptr2 != ')')
- elog(ERROR, "%s: expected a right parenthesis", caller);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("expected a right parenthesis")));
+
*ptr2 = '\0';
/* Separate the remaining string into comma-separated type names */
{
/* End of string. Okay unless we had a comma before. */
if (had_comma)
- elog(ERROR, "%s: expected a type name", caller);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("expected a type name")));
break;
}
typename = ptr;
}
}
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;
if (*ptr == ',')
{
parseTypeString(typename, &typeid, &typmod);
}
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;
(*nargs)++;
}
* back to source text
*
* 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.
*
* Connect to SPI manager
*/
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
argtypes[0] = OIDOID;
plan = SPI_prepare(query_getrulebyoid, 1, argtypes);
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);
}
nulls[0] = ' ';
spirc = SPI_execp(plan_getrulebyoid, args, nulls, 1);
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_finish() != SPI_OK_FINISH)
- elog(ERROR, "get_ruledef: SPI_finish() failed");
+ elog(ERROR, "SPI_finish failed");
ruledef = palloc(VARHDRSZ + 1);
VARATT_SIZEP(ruledef) = VARHDRSZ + 1;
VARDATA(ruledef)[0] = '-';
* Disconnect from SPI manager
*/
if (SPI_finish() != SPI_OK_FINISH)
- elog(ERROR, "get_ruledef: SPI_finish() failed");
+ elog(ERROR, "SPI_finish failed");
/*
* Easy - isn't it?
* Connect to SPI manager
*/
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
argtypes[1] = NAMEOID;
plan = SPI_prepare(query_getviewrule, 2, argtypes);
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);
}
* Disconnect from SPI manager
*/
if (SPI_finish() != SPI_OK_FINISH)
- elog(ERROR, "get_viewdef: SPI_finish() failed");
+ elog(ERROR, "SPI_finish failed");
return ruledef;
}
ht_trig = systable_getnext(tgscan);
if (!HeapTupleIsValid(ht_trig))
- elog(ERROR, "pg_get_triggerdef: there is no trigger with oid %u",
- trigid);
+ elog(ERROR, "could not find tuple for trigger %u", trigid);
trigrec = (Form_pg_trigger) GETSTRUCT(ht_trig);
ObjectIdGetDatum(indexrelid),
0, 0, 0);
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);
indrelid = idxrec->indrelid;
ObjectIdGetDatum(indexrelid),
0, 0, 0);
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);
/*
ObjectIdGetDatum(idxrelrec->relam),
0, 0, 0);
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);
/*
tup = systable_getnext(conscan);
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);
initStringInfo(&buf);
val = heap_getattr(tup, Anum_pg_constraint_conkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
- elog(ERROR, "pg_get_constraintdef: Null conkey for constraint %u",
+ elog(ERROR, "null conkey for constraint %u",
constraintId);
decompile_column_index_array(val, conForm->conrelid, &buf);
val = heap_getattr(tup, Anum_pg_constraint_confkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
- elog(ERROR, "pg_get_constraintdef: Null confkey for constraint %u",
+ elog(ERROR, "null confkey for constraint %u",
constraintId);
decompile_column_index_array(val, conForm->confrelid, &buf);
string = "";
break;
default:
- elog(ERROR, "pg_get_constraintdef: Unknown confmatchtype '%c' for constraint %u",
- conForm->confmatchtype, constraintId);
+ elog(ERROR, "unrecognized confmatchtype: %d",
+ conForm->confmatchtype);
string = ""; /* keep compiler quiet */
break;
}
string = "SET DEFAULT";
break;
default:
- elog(ERROR, "pg_get_constraintdef: Unknown confupdtype '%c' for constraint %u",
- conForm->confupdtype, constraintId);
+ elog(ERROR, "unrecognized confupdtype: %d",
+ conForm->confupdtype);
string = NULL; /* keep compiler quiet */
break;
}
string = "SET DEFAULT";
break;
default:
- elog(ERROR, "pg_get_constraintdef: Unknown confdeltype '%c' for constraint %u",
- conForm->confdeltype, constraintId);
+ elog(ERROR, "unrecognized confdeltype: %d",
+ conForm->confdeltype);
string = NULL; /* keep compiler quiet */
break;
}
val = heap_getattr(tup, Anum_pg_constraint_conkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
- elog(ERROR, "pg_get_constraintdef: Null conkey for constraint %u",
+ elog(ERROR, "null conkey for constraint %u",
constraintId);
decompile_column_index_array(val, conForm->conrelid, &buf);
val = heap_getattr(tup, Anum_pg_constraint_conbin,
RelationGetDescr(conDesc), &isnull);
if (isnull)
- elog(ERROR, "pg_get_constraintdef: Null consrc for constraint %u",
+ elog(ERROR, "null consrc for constraint %u",
constraintId);
conbin = DatumGetCString(DirectFunctionCall1(textout, val));
break;
}
default:
- elog(ERROR, "pg_get_constraintdef: unsupported constraint type '%c'",
- conForm->contype);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unsupported constraint type \"%c\"",
+ conForm->contype)));
break;
}
break;
default:
- elog(ERROR, "get_ruledef: rule %s has unsupported event type %d",
- rulename, ev_type);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("rule \"%s\" has unsupported event type %d",
+ rulename, ev_type)));
break;
}
break;
default:
- elog(ERROR, "get_query_def: unknown query command type %d",
+ elog(ERROR, "unrecognized query command type: %d",
query->commandType);
break;
}
appendStringInfo(buf, ") EXCEPT ");
break;
default:
- elog(ERROR, "get_setop_query: unexpected set op %d",
+ elog(ERROR, "unrecognized set op: %d",
(int) op->op);
}
if (op->all)
}
else
{
- elog(ERROR, "get_setop_query: unexpected node %d",
+ elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(setOp));
}
}
if (rte->rtekind != RTE_SUBQUERY)
continue;
if (select_rte)
- elog(ERROR, "get_insert_query_def: too many RTEs in INSERT!");
+ elog(ERROR, "too many RTEs in INSERT");
select_rte = rte;
}
stmt->relation->relname));
}
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");
+ }
}
while (sup-- > 0 && nslist != NIL)
nslist = lnext(nslist);
if (nslist == NIL)
- elog(ERROR, "get_names_for_var: bogus varlevelsup %d",
- var->varlevelsup);
+ elog(ERROR, "bogus varlevelsup: %d", var->varlevelsup);
dpns = (deparse_namespace *) lfirst(nslist);
/* Find the relevant RTE */
else
rte = NULL;
if (rte == NULL)
- elog(ERROR, "get_names_for_var: bogus varno %d",
- var->varno);
+ elog(ERROR, "bogus varno: %d", var->varno);
/* Emit results */
*schemaname = NULL; /* default assumptions */
break;
default:
- elog(ERROR, "get_rule_expr: unknown boolop %d",
+ elog(ERROR, "unrecognized boolop: %d",
(int) expr->boolop);
}
}
/* lookup arg type and get the field name */
typrelid = get_typ_typrelid(argType);
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));
fieldname = get_relid_attribute_name(typrelid,
fselect->fieldnum);
appendStringInfo(buf, " IS NOT NULL)");
break;
default:
- elog(ERROR, "get_rule_expr: unexpected nulltesttype %d",
+ elog(ERROR, "unrecognized nulltesttype: %d",
(int) ntest->nulltesttype);
}
}
appendStringInfo(buf, " IS NOT UNKNOWN)");
break;
default:
- elog(ERROR, "get_rule_expr: unexpected booltesttype %d",
+ elog(ERROR, "unrecognized booltesttype: %d",
(int) btest->booltesttype);
}
}
break;
default:
- elog(ERROR, "get_rule_expr: unknown node type %d", nodeTag(node));
+ elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
break;
}
}
ObjectIdGetDatum(opno),
0, 0, 0);
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);
switch (optup->oprkind)
{
InvalidOid));
break;
default:
- elog(ERROR, "get_rule_expr: bogus oprkind");
+ elog(ERROR, "bogus oprkind: %d", optup->oprkind);
}
ReleaseSysCache(tp);
}
ObjectIdGetDatum(constval->consttype),
0, 0, 0);
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);
break;
default:
- elog(ERROR, "get_sublink_expr: unsupported sublink type %d",
- sublink->subLinkType);
+ elog(ERROR, "unrecognized sublink type: %d",
+ (int) sublink->subLinkType);
break;
}
coldeflist = rte->coldeflist;
break;
default:
- elog(ERROR, "unexpected rte kind %d", (int) rte->rtekind);
+ elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
break;
}
if (rte->alias != NULL)
appendStringInfo(buf, " UNION JOIN ");
break;
default:
- elog(ERROR, "get_from_clause_item: unknown join type %d",
+ elog(ERROR, "unrecognized join type: %d",
(int) j->jointype);
}
get_from_clause_item(j->rarg, query, context);
}
}
else
- elog(ERROR, "get_from_clause_item: unexpected node type %d",
- nodeTag(jtnode));
+ elog(ERROR, "unrecognized node type: %d",
+ (int) nodeTag(jtnode));
}
/*
*/
if (aref->refexpr == NULL || !IsA(aref->refexpr, Var) ||
((Var *) aref->refexpr)->varattno != tle->resdom->resno)
- elog(WARNING, "tleIsArrayAssign: I'm confused ...");
+ elog(ERROR, "unrecognized situation in array assignment");
+
return true;
}
ObjectIdGetDatum(relid),
0, 0, 0);
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);
/* Qualify the name if not visible in search path */
ObjectIdGetDatum(funcid),
0, 0, 0);
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);
proname = NameStr(procform->proname);
Assert(nargs == procform->pronargs);
ObjectIdGetDatum(operid),
0, 0, 0);
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);
oprname = NameStr(operform->oprname);
p_result = right_oper(makeList1(makeString(oprname)), arg1, true);
break;
default:
- elog(ERROR, "unexpected oprkind %c for operator %u",
- operform->oprkind, operid);
+ elog(ERROR, "unrecognized oprkind: %d", operform->oprkind);
p_result = NULL; /* keep compiler quiet */
break;
}
attname = get_attname(relid, attnum);
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);
return attname;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
prefix->constvalue));
break;
default:
- elog(ERROR, "patternsel: unexpected consttype %u",
+ elog(ERROR, "unrecognized consttype: %u",
prefix->consttype);
return DEFAULT_MATCH_SEL;
}
List *eqargs;
if (eqopr == InvalidOid)
- elog(ERROR, "patternsel: no = operator for opclass %u", opclass);
+ elog(ERROR, "no = operator for opclass %u", opclass);
eqargs = makeList2(var, prefix);
result = DatumGetFloat8(DirectFunctionCall4(eqsel,
PointerGetDatum(root),
varRelid, jointype);
break;
default:
- elog(ERROR, "booltestsel: unexpected booltesttype %d",
+ elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
selec = 1.0 - freq_false;
break;
default:
- elog(ERROR, "booltestsel: unexpected booltesttype %d",
+ elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
selec = (1.0 - freq_null) / 2.0;
break;
default:
- elog(ERROR, "booltestsel: unexpected booltesttype %d",
+ elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
selec = DEFAULT_BOOL_SEL;
break;
default:
- elog(ERROR, "booltestsel: unexpected booltesttype %d",
+ elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
defselec = DEFAULT_NOT_UNK_SEL;
break;
default:
- elog(ERROR, "nulltestsel: unexpected nulltesttype %d",
+ elog(ERROR, "unrecognized nulltesttype: %d",
(int) nulltesttype);
return (Selectivity) 0; /* keep compiler quiet */
}
selec = 1.0 - freq_null;
break;
default:
- elog(ERROR, "nulltestsel: unexpected nulltesttype %d",
+ elog(ERROR, "unrecognized nulltesttype: %d",
(int) nulltesttype);
return (Selectivity) 0; /* keep compiler quiet */
}
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* 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;
}
* Can't get here unless someone tries to use scalarltsel on
* 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;
}
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* 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;
}
Assert(typeid == BYTEAOID || typeid == TEXTOID);
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)
{
* been made safe for binary (possibly NULL containing) strings.
*/
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 */
patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue));
result = regex_fixed_prefix(patt, true, prefix, rest);
break;
default:
- elog(ERROR, "pattern_fixed_prefix: bogus ptype");
+ elog(ERROR, "unrecognized ptype: %d", (int) ptype);
result = Pattern_Prefix_None; /* keep compiler quiet */
break;
}
cmpopr = get_opclass_member(opclass, BTGreaterEqualStrategyNumber);
if (cmpopr == InvalidOid)
- elog(ERROR, "prefix_selectivity: no >= operator for opclass %u",
- opclass);
+ elog(ERROR, "no >= operator for opclass %u", opclass);
cmpargs = makeList2(var, prefixcon);
/* Assume scalargtsel is appropriate for all supported types */
prefixsel = DatumGetFloat8(DirectFunctionCall4(scalargtsel,
cmpopr = get_opclass_member(opclass, BTLessStrategyNumber);
if (cmpopr == InvalidOid)
- elog(ERROR, "prefix_selectivity: no < operator for opclass %u",
- opclass);
+ elog(ERROR, "no < operator for opclass %u", opclass);
cmpargs = makeList2(var, greaterstrcon);
/* Assume scalarltsel is appropriate for all supported types */
topsel = DatumGetFloat8(DirectFunctionCall4(scalarltsel,
Assert(typeid == BYTEAOID || typeid == TEXTOID);
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)
{
* been made safe for binary (possibly NULL containing) strings.
*/
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 */
patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue));
result = regex_selectivity(patt, true);
break;
default:
- elog(ERROR, "pattern_selectivity: bogus ptype");
+ elog(ERROR, "unrecognized ptype: %d", (int) ptype);
result = 1.0; /* keep compiler quiet */
break;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
ObjectIdGetDatum(setoid),
0, 0, 0);
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
if (rsi && IsA(rsi, ReturnSetInfo))
rsi->isDone = isDone;
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);
*
*
* 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
* input routine largely stolen from boxin().
coord[i++] = p + 1;
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;
blockNumber = strtoul(coord[0], &badp, 10);
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);
if (errno || *badp != RDELIM ||
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;
result = (ItemPointer) palloc(sizeof(ItemPointerData));
}
}
if (tididx < 0)
- elog(ERROR, "currtid can't handle views with no CTID");
- if (rulelock = viewrel->rd_rules, !rulelock)
+ elog(ERROR, "currtid cannot handle views with no CTID");
+ rulelock = viewrel->rd_rules;
+ if (!rulelock)
elog(ERROR, "the view has no rules");
for (i = 0; i < rulelock->numLocks; i++)
{
elog(ERROR, "only one select rule is allowed in views");
query = (Query *) lfirst(rewrite->actions);
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;
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);
if (rte)
break;
}
}
- elog(ERROR, "currtid can't handle this view");
+ elog(ERROR, "currtid cannot handle this view");
return (Datum) 0;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
char lowstr[MAXDATELEN + MAXDATEFIELDS];
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)
|| (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)
{
case DTK_DATE:
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;
case DTK_EPOCH:
break;
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);
break;
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);
}
else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0)
EncodeDateTime(tm, fsec, NULL, &tzn, DateStyle, buf);
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);
PG_RETURN_CSTRING(result);
&& (typmod != -1) && (typmod != MAX_TIMESTAMP_PRECISION))
{
if ((typmod < 0) || (typmod > MAX_TIMESTAMP_PRECISION))
- elog(ERROR, "TIMESTAMP(%d) precision must be between %d and %d",
- typmod, 0, MAX_TIMESTAMP_PRECISION);
+ ereport(ERROR,
+ (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
char lowstr[MAXDATELEN + MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr))
- elog(ERROR, "Bad timestamp with time zone"
- " external representation (too long) '%s'", str);
+ ereport(ERROR,
+ (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)
|| (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)
{
case DTK_DATE:
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;
case DTK_EPOCH:
break;
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);
break;
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);
}
else if (timestamp2tm(dt, &tz, tm, &fsec, &tzn) == 0)
EncodeDateTime(tm, fsec, &tz, &tzn, DateStyle, buf);
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);
PG_RETURN_CSTRING(result);
fsec = 0;
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)
|| (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));
{
case DTK_DELTA:
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);
break;
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;
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);
char buf[MAXDATELEN + 1];
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)
- elog(ERROR, "Unable to format interval; internal coding error");
+ elog(ERROR, "could not format interval");
result = pstrdup(buf);
PG_RETURN_CSTRING(result);
#endif
}
else
- elog(ERROR, "AdjustIntervalForTypmod(): internal coding error");
+ elog(ERROR, "unrecognized interval typmod: %d", typmod);
/* Need to adjust precision? If not, don't even try! */
if (precision != INTERVAL_FULL_PRECISION)
{
if ((precision < 0) || (precision > MAX_INTERVAL_PRECISION))
- elog(ERROR, "INTERVAL(%d) precision must be between %d and %d",
- precision, 0, MAX_INTERVAL_PRECISION);
+ ereport(ERROR,
+ (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
}
return 0;
-} /* timestamp2tm() */
+}
/* tm2timestamp()
* Note that year is _not_ 1900-based, but is an explicit full value.
* Also, month is one-based, _not_ zero-based.
*
- * Returns -1 on failure (overflow).
+ * Returns -1 on failure (value out of range).
*/
int
tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
*result = dt2local(*result, -(*tzp));
return 0;
-} /* tm2timestamp() */
+}
/* interval2tm()
#endif
return 0;
-} /* interval2tm() */
+}
int
tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
#endif
return 0;
-} /* tm2interval() */
+}
#ifdef HAVE_INT64_TIMESTAMP
static int64
*tm = &tt;
GetEpochTime(tm);
+ /* we don't bother to test for failure ... */
tm2timestamp(tm, 0, NULL, &dt);
return dt;
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;
}
else
*tm = &tt;
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;
+ if (tm->tm_mon > 12)
{
- tm->tm_mon += span->month;
- if (tm->tm_mon > 12)
- {
- tm->tm_year += ((tm->tm_mon - 1) / 12);
- tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
- }
- else if (tm->tm_mon < 1)
- {
- tm->tm_year += ((tm->tm_mon / 12) - 1);
- tm->tm_mon = ((tm->tm_mon % 12) + 12);
- }
-
- /* adjust for end of month boundary problems... */
- if (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, ×tamp) != 0)
- {
- elog(ERROR, "Unable to add TIMESTAMP and INTERVAL"
- "\n\ttimestamp_pl_span() internal error encoding timestamp");
- PG_RETURN_NULL();
- }
+ tm->tm_year += ((tm->tm_mon - 1) / 12);
+ tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
}
- else
+ else if (tm->tm_mon < 1)
{
- elog(ERROR, "Unable to add TIMESTAMP and INTERVAL"
- "\n\ttimestamp_pl_span() internal error decoding timestamp");
- PG_RETURN_NULL();
+ tm->tm_year += ((tm->tm_mon / 12) - 1);
+ tm->tm_mon = ((tm->tm_mon % 12) + 12);
}
+
+ /* adjust for end of month boundary problems... */
+ if (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, ×tamp) != 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
}
timestamp += span->time;
*tm = &tt;
fsec_t fsec;
- if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0)
- {
- tm->tm_mon += span->month;
- if (tm->tm_mon > 12)
- {
- tm->tm_year += ((tm->tm_mon - 1) / 12);
- tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
- }
- else if (tm->tm_mon < 1)
- {
- tm->tm_year += ((tm->tm_mon / 12) - 1);
- tm->tm_mon = ((tm->tm_mon % 12) + 12);
- }
-
- /* adjust for end of month boundary problems... */
- if (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]);
-
- tz = DetermineLocalTimeZone(tm);
+ if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
- if (tm2timestamp(tm, fsec, &tz, ×tamp) != 0)
- elog(ERROR, "Unable to add TIMESTAMP and INTERVAL"
- "\n\ttimestamptz_pl_span() internal error encoding timestamp");
+ tm->tm_mon += span->month;
+ if (tm->tm_mon > 12)
+ {
+ tm->tm_year += ((tm->tm_mon - 1) / 12);
+ tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
}
- else
+ else if (tm->tm_mon < 1)
{
- elog(ERROR, "Unable to add TIMESTAMP and INTERVAL"
- "\n\ttimestamptz_pl_span() internal error decoding timestamp");
+ tm->tm_year += ((tm->tm_mon / 12) - 1);
+ tm->tm_mon = ((tm->tm_mon % 12) + 12);
}
+
+ /* adjust for end of month boundary problems... */
+ if (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]);
+
+ tz = DetermineLocalTimeZone(tm);
+
+ if (tm2timestamp(tm, fsec, &tz, ×tamp) != 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
}
timestamp += span->time;
result = (Interval *) palloc(sizeof(Interval));
if (factor == 0.0)
- elog(ERROR, "division by zero");
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
#ifdef HAVE_INT64_TIMESTAMP
result->month = (span->month / factor);
INTERVALOID, 12, false, 'd',
&transdatums, &ndatums);
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
INTERVALOID, 12, false, 'd',
&transdatums, &ndatums);
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
}
if (tm2interval(tm, fsec, result) != 0)
- elog(ERROR, "Unable to encode INTERVAL"
- "\n\ttimestamp_age() internal coding error");
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("interval out of range")));
}
else
- elog(ERROR, "Unable to decode TIMESTAMP"
- "\n\ttimestamp_age() internal coding error");
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("timestamp out of range")));
PG_RETURN_INTERVAL_P(result);
}
}
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
- 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);
}
dstr[MAXDATELEN + 1];
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);
dp = dstr;
dstr[MAXDATELEN + 1];
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);
dp = dstr;
dstr[MAXDATELEN + 1];
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);
dp = dstr;
for (i = 0; i < (VARSIZE(str) - VARHDRSZ); i++)
*tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "TIMESTAMP units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("timestamp units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
+
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
if (TIMESTAMP_NOT_FINITE(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)
{
case DTK_MILLENNIUM:
break;
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;
}
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
{
- elog(ERROR, "TIMESTAMP units '%s' not recognized", lowunits);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("timestamp units \"%s\" not recognized",
+ lowunits)));
result = 0;
}
*tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("timestamp with time zone units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
if (TIMESTAMP_NOT_FINITE(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)
{
case DTK_MILLENNIUM:
break;
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;
}
tz = DetermineLocalTimeZone(tm);
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
{
- elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized", lowunits);
- PG_RETURN_NULL();
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("timestamp with time zone units \"%s\" not recognized",
+ lowunits)));
+ result = 0;
}
PG_RETURN_TIMESTAMPTZ(result);
result = (Interval *) palloc(sizeof(Interval));
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "INTERVAL units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("interval units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
break;
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)
- elog(ERROR, "Unable to truncate INTERVAL to '%s'", lowunits);
-
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("interval out of range")));
}
else
{
- elog(WARNING, "Unable to decode INTERVAL; internal coding error");
- *result = *interval;
+ elog(ERROR, "could not convert interval to tm");
}
}
else
{
- elog(ERROR, "INTERVAL units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("interval units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
*result = *interval;
}
dayn;
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 */
day4 = date2j(*year, 1, 4);
*tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "TIMESTAMP units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("timestamp units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
PG_RETURN_FLOAT8(result);
}
- 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)
{
case DTK_MICROSEC:
case DTK_TZ_MINUTE:
case DTK_TZ_HOUR:
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;
}
}
/* convert to timestamptz to produce consistent results */
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);
if (tm2timestamp(tm, fsec, &tz, ×tamptz) != 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
result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);
}
case DTK_DOW:
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));
break;
case DTK_DOY:
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)
- date2j(tm->tm_year, 1, 1) + 1);
break;
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;
}
}
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;
}
*tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("timestamp with time zone units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
PG_RETURN_FLOAT8(result);
}
- 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)
{
case DTK_TZ:
break;
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;
}
case DTK_DOW:
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));
break;
case DTK_DOY:
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)
- date2j(tm->tm_year, 1, 1) + 1);
break;
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;
}
}
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;
}
*tm = &tt;
if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "INTERVAL units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("interval units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
up = VARDATA(units);
lp = lowunits;
for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
break;
default:
- elog(ERROR, "INTERVAL units '%s' not supported",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("interval units \"%s\" not supported",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
result = 0;
}
}
else
{
- elog(WARNING, "Unable to decode INTERVAL"
- "\n\tinterval_part() internal coding error");
+ elog(ERROR, "could not convert interval to tm");
result = 0;
}
}
}
else
{
- elog(ERROR, "INTERVAL units '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("interval units \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(units))))));
result = 0;
}
lowzone[MAXDATELEN + 1];
if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "Time zone '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(zone))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("time zone \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(zone))))));
if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_TIMESTAMPTZ(timestamp);
}
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_TIMESTAMPTZ(timestamp);
if (zone->month != 0)
- elog(ERROR, "INTERVAL time zone '%s' not legal (month specified)",
- DatumGetCString(DirectFunctionCall1(interval_out,
- PointerGetDatum(zone))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("interval time zone \"%s\" must not specify month",
+ DatumGetCString(DirectFunctionCall1(interval_out,
+ PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
tz = (zone->time / INT64CONST(1000000));
else
{
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);
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);
else
{
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)
- 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);
lowzone[MAXDATELEN + 1];
if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
- elog(ERROR, "Time zone '%s' not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(zone))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("time zone \"%s\" not recognized",
+ DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(zone))))));
up = VARDATA(zone);
lp = lowzone;
for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
}
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();
if (zone->month != 0)
- elog(ERROR, "INTERVAL time zone '%s' not legal (month specified)",
- DatumGetCString(DirectFunctionCall1(interval_out,
- PointerGetDatum(zone))));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("interval time zone \"%s\" must not specify month",
+ DatumGetCString(DirectFunctionCall1(interval_out,
+ PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
tz = -(zone->time / INT64CONST(1000000));
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
if (atttypmod <= 0)
atttypmod = bitlen;
else if (bitlen != atttypmod)
- elog(ERROR, "Bit string length %d does not match type BIT(%d)",
- bitlen, atttypmod);
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
+ errmsg("bit string length %d does not match type bit(%d)",
+ bitlen, atttypmod)));
len = VARBITTOTALLEN(atttypmod);
/* set to 0 so that *r is always initialised and string is zero-padded */
if (*sp == '1')
*r |= x;
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;
if (x == 0)
{
else if (*sp >= 'a' && *sp <= 'f')
x = (bits8) (*sp - 'a') + 10;
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)
{
*r++ |= x;
PG_RETURN_VARBIT_P(arg);
if (!isExplicit)
- elog(ERROR, "Bit string length %d does not match type BIT(%d)",
- VARBITLEN(arg), len);
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
+ errmsg("bit string length %d does not match type bit(%d)",
+ VARBITLEN(arg), len)));
rlen = VARBITTOTALLEN(len);
/* set to 0 so that string is zero-padded */
if (atttypmod <= 0)
atttypmod = bitlen;
else if (bitlen > atttypmod)
- elog(ERROR, "Bit string too long for type BIT VARYING(%d)",
- atttypmod);
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
+ errmsg("bit string too long for type bit varying(%d)",
+ atttypmod)));
len = VARBITTOTALLEN(bitlen);
/* set to 0 so that *r is always initialised and string is zero-padded */
if (*sp == '1')
*r |= x;
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;
if (x == 0)
{
else if (*sp >= 'a' && *sp <= 'f')
x = (bits8) (*sp - 'a') + 10;
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)
{
*r++ |= x;
bitlen = pq_getmsgint(buf, sizeof(int32));
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);
result = (VarBit *) palloc(len);
PG_RETURN_VARBIT_P(arg);
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);
result = (VarBit *) palloc(rlen);
bitlen1 = VARBITLEN(arg1);
bitlen2 = VARBITLEN(arg2);
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);
result = (VarBit *) palloc(len);
VARATT_SIZEP(result) = len;
bitlen1 = VARBITLEN(arg1);
bitlen2 = VARBITLEN(arg2);
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);
result = (VarBit *) palloc(len);
VARATT_SIZEP(result) = len;
bitlen1 = VARBITLEN(arg1);
bitlen2 = VARBITLEN(arg2);
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);
result = (VarBit *) palloc(len);
VARATT_SIZEP(result) = len;
/* Check that the bit string is not too long */
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;
for (r = VARBITS(arg); r < VARBITEND(arg); r++)
{
PG_RETURN_VARBIT_P(result);
#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();
#endif
}
/* Check that the bit string is not too long */
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;
for (r = VARBITS(arg); r < VARBITEND(arg); r++)
{
PG_RETURN_INT64(result);
#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();
#endif
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
size_t len,
maxlen;
int i;
-
int charlen; /* number of charcters in the input string */
- char *ermsg;
+ /* verify encoding */
len = strlen(s);
-
- if ((ermsg = pg_verifymbstr(s, len)))
- elog(ERROR, "%s", ermsg);
+ pg_verifymbstr(s, len, false);
charlen = pg_mbstrlen(s);
-
/* If typmod is -1 (or invalid), use the actual string length */
if (atttypmod < (int32) VARHDRSZ)
maxlen = charlen;
if (strspn(s + mbmaxlen, " ") == len - mbmaxlen)
len = mbmaxlen;
else
- elog(ERROR, "value too long for type character(%d)",
- (int) maxlen);
+ ereport(ERROR,
+ (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
{
for (i = maxmblen - VARHDRSZ; i < len - VARHDRSZ; i++)
if (*(VARDATA(source) + i) != ' ')
- elog(ERROR, "value too long for type character(%d)",
- maxlen - VARHDRSZ);
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
+ errmsg("value too long for type character(%d)",
+ maxlen - VARHDRSZ)));
}
len = maxmblen;
size_t len,
maxlen;
- char *ermsg;
-
+ /* verify encoding */
len = strlen(s);
-
- if ((ermsg = pg_verifymbstr(s, len)))
- elog(ERROR, "%s", ermsg);
+ pg_verifymbstr(s, len, false);
maxlen = atttypmod - VARHDRSZ;
if (strspn(s + mbmaxlen, " ") == len - mbmaxlen)
len = mbmaxlen;
else
- elog(ERROR, "value too long for type character varying(%d)",
- (int) maxlen);
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
+ errmsg("value too long for type character varying(%d)",
+ (int) maxlen)));
}
result = palloc(len + VARHDRSZ);
{
for (i = maxmblen; i < len - VARHDRSZ; i++)
if (*(VARDATA(source) + i) != ' ')
- elog(ERROR, "value too long for type character varying(%d)",
- maxlen - VARHDRSZ);
+ ereport(ERROR,
+ (errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
+ errmsg("value too long for type character varying(%d)",
+ maxlen - VARHDRSZ)));
}
len = maxmblen + VARHDRSZ;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*
* Non-printable characters must be passed as '\nnn' (octal) and are
* converted to internal form. '\' must be passed as '\\'.
- * elog(ERROR, ...) if bad form.
+ * ereport(ERROR, ...) if bad form.
*
* BUGS:
* The input is scaned twice.
/*
* 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")));
}
}
* We should never get here. The first pass should not allow
* it.
*/
- elog(ERROR, "Bad input string for type bytea");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for bytea")));
}
}
text *result;
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)))
- elog(ERROR, "%s", ermsg);
-
- result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
-
- memcpy(VARDATA(result), inputText, len - VARHDRSZ);
+ memcpy(VARDATA(result), inputText, len);
#ifdef CYR_RECODE
- convertstr(VARDATA(result), len - VARHDRSZ, 0);
+ convertstr(VARDATA(result), len, 0);
#endif
PG_RETURN_TEXT_P(result);
}
/* should never get here */
- elog(ERROR, "Invalid backend encoding; encoding max length "
- "is less than one.");
+ elog(ERROR, "invalid backend encoding: encoding max length < 1");
/* not reached: suppress compiler warning */
return 0;
* to be before the start. SQL99 says to throw an error.
*/
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
* to be before the start. SQL99 says to throw an error.
*/
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
return ret;
}
else
- elog(ERROR, "Invalid backend encoding; encoding max length "
- "is less than one.");
+ elog(ERROR, "invalid backend encoding: encoding max length < 1");
/* not reached: suppress compiler warning */
return PG_STR_GET_TEXT("");
pfree(ps2);
}
else
- elog(ERROR, "Invalid backend encoding; encoding max length "
- "is less than one.");
+ elog(ERROR, "invalid backend encoding: encoding max length < 1");
PG_RETURN_INT32(pos);
}
* be before the start. SQL99 says to throw an error.
*/
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
len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len)
- elog(ERROR, "byteaGetByte: index %d out of range [0..%d]",
- n, len - 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("index %d out of valid range, 0..%d",
+ n, len - 1)));
byte = ((unsigned char *) VARDATA(v))[n];
len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len * 8)
- elog(ERROR, "byteaGetBit: index %d out of range [0..%d]",
- n, len * 8 - 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("index %d out of valid range, 0..%d",
+ n, len * 8 - 1)));
byteNo = n / 8;
bitNo = n % 8;
len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len)
- elog(ERROR, "byteaSetByte: index %d out of range [0..%d]",
- n, len - 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("index %d out of valid range, 0..%d",
+ n, len - 1)));
/*
* Make a copy of the original varlena.
len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len * 8)
- elog(ERROR, "byteaSetBit: index %d out of range [0..%d]",
- n, len * 8 - 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("index %d out of valid range, 0..%d",
+ n, len * 8 - 1)));
byteNo = n / 8;
bitNo = n % 8;
* sanity check!
*/
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.
PointerGetDatum(textval)));
if (!SplitIdentifierString(rawname, '.', &namelist))
- elog(ERROR, "%s: invalid name syntax", caller);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("invalid name syntax")));
if (namelist == NIL)
- elog(ERROR, "%s: invalid name syntax", caller);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("invalid name syntax")));
foreach(l, namelist)
{
/* field number is 1 based */
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),
PointerGetDatum(fldsep),
/*
* conversion functions between pg_wchar and multibyte streams.
* 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
*
}
#ifndef FRONTEND
+
/*
* Verify mbstr to make sure that it has a valid character sequence.
- * mbstr is not necessarily NULL terminated. length of mbstr is
- * specified by len. If an error was found, returns an error message.
- * Note that the message is kept in a static buffer, the next invocation
- * might break the message.
- * If no error was found, this function returns NULL.
+ * mbstr is not necessarily NULL terminated; length of mbstr is
+ * specified by len.
+ *
+ * If OK, return TRUE. If a problem is found, return FALSE when noError is
+ * true; when noError is false, ereport() a descriptive message.
*/
-char *
-pg_verifymbstr(const unsigned char *mbstr, int len)
+bool
+pg_verifymbstr(const unsigned char *mbstr, int len, bool noError)
{
int l;
- int i,
- j;
- static char buf[256];
- int slen = 0;
+ int i;
+ int encoding;
- /* we do not check single byte encodings */
+ /* we do not need any check in single-byte encodings */
if (pg_database_encoding_max_length() <= 1)
- return NULL;
+ return true;
+
+ encoding = GetDatabaseEncoding();
while (len > 0 && *mbstr)
{
/* special UTF-8 check */
- if (GetDatabaseEncoding() == PG_UTF8 &&
- (*mbstr & 0xf8) == 0xf0)
+ if (encoding == PG_UTF8 && (*mbstr & 0xf8) == 0xf0)
{
- snprintf(buf, sizeof(buf), "Unicode >= 0x10000 is not supported");
- return (buf);
+ if (noError)
+ return false;
+ ereport(ERROR,
+ (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
+ errmsg("UNICODE characters >= 0x10000 are not supported")));
}
l = pg_mblen(mbstr);
- /* multibyte letter? */
- if (l > 1)
+ for (i = 1; i < l; i++)
{
- for (i = 1; i < l; i++)
+ /*
+ * we expect that every multibyte char consists of bytes
+ * having the 8th bit set
+ */
+ if (i >= len || (mbstr[i] & 0x80) == 0)
{
- if (i > len || *(mbstr + i) == '\0' ||
+ char buf[8 * 2 + 1];
+ char *p = buf;
+ int j,
+ jlimit;
+
+ if (noError)
+ return false;
- /*
- * we assume that every multibyte letter consists of bytes
- * being the 8th bit set
- */
- ((*(mbstr + i) & 0x80) == 0))
+ jlimit = Min(l, len);
+ jlimit = Min(jlimit, 8); /* prevent buffer overrun */
+
+ for (j = 0; j < jlimit; j++)
{
- int remains = sizeof(buf);
- char *p = buf;
-
- slen = snprintf(p, remains, "Invalid %s character sequence found (0x",
- GetDatabaseEncodingName());
- p += slen;
- remains -= slen;
-
- i = ((*(mbstr + i) & 0x80) == 0) ? l : i;
-
- for (j = 0; j < i; j++)
- {
- slen = snprintf(p, remains, "%02x",
- *(mbstr + j));
- p += slen;
- remains -= slen;
- }
- snprintf(p, remains, ")");
- return (buf);
+ p += sprintf(p, "%02x", mbstr[j]);
}
+
+ ereport(ERROR,
+ (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
+ errmsg("invalid %s character sequence: 0x%s",
+ GetDatabaseEncodingName(), buf)));
}
}
+
len -= 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
#define PG_WCHAR_H
extern void UtfToLocal(unsigned char *utf, unsigned char *iso,
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_mic2ascii(unsigned char *src, unsigned char *dest, int len);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
#define ERRCODE_ARRAY_SUBSCRIPT_ERROR ERRCODE_ARRAY_ELEMENT_ERROR
#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_VALUE_OUT_OF_RANGE ERRCODE_DATETIME_FIELD_OVERFLOW
#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_ESCAPE_CHARACTER_CONFLICT MAKE_SQLSTATE('2','2', '0','0','B')
#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_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_INVALID_BINARY_REPRESENTATION MAKE_SQLSTATE('2','2', 'P','0','2')
-#define ERRCODE_FLOATING_POINT_EXCEPTION MAKE_SQLSTATE('2','2', 'P','0','3')
-#define ERRCODE_UNTRANSLATABLE_CHARACTER MAKE_SQLSTATE('2','2', 'P','0','4')
+#define ERRCODE_FLOATING_POINT_EXCEPTION MAKE_SQLSTATE('2','2', 'P','0','1')
+#define ERRCODE_INVALID_TEXT_REPRESENTATION MAKE_SQLSTATE('2','2', 'P','0','2')
+#define ERRCODE_INVALID_BINARY_REPRESENTATION MAKE_SQLSTATE('2','2', 'P','0','3')
+#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 */
#define ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('2','3', '0','0','0')
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
-- what happens if we specify slightly misformatted abstime?
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');
-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
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');
-- test abstime operators
SELECT '' AS eight, ABSTIME_TBL.*;
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
-- what happens if we specify slightly misformatted abstime?
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');
-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
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');
-- test abstime operators
SELECT '' AS eight, ABSTIME_TBL.*;
-- set defaults to an incorrect type: this should fail
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;
-- set defaults on a non-existent column: this should fail
alter table def_test alter column c3 set default 30;
--
CREATE TABLE BIT_TABLE(b BIT(11));
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'11011000000');
INSERT INTO BIT_TABLE VALUES (B'01010101010');
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 ('X555');
SELECT * FROM BIT_TABLE;
INSERT INTO VARBIT_TABLE VALUES (B'010101');
INSERT INTO VARBIT_TABLE VALUES (B'01010101010');
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 ('X555');
SELECT * FROM VARBIT_TABLE;
DROP TABLE bit_table;
-- The following should fail
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';
-ERROR: Cannot OR bit strings of different sizes
+ERROR: cannot OR bit strings of different sizes
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
SELECT POSITION(B'1010' IN B'0000101'); -- 0
position
-- For pre-v6.3 this evaluated to false - thomas 1997-10-23
INSERT INTO BOOLTBL2 (f1)
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
SELECT '' AS f_4, BOOLTBL2.*;
f_4 | f1
INSERT INTO BOX_TBL (f1) VALUES ('(3.0, 3.0,3.0,3.0)');
-- badly formatted box inputs
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');
-ERROR: Bad box external representation 'asdfasdf(ad'
+ERROR: invalid input syntax for box: "asdfasdf(ad"
SELECT '' AS four, BOX_TBL.*;
four | f1
------+---------------------
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
-- bad values
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');
-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)');
-ERROR: Bad circle external representation '(3,(1,2),3)'
+ERROR: invalid input syntax for circle: "(3,(1,2),3)"
SELECT * FROM CIRCLE_TBL;
f1
----------------
ERROR: attribute "d" specified more than once
-- missing data: should fail
COPY x from stdin;
-ERROR: pg_atoi: zero-length string
+ERROR: invalid input syntax for integer: ""
CONTEXT: COPY FROM, line 1
COPY x from stdin;
ERROR: missing data for column "e"
INSERT INTO DATE_TBL VALUES ('1996-03-02');
INSERT INTO DATE_TBL VALUES ('1997-02-28');
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-02');
INSERT INTO DATE_TBL VALUES ('2000-04-01');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow
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');
-ERROR: Bad float4 input format -- overflow
+ERROR: float4 value out of range: overflow
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');
-ERROR: Bad float4 input format -- underflow
+ERROR: float4 value out of range: underflow
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+--------------
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow
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');
-ERROR: Bad float4 input format -- overflow
+ERROR: float4 value out of range: overflow
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');
-ERROR: Bad float4 input format -- underflow
+ERROR: float4 value out of range: underflow
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+-------------
SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0';
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;
-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' ;
-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' ;
-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;
-ERROR: exp() result is out of range
+ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow
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');
-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');
-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');
-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
-- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL;
SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0';
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;
-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' ;
-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' ;
-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;
-ERROR: exp() result is out of range
+ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow
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');
-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');
-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');
-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
-- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL;
SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0';
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;
-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' ;
-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' ;
-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;
-ERROR: exp() result is out of range
+ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow
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');
-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');
-- maintain external table consistency across platforms
SET f1 = FLOAT8_TBL.f1 * '-1'
WHERE FLOAT8_TBL.f1 > '0.0';
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;
-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' ;
-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' ;
-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;
-ERROR: exp() result is out of range
+ERROR: result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
-- test for over- and underflow
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');
-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');
-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');
-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
-- delete all values and reinsert well-behaved ones
DELETE FROM FLOAT8_TBL;
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
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
FROM INTERVAL_TBL;
ten | interval | reltime
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
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
FROM INTERVAL_TBL;
ten | interval | reltime
SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp"
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
FROM INTERVAL_TBL;
ten | interval | reltime
INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24');
-- check that CIDR rejects invalid input:
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');
-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:
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');
-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;
- ten | cidr | inet
+ ten | cidr | inet
-----+--------------------+------------------
| 192.168.1.0/24 | 192.168.1.226/24
| 192.168.1.0/24 | 192.168.1.226
-- now test some support functions
SELECT '' AS ten, i AS inet, host(i), text(i), family(i) FROM INET_TBL;
- ten | inet | host | text | family
+ ten | inet | host | text | family
-----+------------------+---------------+------------------+--------
| 192.168.1.226/24 | 192.168.1.226 | 192.168.1.226/24 | 4
| 192.168.1.226 | 192.168.1.226 | 192.168.1.226/32 | 4
SELECT '' AS ten, c AS cidr, broadcast(c),
i AS inet, broadcast(i) FROM INET_TBL;
- ten | cidr | broadcast | inet | broadcast
+ ten | cidr | broadcast | inet | broadcast
-----+--------------------+------------------+------------------+---------------------------------------
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226 | 192.168.1.226
SELECT '' AS ten, c AS cidr, network(c) AS "network(cidr)",
i AS inet, network(i) AS "network(inet)" FROM INET_TBL;
- ten | cidr | network(cidr) | inet | network(inet)
+ ten | cidr | network(cidr) | inet | network(inet)
-----+--------------------+--------------------+------------------+------------------
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226/24 | 192.168.1.0/24
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226 | 192.168.1.226/32
i << c AS sb, i <<= c AS sbe,
i >> c AS sup, i >>= c AS spe
FROM INET_TBL;
- ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
+ ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
-----+------------------+--------------------+----+----+----+----+----+----+----+-----+-----+-----
| 192.168.1.226/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
| 192.168.1.226 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
INSERT INTO INT2_TBL(f1) VALUES ('1234');
INSERT INTO INT2_TBL(f1) VALUES ('-1234');
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
INSERT INTO INT2_TBL(f1) VALUES ('32767');
INSERT INTO INT2_TBL(f1) VALUES ('-32767');
-- bad input values -- should give warnings
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');
-ERROR: pg_atoi: error in "asdf": can't parse "asdf"
+ERROR: invalid input syntax for integer: "asdf"
SELECT '' AS five, INT2_TBL.*;
five | f1
------+--------
INSERT INTO INT4_TBL(f1) VALUES ('123456');
INSERT INTO INT4_TBL(f1) VALUES ('-123456');
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
INSERT INTO INT4_TBL(f1) VALUES ('2147483647');
INSERT INTO INT4_TBL(f1) VALUES ('-2147483647');
-- bad input values -- should give warnings
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');
-ERROR: pg_atoi: error in "asdf": can't parse "asdf"
+ERROR: invalid input syntax for integer: "asdf"
SELECT '' AS five, INT4_TBL.*;
five | f1
------+-------------
INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
-- 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');
-ERROR: Bad interval external representation '@ 30 eons ago'
+ERROR: invalid input syntax for interval: "@ 30 eons ago"
-- test interval operators
SELECT '' AS ten, INTERVAL_TBL.*;
ten | f1
INSERT INTO LSEG_TBL VALUES ('(11,22,33,44)');
-- bad values for parser testing
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');
-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)]');
-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)');
-ERROR: Bad lseg external representation '[(1,2),(3,4)'
+ERROR: invalid input syntax for lseg: "[(1,2),(3,4)"
select * from LSEG_TBL;
s
-------------------------------
INSERT INTO fract_only VALUES (1, '0.0');
INSERT INTO fract_only VALUES (2, '0.1');
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 (5, '0.99994');
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 (8, '0.00017');
SELECT * FROM fract_only;
INSERT INTO OID_TBL(f1) VALUES ('');
-- bad inputs
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');
-ERROR: oidin: error in "99asdfasd": can't parse "asdfasd"
+ERROR: invalid input syntax for OID: "99asdfasd"
SELECT '' AS six, OID_TBL.*;
six | f1
-----+------------
INSERT INTO PATH_TBL VALUES ('(11,12,13,14)');
-- bad values for parser testing
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)');
-ERROR: Bad path external representation '[(1,2),(3,4)'
+ERROR: invalid input syntax for path: "[(1,2),(3,4)"
SELECT f1 FROM PATH_TBL;
f1
---------------------------
INSERT INTO POINT_TBL(f1) VALUES ('(-5.0,-12.0)');
-- bad format points
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)');
-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');
-ERROR: Bad point external representation '(10.0,10.0'
+ERROR: invalid input syntax for point: "(10.0,10.0"
SELECT '' AS six, POINT_TBL.*;
six | f1
-----+------------
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,1.0),(0.0,1.0)');
-- bad polygon input strings
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');
-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)');
-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');
-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');
-ERROR: Bad polygon external representation 'asdf'
+ERROR: invalid input syntax for polygon: "asdf"
SELECT '' AS four, POLYGON_TBL.*;
four | f1
------+---------------------
select has_table_privilege('nosuchuser','pg_shadow','select');
ERROR: user "nosuchuser" does not exist
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');
ERROR: user with ID 4293967297 does not exist
select has_table_privilege(1,'rule');
(1 row)
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
SELECT has_table_privilege('regressuser2', 'atest4', 'SELECT'); -- true
has_table_privilege
INSERT INTO RELTIME_TBL (f1) VALUES ('@ 14 seconds ago');
-- badly formatted reltimes
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');
-ERROR: Bad reltime external representation '@ 30 eons ago'
+ERROR: invalid input syntax for reltime: "@ 30 eons ago"
-- test reltime operators
SELECT '' AS six, RELTIME_TBL.*;
six | f1
-- test split_part
--
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";
joeuser
---------
-- statements.
INSERT INTO TIMESTAMP_TBL VALUES ('now');
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 ('yesterday');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Obsolete special values
INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
-ERROR: TIMESTAMP 'invalid' no longer supported
+ERROR: "invalid" is no longer supported
-- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
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');
-ERROR: TIMESTAMP 'Undefined Abstime' no longer supported
+ERROR: "Undefined Abstime" is no longer supported
-- 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.999999 1997 PST');
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 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 ('Dec 30 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges
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');
-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;
64 | d1
----+-----------------------------
(1 row)
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');
to_timestamp_10 | to_timestamp
-----------------+------------------------------
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone);
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
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 ('yesterday');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch');
-- Obsolete special values
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
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
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');
-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
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 ('Jan 01 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');
-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 ('Dec 30 17:32:01 1997');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 1997');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges
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');
-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;
64 | d1
----+---------------------------------
(1 row)
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');
to_timestamp_10 | to_timestamp
-----------------+------------------------------
-- badly formatted tintervals
INSERT INTO TINTERVAL_TBL (f1)
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)
VALUES ('["" "infinity"]');
-ERROR: Bad abstime external representation ''
+ERROR: invalid input syntax for abstime: ""
-- test tinterval operators
SELECT '' AS five, TINTERVAL_TBL.*;
five | f1
-- badly formatted tintervals
INSERT INTO TINTERVAL_TBL (f1)
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)
VALUES ('["" "infinity"]');
-ERROR: Bad abstime external representation ''
+ERROR: invalid input syntax for abstime: ""
-- test tinterval operators
SELECT '' AS five, TINTERVAL_TBL.*;
five | f1