Error message editing in utils/adt. Again thanks to Joe Conway for doing
authorTom Lane <[email protected]>
Sun, 27 Jul 2003 04:53:12 +0000 (04:53 +0000)
committerTom Lane <[email protected]>
Sun, 27 Jul 2003 04:53:12 +0000 (04:53 +0000)
the bulk of the heavy lifting ...

79 files changed:
src/backend/utils/adt/acl.c
src/backend/utils/adt/array_userfuncs.c
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/ascii.c
src/backend/utils/adt/bool.c
src/backend/utils/adt/cash.c
src/backend/utils/adt/char.c
src/backend/utils/adt/date.c
src/backend/utils/adt/datetime.c
src/backend/utils/adt/datum.c
src/backend/utils/adt/encode.c
src/backend/utils/adt/float.c
src/backend/utils/adt/format_type.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/geo_ops.c
src/backend/utils/adt/int.c
src/backend/utils/adt/int8.c
src/backend/utils/adt/like.c
src/backend/utils/adt/like_match.c
src/backend/utils/adt/mac.c
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/name.c
src/backend/utils/adt/network.c
src/backend/utils/adt/not_in.c
src/backend/utils/adt/numeric.c
src/backend/utils/adt/numutils.c
src/backend/utils/adt/oid.c
src/backend/utils/adt/oracle_compat.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/pgstatfuncs.c
src/backend/utils/adt/pseudotypes.c
src/backend/utils/adt/regexp.c
src/backend/utils/adt/regproc.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/sets.c
src/backend/utils/adt/tid.c
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/varbit.c
src/backend/utils/adt/varchar.c
src/backend/utils/adt/varlena.c
src/backend/utils/mb/wchar.c
src/include/mb/pg_wchar.h
src/include/utils/elog.h
src/test/regress/expected/abstime-solaris-1947.out
src/test/regress/expected/abstime.out
src/test/regress/expected/alter_table.out
src/test/regress/expected/bit.out
src/test/regress/expected/boolean.out
src/test/regress/expected/box.out
src/test/regress/expected/circle.out
src/test/regress/expected/copy2.out
src/test/regress/expected/date.out
src/test/regress/expected/float4-exp-three-digits.out
src/test/regress/expected/float4.out
src/test/regress/expected/float8-exp-three-digits.out
src/test/regress/expected/float8-fp-exception.out
src/test/regress/expected/float8-small-is-zero.out
src/test/regress/expected/float8.out
src/test/regress/expected/horology-no-DST-before-1970.out
src/test/regress/expected/horology-solaris-1947.out
src/test/regress/expected/horology.out
src/test/regress/expected/inet.out
src/test/regress/expected/int2.out
src/test/regress/expected/int4.out
src/test/regress/expected/interval.out
src/test/regress/expected/lseg.out
src/test/regress/expected/numeric.out
src/test/regress/expected/oid.out
src/test/regress/expected/path.out
src/test/regress/expected/point.out
src/test/regress/expected/polygon.out
src/test/regress/expected/privileges.out
src/test/regress/expected/reltime.out
src/test/regress/expected/strings.out
src/test/regress/expected/timestamp.out
src/test/regress/expected/timestamptz.out
src/test/regress/expected/tinterval-solaris-1947.out
src/test/regress/expected/tinterval.out

index 878f4ebe2a11053de2226b9bf616a3aeff712723..8c5f64a8ed2c6f8126e99d55789f2f3e0532de95 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.91 2003/06/27 00:33:25 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.92 2003/07/27 04:53:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -90,8 +90,12 @@ getid(const char *s, char *n)
        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;
        }
    }
@@ -157,26 +161,34 @@ aclparse(const char *s, AclItem *aip)
    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;
 
@@ -221,8 +233,10 @@ aclparse(const char *s, AclItem *aip)
                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;
@@ -247,14 +261,18 @@ aclparse(const char *s, AclItem *aip)
    {
        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);
@@ -280,7 +298,7 @@ allocacl(int n)
    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;
@@ -311,7 +329,10 @@ aclitemin(PG_FUNCTION_ARGS)
    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);
 }
 
@@ -373,8 +394,8 @@ aclitemout(PG_FUNCTION_ARGS)
        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)
@@ -482,7 +503,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
            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;
@@ -644,7 +665,10 @@ restart:
            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;
@@ -718,7 +742,9 @@ aclremove(PG_FUNCTION_ARGS)
        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 */
@@ -784,7 +810,9 @@ makeaclitem(PG_FUNCTION_ARGS)
    }
    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)
    {
@@ -840,7 +868,9 @@ convert_priv_string(text *priv_type_text)
    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 */
 }
 
@@ -1063,8 +1093,9 @@ convert_table_priv_string(text *priv_type_text)
    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 */
 }
 
@@ -1237,7 +1268,9 @@ convert_database_name(text *databasename)
 
    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;
 }
@@ -1272,8 +1305,9 @@ convert_database_priv_string(text *priv_type_text)
    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 */
 }
 
@@ -1448,7 +1482,9 @@ convert_function_name(text *functionname)
                                             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;
 }
@@ -1473,8 +1509,9 @@ convert_function_priv_string(text *priv_type_text)
    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 */
 }
 
@@ -1649,7 +1686,9 @@ convert_language_name(text *languagename)
                         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;
 }
@@ -1674,8 +1713,9 @@ convert_language_priv_string(text *priv_type_text)
    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 */
 }
 
@@ -1850,7 +1890,9 @@ convert_schema_name(text *schemaname)
                         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;
 }
@@ -1880,7 +1922,8 @@ convert_schema_priv_string(text *priv_type_text)
    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 */
 }
index 6c28b211cebb4c801169843f6c86c776fc39731a..7a9e89088a16488e2541fa5bce4eba9291168b32 100644 (file)
@@ -6,7 +6,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,6 +15,7 @@
 #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"
 
@@ -44,7 +45,10 @@ array_push(PG_FUNCTION_ARGS)
    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);
 
@@ -63,7 +67,9 @@ array_push(PG_FUNCTION_ARGS)
    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 */
    }
 
@@ -87,8 +93,9 @@ array_push(PG_FUNCTION_ARGS)
    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
@@ -169,16 +176,25 @@ array_cat(PG_FUNCTION_ARGS)
 
    /* 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;
@@ -211,7 +227,11 @@ array_cat(PG_FUNCTION_ARGS)
        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];
@@ -237,7 +257,11 @@ array_cat(PG_FUNCTION_ARGS)
        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) */
@@ -260,7 +284,11 @@ array_cat(PG_FUNCTION_ARGS)
        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.")));
        }
    }
 
@@ -302,9 +330,18 @@ create_singleton_array(FunctionCallInfo fcinfo,
    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;
 
index d0a876a877b1fc54bb9fa2bdb5ad8c3559012695..04e7f0f2515d570ca323be6765824ce4e82f3e8f 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.93 2003/07/01 00:04:38 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.94 2003/07/27 04:53:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -203,10 +203,17 @@ array_in(PG_FUNCTION_ARGS)
            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 */
@@ -215,7 +222,9 @@ array_in(PG_FUNCTION_ARGS)
            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
        {
@@ -223,12 +232,18 @@ array_in(PG_FUNCTION_ARGS)
            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++;
    }
@@ -237,7 +252,9 @@ array_in(PG_FUNCTION_ARGS)
    {
        /* 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;
@@ -246,7 +263,9 @@ array_in(PG_FUNCTION_ARGS)
    {
        /* 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++;
@@ -272,7 +291,9 @@ array_in(PG_FUNCTION_ARGS)
    }
 
    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,
@@ -328,14 +349,18 @@ ArrayCount(char *str, int *dim, char typdelim)
            {
                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;
@@ -344,7 +369,10 @@ ArrayCount(char *str, int *dim, char typdelim)
                    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)
@@ -355,7 +383,9 @@ ArrayCount(char *str, int *dim, char typdelim)
                    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;
@@ -447,7 +477,9 @@ ReadArrayStr(char *arrayStr,
            {
                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 '\\':
                    {
@@ -457,7 +489,9 @@ ReadArrayStr(char *arrayStr,
                        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 '\"':
@@ -476,7 +510,9 @@ ReadArrayStr(char *arrayStr,
                    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 */
@@ -489,7 +525,9 @@ ReadArrayStr(char *arrayStr,
                    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;
@@ -525,7 +563,10 @@ ReadArrayStr(char *arrayStr,
        }
        *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),
@@ -839,16 +880,29 @@ array_recv(PG_FUNCTION_ARGS)
 
    /* 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++)
@@ -889,8 +943,10 @@ array_recv(PG_FUNCTION_ARGS)
                         &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;
@@ -955,7 +1011,9 @@ ReadArrayBinary(StringInfo buf,
        /* 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
@@ -981,8 +1039,10 @@ ReadArrayBinary(StringInfo buf,
 
        /* 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;
    }
@@ -1060,8 +1120,10 @@ array_send(PG_FUNCTION_ARGS)
                         &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;
@@ -1407,7 +1469,9 @@ array_get_slice(ArrayType *array,
         * 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
@@ -1543,9 +1607,15 @@ array_set(ArrayType *array,
         * 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;
@@ -1582,7 +1652,9 @@ array_set(ArrayType *array,
    }
 
    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));
@@ -1602,7 +1674,9 @@ array_set(ArrayType *array,
                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]))
        {
@@ -1612,7 +1686,9 @@ array_set(ArrayType *array,
                extendafter = true;
            }
            else
-               elog(ERROR, "Invalid array subscripts");
+               ereport(ERROR,
+                       (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+                        errmsg("invalid array subscripts")));
        }
    }
 
@@ -1727,7 +1803,9 @@ array_set_slice(ArrayType *array,
        /*
         * 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 */
@@ -1763,7 +1841,9 @@ array_set_slice(ArrayType *array,
    }
 
    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));
@@ -1778,7 +1858,9 @@ array_set_slice(ArrayType *array,
    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)
@@ -1787,14 +1869,18 @@ array_set_slice(ArrayType *array,
                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 */
@@ -1803,7 +1889,9 @@ array_set_slice(ArrayType *array,
        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")));
    }
 
    /*
@@ -1813,7 +1901,9 @@ array_set_slice(ArrayType *array,
    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
@@ -1948,9 +2038,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
 
    /* 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);
@@ -2034,7 +2124,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
        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)
@@ -2129,9 +2221,30 @@ construct_md_array(Datum *elems,
    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);
 
@@ -2249,7 +2362,9 @@ array_eq(PG_FUNCTION_ARGS)
    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)
@@ -2415,7 +2530,9 @@ array_cmp(FunctionCallInfo fcinfo)
 
    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
@@ -2797,10 +2914,15 @@ array_type_coerce(PG_FUNCTION_ARGS)
        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.
@@ -2811,8 +2933,10 @@ array_type_coerce(PG_FUNCTION_ARGS)
         * 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))
@@ -2901,7 +3025,9 @@ accumArrayResult(ArrayBuildState *astate,
    }
 
    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++] =
index 0091ead7d3b1003f4687114a647e8b1a76cb92f9..fe7d6ba74ff7ba2a2e07548ad96d7d3920900fbb 100644 (file)
@@ -5,7 +5,7 @@
  *  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 $
  *
  *-----------------------------------------------------------------------
  */
@@ -63,8 +63,10 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *dest, int
    }
    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 */
    }
 
index ccc97683033da10bc2085dce9741553dc49a6a7e..9bfb887d4011c15b3df6667524f6ccfb570f12e0 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.27 2003/05/12 23:08:50 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.28 2003/07/27 04:53:03 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -75,7 +75,9 @@ boolin(PG_FUNCTION_ARGS)
            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);
index 4a4e13117ef8aa073c752bec87ec373d73934d0f..e33aad28d6400f1aef49526828eeb8ff9c821b19 100644 (file)
@@ -9,7 +9,7 @@
  * 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"
@@ -193,7 +193,9 @@ cash_in(PG_FUNCTION_ARGS)
        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);
 
@@ -290,7 +292,9 @@ cash_out(PG_FUNCTION_ARGS)
    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)
@@ -303,7 +307,9 @@ cash_out(PG_FUNCTION_ARGS)
    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);
    }
@@ -468,7 +474,9 @@ cash_div_flt8(PG_FUNCTION_ARGS)
    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);
@@ -518,7 +526,9 @@ cash_div_flt4(PG_FUNCTION_ARGS)
    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);
@@ -569,7 +579,9 @@ cash_div_int4(PG_FUNCTION_ARGS)
    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);
 
@@ -619,7 +631,9 @@ cash_div_int2(PG_FUNCTION_ARGS)
    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);
index 969f8946666683fd817275d83d3be40fcd704196..5bf3a025d1c02e4697709be71968141740924644 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.35 2003/05/12 23:08:50 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.36 2003/07/27 04:53:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -181,7 +181,9 @@ chardiv(PG_FUNCTION_ARGS)
    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);
 }
index 6519018c28aaa3c3c43dacf0c00a574f4b9591c4..ed449e524dd15eb1a9d7dd95879c42fb769fa9e7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.86 2003/07/24 04:38:19 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.87 2003/07/27 04:53:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -67,11 +67,15 @@ date_in(PG_FUNCTION_ARGS)
    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)
    {
@@ -79,8 +83,10 @@ date_in(PG_FUNCTION_ARGS)
            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;
 
@@ -89,7 +95,9 @@ date_in(PG_FUNCTION_ARGS)
            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;
@@ -356,7 +364,9 @@ timestamp_date(PG_FUNCTION_ARGS)
        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;
 
@@ -426,7 +436,9 @@ timestamptz_date(PG_FUNCTION_ARGS)
        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;
 
@@ -451,7 +463,9 @@ abstime_date(PG_FUNCTION_ARGS)
        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
@@ -510,7 +524,10 @@ text_date(PG_FUNCTION_ARGS)
                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;
@@ -548,11 +565,15 @@ time_in(PG_FUNCTION_ARGS)
    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);
@@ -978,7 +999,9 @@ timestamp_time(PG_FUNCTION_ARGS)
        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
 
@@ -1013,7 +1036,9 @@ timestamptz_time(PG_FUNCTION_ARGS)
        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
 
@@ -1228,7 +1253,10 @@ text_time(PG_FUNCTION_ARGS)
                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;
@@ -1259,9 +1287,12 @@ time_part(PG_FUNCTION_ARGS)
                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++)
@@ -1326,9 +1357,12 @@ time_part(PG_FUNCTION_ARGS)
            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;
        }
    }
@@ -1342,9 +1376,11 @@ time_part(PG_FUNCTION_ARGS)
    }
    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;
    }
 
@@ -1394,12 +1430,17 @@ timetz_in(PG_FUNCTION_ARGS)
    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);
@@ -1898,7 +1939,9 @@ timestamptz_timetz(PG_FUNCTION_ARGS)
        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));
 
@@ -1974,7 +2017,10 @@ text_timetz(PG_FUNCTION_ARGS)
                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;
@@ -2005,9 +2051,12 @@ timetz_part(PG_FUNCTION_ARGS)
                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++)
@@ -2086,9 +2135,12 @@ timetz_part(PG_FUNCTION_ARGS)
            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;
        }
    }
@@ -2102,9 +2154,12 @@ timetz_part(PG_FUNCTION_ARGS)
    }
    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;
    }
 
@@ -2129,9 +2184,12 @@ timetz_zone(PG_FUNCTION_ARGS)
                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++)
@@ -2163,7 +2221,10 @@ timetz_zone(PG_FUNCTION_ARGS)
    }
    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();
    }
 
@@ -2182,9 +2243,11 @@ timetz_izone(PG_FUNCTION_ARGS)
    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));
index 288203389bb10a47acb86cf47d386514ec80168a..1b9b4fcc821f16ee050c00d32e0578ee13b34f92 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.106 2003/06/25 21:14:14 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.107 2003/07/27 04:53:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1251,7 +1251,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
                        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;
 
@@ -1428,7 +1431,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
        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)
    {
@@ -1965,7 +1971,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
                        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;
 
@@ -2238,7 +2246,10 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
        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)
    {
@@ -2554,7 +2565,7 @@ DecodeNumberField(int len, char *str, int fmask,
  *
  * 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.
@@ -2611,7 +2622,7 @@ DecodeTimezone(char *str, int *tzp)
  *
  * 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)
@@ -2663,7 +2674,7 @@ 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
@@ -3715,7 +3726,7 @@ CheckDateTokenTable(const char *tablename, datetkn *base, unsigned int nel)
    {
        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);
index 9519ef2b674b80c3ac6b4bc0576e7c82aca5a13f..6bdfb84dd9673232f921a791a1aa6948ab74933c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.25 2002/09/04 20:31:27 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.26 2003/07/27 04:53:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -75,7 +75,10 @@ datumGetSize(Datum value, bool typByVal, int typLen)
            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)
@@ -84,12 +87,15 @@ datumGetSize(Datum value, bool typByVal, int typLen)
            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 */
        }
    }
index 21139b89f4f71fdf1f07f11e75f09c3b1c8e6247..949ce61206e335187110876da28e074678640034 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/encode.c,v 1.6 2001/11/05 17:46:29 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/encode.c,v 1.7 2003/07/27 04:53:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -50,7 +50,9 @@ binary_encode(PG_FUNCTION_ARGS)
 
    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);
@@ -59,7 +61,7 @@ binary_encode(PG_FUNCTION_ARGS)
 
    /* 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;
 
@@ -84,7 +86,9 @@ binary_decode(PG_FUNCTION_ARGS)
 
    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);
@@ -93,7 +97,7 @@ binary_decode(PG_FUNCTION_ARGS)
 
    /* 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;
 
@@ -141,7 +145,9 @@ get_hex(unsigned c)
        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;
 }
@@ -167,7 +173,10 @@ hex_decode(const uint8 *src, unsigned len, uint8 *dst)
        }
        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;
    }
@@ -281,7 +290,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
                else if (pos == 3)
                    end = 2;
                else
-                   elog(ERROR, "base64: unexpected '='");
+                   ereport(ERROR,
+                           (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                            errmsg("unexpected \"=\"")));
            }
            b = 0;
        }
@@ -291,7 +302,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
            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;
@@ -309,7 +322,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
    }
 
    if (pos != 0)
-       elog(ERROR, "base64: invalid end sequence");
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                errmsg("invalid end sequence")));
 
    return p - dst;
 }
@@ -416,7 +431,9 @@ esc_decode(const uint8 *src, unsigned srclen, uint8 *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++;
@@ -479,7 +496,9 @@ esc_dec_len(const uint8 *src, unsigned srclen)
            /*
             * 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++;
index 08ee7651792ca8fff9654f88b4721a9d00a16381..ac3fb2d149a79a7292a1587b62f278d89685fd80 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.89 2003/05/26 00:55:25 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.90 2003/07/27 04:53:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -115,7 +115,7 @@ static void CheckFloat8Val(double val);
  * 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)
@@ -128,9 +128,14 @@ 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 */
 }
@@ -139,7 +144,7 @@ CheckFloat4Val(double val)
  * 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)
@@ -152,9 +157,13 @@ 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 */
 }
 
@@ -184,12 +193,17 @@ float4in(PG_FUNCTION_ARGS)
        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)));
    }
 
    /*
@@ -280,12 +294,17 @@ float8in(PG_FUNCTION_ARGS)
        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);
@@ -535,7 +554,9 @@ float4div(PG_FUNCTION_ARGS)
    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;
@@ -597,7 +618,9 @@ float8div(PG_FUNCTION_ARGS)
    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;
 
@@ -847,7 +870,9 @@ dtoi4(PG_FUNCTION_ARGS)
    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);
@@ -864,7 +889,9 @@ dtoi2(PG_FUNCTION_ARGS)
    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);
@@ -909,7 +936,9 @@ ftoi4(PG_FUNCTION_ARGS)
    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);
@@ -926,7 +955,9 @@ ftoi2(PG_FUNCTION_ARGS)
    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);
@@ -1160,7 +1191,9 @@ dsqrt(PG_FUNCTION_ARGS)
    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);
 
@@ -1204,7 +1237,9 @@ dpow(PG_FUNCTION_ARGS)
        || !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);
@@ -1232,7 +1267,9 @@ dexp(PG_FUNCTION_ARGS)
        || !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);
@@ -1250,9 +1287,14 @@ dlog1(PG_FUNCTION_ARGS)
    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);
 
@@ -1271,9 +1313,14 @@ dlog10(PG_FUNCTION_ARGS)
    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);
 
@@ -1298,7 +1345,9 @@ dacos(PG_FUNCTION_ARGS)
        || !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);
@@ -1321,7 +1370,9 @@ dasin(PG_FUNCTION_ARGS)
        || !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);
@@ -1344,7 +1395,9 @@ datan(PG_FUNCTION_ARGS)
        || !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);
@@ -1368,7 +1421,9 @@ datan2(PG_FUNCTION_ARGS)
        || !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);
@@ -1391,7 +1446,9 @@ dcos(PG_FUNCTION_ARGS)
        || !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);
@@ -1414,7 +1471,9 @@ dcot(PG_FUNCTION_ARGS)
        || !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);
@@ -1438,7 +1497,9 @@ dsin(PG_FUNCTION_ARGS)
        || !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);
@@ -1461,7 +1522,9 @@ dtan(PG_FUNCTION_ARGS)
        || !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);
@@ -1777,7 +1840,9 @@ float48div(PG_FUNCTION_ARGS)
    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);
@@ -1837,7 +1902,9 @@ float84div(PG_FUNCTION_ARGS)
    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;
 
index c852ed26f3c954cacec3bd7a638cbde054a0e02e..5335b9a0b1e9129fee3d0f3a5ba912030eb1724b 100644 (file)
@@ -8,7 +8,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -133,8 +133,7 @@ format_type_internal(Oid type_oid, int32 typemod,
        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);
 
@@ -159,8 +158,7 @@ format_type_internal(Oid type_oid, int32 typemod,
            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;
@@ -312,7 +310,7 @@ format_type_internal(Oid type_oid, int32 typemod,
                        fieldstr = "";
                        break;
                    default:
-                       elog(LOG, "Invalid INTERVAL typmod 0x%x", typemod);
+                       elog(ERROR, "invalid INTERVAL typmod: 0x%x", typemod);
                        fieldstr = "";
                        break;
                }
index 10db8312fb40cfa7afd06d8b1e7376b7bd915b86..1df3593ee969acd689e14cf96247e2ddfd2a0eed 100644 (file)
@@ -1,7 +1,7 @@
 /* -----------------------------------------------------------------------
  * 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
@@ -961,7 +961,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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))
            {
@@ -978,7 +980,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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))
            {
@@ -1005,12 +1009,16 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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;
@@ -1023,12 +1031,16 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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))
            {
@@ -1050,7 +1062,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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))
@@ -1061,7 +1075,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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))
@@ -1072,7 +1088,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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;
@@ -1082,7 +1100,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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;
@@ -1101,14 +1121,18 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
            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;
@@ -1132,7 +1156,7 @@ parse_format(FormatNode *node, char *str, KeyWord *kw,
                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;
@@ -1343,7 +1367,7 @@ dump_node(FormatNode *node, int max)
            return;
        }
        else
-           elog(DEBUG_elog_output, "%d:\t UnKnown NODE !!!", a);
+           elog(DEBUG_elog_output, "%d:\t unknown NODE!", a);
 
    }
 }
@@ -1367,7 +1391,9 @@ get_th(char *num, int type)
 
    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
@@ -1628,7 +1654,9 @@ strdigits_len(char *str)
    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:
@@ -1972,15 +2000,19 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
                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)
 
@@ -2614,7 +2646,7 @@ DCH_cache_getnew(char *str)
        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++)
        {
@@ -2788,17 +2820,16 @@ timestamp_to_char(PG_FUNCTION_ARGS)
    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();
@@ -2813,18 +2844,17 @@ timestamptz_to_char(PG_FUNCTION_ARGS)
    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();
@@ -3000,7 +3030,9 @@ to_timestamp(PG_FUNCTION_ARGS)
    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;
@@ -3037,7 +3069,10 @@ to_timestamp(PG_FUNCTION_ARGS)
        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)
@@ -3069,7 +3104,9 @@ to_timestamp(PG_FUNCTION_ARGS)
        {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)];
 
@@ -3104,7 +3141,9 @@ to_timestamp(PG_FUNCTION_ARGS)
    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);
 }
@@ -3190,7 +3229,7 @@ NUM_cache_getnew(char *str)
                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 */
@@ -3477,7 +3516,7 @@ get_last_relevant_decnum(char *num)
               *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)
@@ -3523,7 +3562,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
    {
 
 #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
 
        /*
@@ -3535,7 +3574,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
            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))
            {
@@ -3554,7 +3593,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
        }
 
 #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
 
        /*
@@ -3595,7 +3634,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
            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
 
        /*
@@ -3606,7 +3645,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
    {
 
 #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 == '.')
        {
@@ -3621,7 +3660,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
            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))
            {
@@ -3661,8 +3701,7 @@ NUM_numpart_to_char(NUMProc *Np, int id)
     * 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,
@@ -3863,7 +3902,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
    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;
index 1412a1c68212655ab78fa9de9614df032c19b684..9934d6a3e0d610a5cf2953989abe36e9574e8fd7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.77 2003/05/13 18:03:07 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.78 2003/07/27 04:53:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -287,7 +287,9 @@ path_encode(bool closed, int npts, Point *pt)
 
    /* 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);
 
@@ -308,7 +310,10 @@ path_encode(bool closed, int npts, Point *pt)
    {
        *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;
@@ -380,7 +385,9 @@ box_in(PG_FUNCTION_ARGS)
 
    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)
@@ -891,12 +898,17 @@ line_in(PG_FUNCTION_ARGS)
 
    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
 
@@ -960,7 +972,9 @@ line_out(PG_FUNCTION_ARGS)
 
    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
 
@@ -973,7 +987,9 @@ line_out(PG_FUNCTION_ARGS)
 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;
 }
 
@@ -983,7 +999,9 @@ line_recv(PG_FUNCTION_ARGS)
 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;
 }
 
@@ -1306,7 +1324,9 @@ path_in(PG_FUNCTION_ARGS)
    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))
@@ -1327,7 +1347,9 @@ path_in(PG_FUNCTION_ARGS)
 
    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);
 
@@ -1362,7 +1384,9 @@ path_recv(PG_FUNCTION_ARGS)
    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);
@@ -1701,7 +1725,9 @@ point_in(PG_FUNCTION_ARGS)
    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));
 
@@ -1927,7 +1953,9 @@ lseg_in(PG_FUNCTION_ARGS)
 
    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]);
@@ -2517,7 +2545,9 @@ dist_lb(PG_FUNCTION_ARGS)
 #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();
 }
@@ -3028,7 +3058,9 @@ close_lb(PG_FUNCTION_ARGS)
 #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();
 }
@@ -3305,7 +3337,9 @@ make_bound_box(POLYGON *poly)
        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")));
 }
 
 /*------------------------------------------------------------------
@@ -3327,7 +3361,9 @@ poly_in(PG_FUNCTION_ARGS)
    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 */
@@ -3337,7 +3373,9 @@ poly_in(PG_FUNCTION_ARGS)
 
    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);
 
@@ -3375,7 +3413,9 @@ poly_recv(PG_FUNCTION_ARGS)
 
    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 */
@@ -3683,7 +3723,9 @@ poly_distance(PG_FUNCTION_ARGS)
    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();
 }
@@ -3762,7 +3804,9 @@ point_div(PG_FUNCTION_ARGS)
    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;
@@ -3881,7 +3925,9 @@ path_add(PG_FUNCTION_ARGS)
    /* 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);
 
@@ -3989,7 +4035,9 @@ path_center(PG_FUNCTION_ARGS)
    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();
 }
@@ -4004,7 +4052,9 @@ path_poly(PG_FUNCTION_ARGS)
 
    /* 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);
@@ -4169,7 +4219,9 @@ circle_in(PG_FUNCTION_ARGS)
    }
 
    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++;
@@ -4177,7 +4229,9 @@ circle_in(PG_FUNCTION_ARGS)
        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)
    {
@@ -4190,11 +4244,15 @@ circle_in(PG_FUNCTION_ARGS)
                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);
 }
@@ -4214,13 +4272,17 @@ circle_out(PG_FUNCTION_ARGS)
    *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;
@@ -4245,7 +4307,9 @@ circle_recv(PG_FUNCTION_ARGS)
    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);
 }
@@ -4736,15 +4800,24 @@ circle_poly(PG_FUNCTION_ARGS)
    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;
@@ -4777,7 +4850,9 @@ poly_circle(PG_FUNCTION_ARGS)
    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));
 
@@ -4798,7 +4873,9 @@ poly_circle(PG_FUNCTION_ARGS)
    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);
 }
index 141312d66742b61e07a8cf74d6bcb5bd6fc50854..1c25df095622c3b6ba5ac451cba0927b17edd422 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.54 2003/05/09 15:44:40 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.55 2003/07/27 04:53:06 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -121,7 +121,10 @@ int2vectorin(PG_FUNCTION_ARGS)
    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;
 
@@ -281,10 +284,10 @@ i4toi2(PG_FUNCTION_ARGS)
 {
    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);
 }
@@ -640,7 +643,9 @@ int4div(PG_FUNCTION_ARGS)
    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);
 }
@@ -703,7 +708,9 @@ int2div(PG_FUNCTION_ARGS)
    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);
 }
@@ -742,7 +749,9 @@ int24div(PG_FUNCTION_ARGS)
    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);
 }
@@ -781,7 +790,9 @@ int42div(PG_FUNCTION_ARGS)
    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);
 }
@@ -793,7 +804,9 @@ int4mod(PG_FUNCTION_ARGS)
    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);
 }
@@ -805,7 +818,9 @@ int2mod(PG_FUNCTION_ARGS)
    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);
 }
@@ -817,7 +832,9 @@ int24mod(PG_FUNCTION_ARGS)
    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);
 }
@@ -829,7 +846,9 @@ int42mod(PG_FUNCTION_ARGS)
    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);
 }
index 30ec836cd6d0d0a07f2e0469722b5f2ec85f8134..123c5e72257c526391693ed8e9dcbbaaa34518fb 100644 (file)
@@ -7,7 +7,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -36,7 +36,7 @@
 /*
  * 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
@@ -83,7 +83,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
        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 */
@@ -96,7 +98,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
            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;
    }
@@ -107,7 +111,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
        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;
@@ -139,7 +145,7 @@ int8out(PG_FUNCTION_ARGS)
    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);
@@ -515,7 +521,9 @@ int8div(PG_FUNCTION_ARGS)
    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);
 }
@@ -542,7 +550,9 @@ int8mod(PG_FUNCTION_ARGS)
    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;
@@ -638,7 +648,9 @@ int84div(PG_FUNCTION_ARGS)
    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);
 }
@@ -677,7 +689,9 @@ int48div(PG_FUNCTION_ARGS)
    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);
 }
@@ -767,7 +781,9 @@ int84(PG_FUNCTION_ARGS)
 
    /* 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);
 }
@@ -790,7 +806,9 @@ int82(PG_FUNCTION_ARGS)
 
    /* 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);
 }
@@ -826,7 +844,9 @@ dtoi8(PG_FUNCTION_ARGS)
    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);
 }
@@ -863,7 +883,9 @@ ftoi8(PG_FUNCTION_ARGS)
    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);
 }
@@ -878,7 +900,9 @@ i8tooid(PG_FUNCTION_ARGS)
 
    /* 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);
 }
index fca4fc77b303895c70363a8b43f514f57c8488c8..0f832aa6e13b0f917a08327a2bc1890dac0995fc 100644 (file)
@@ -11,7 +11,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -448,7 +448,11 @@ like_escape_bytea(PG_FUNCTION_ARGS)
         */
        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);
 
        /*
index 60bc186c7e0f3a0af09b02f0dac3e70cf3e2e7a7..9530873ae3f634b0d0a1ee7602e5ec3bc1ad2179 100644 (file)
@@ -19,7 +19,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -286,7 +286,11 @@ do_like_escape(text *pat, text *esc)
         */
        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);
 
        /*
index 01111e3c2fb56a873117b3de96ed01f8d8b64f6c..36ae41f9c71edd50c3819d05e9fa5aa901b0d6ae 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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"
@@ -60,12 +60,16 @@ macaddr_in(PG_FUNCTION_ARGS)
        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));
 
@@ -181,7 +185,9 @@ text_macaddr(PG_FUNCTION_ARGS)
 
    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';
index 88943a7667609e25ed03c20a7760c221d7c25d88..4c9990194ea71ae77407ec4133b02852bd1c0c34 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.109 2003/07/17 00:55:37 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.110 2003/07/27 04:53:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -239,8 +239,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
                 */
                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)));
            }
        }
    }
@@ -273,8 +275,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
                 */
                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])));
            }
        }
    }
@@ -367,11 +371,15 @@ abstimein(PG_FUNCTION_ARGS)
                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)
    {
@@ -401,7 +409,8 @@ abstimein(PG_FUNCTION_ARGS)
            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;
    };
@@ -513,7 +522,7 @@ abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
        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();
@@ -617,7 +626,9 @@ timestamp_abstime(PG_FUNCTION_ARGS)
    }
    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;
    }
 
@@ -641,7 +652,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
    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;
 
@@ -656,8 +669,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
        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;
    };
 
@@ -685,7 +699,9 @@ timestamptz_abstime(PG_FUNCTION_ARGS)
        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;
    }
 
@@ -709,7 +725,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
    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;
 
@@ -724,8 +742,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
        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;
    };
 
@@ -755,11 +774,15 @@ reltimein(PG_FUNCTION_ARGS)
    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)
    {
@@ -769,7 +792,8 @@ reltimein(PG_FUNCTION_ARGS)
            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;
    }
@@ -851,7 +875,10 @@ tintervalin(PG_FUNCTION_ARGS)
 
    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  */
@@ -911,7 +938,10 @@ tintervalrecv(PG_FUNCTION_ARGS)
    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]));
 
@@ -1000,7 +1030,9 @@ reltime_interval(PG_FUNCTION_ARGS)
    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;
index 37dca0b0c6347a6cb8232f927b4d8e8d1f0e63f5..47af778f3df99da3341f5af07e98036cf9067e29 100644 (file)
@@ -14,7 +14,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.46 2003/05/15 15:50:18 petere Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.47 2003/07/27 04:53:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -48,12 +48,10 @@ namein(PG_FUNCTION_ARGS)
    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);
 
@@ -87,7 +85,11 @@ namerecv(PG_FUNCTION_ARGS)
 
    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);
index 213bf5d2f6655884c0bf20020d0afd22062e873e..d238098c25932a80fd5abc96388a7e9bce84b835 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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
  */
@@ -85,17 +85,23 @@ network_in(char *src, int type)
    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
@@ -139,7 +145,10 @@ inet_out(PG_FUNCTION_ARGS)
    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)
    {
@@ -180,18 +189,25 @@ inet_recv(PG_FUNCTION_ARGS)
 
    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);
@@ -207,7 +223,10 @@ inet_recv(PG_FUNCTION_ARGS)
    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);
@@ -291,7 +310,9 @@ inet_set_masklen(PG_FUNCTION_ARGS)
             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));
@@ -477,7 +498,9 @@ network_host(PG_FUNCTION_ARGS)
    /* 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)
@@ -501,7 +524,10 @@ network_show(PG_FUNCTION_ARGS)
 
    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)
    {
@@ -534,8 +560,9 @@ network_abbrev(PG_FUNCTION_ARGS)
                    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);
@@ -818,7 +845,7 @@ convert_network_to_scalar(Datum value, Oid typid)
     * 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;
 }
 
index ef29e065138b92e56b6474ccd4ff6f00e8f1ef93..c3f0aee5cb9c3a27409b1d9f5dd2ac76a52a2ee7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.32 2002/09/04 20:31:28 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.33 2003/07/27 04:53:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -59,7 +59,10 @@ int4notin(PG_FUNCTION_ARGS)
    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);
index ea34a5579c20e08fc5d9fa5f6693dba0eeac7e09..476d3d5b5ce5f84bfdd5e31c87a2734380b91e4c 100644 (file)
@@ -14,7 +14,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -390,7 +390,9 @@ numeric_recv(PG_FUNCTION_ARGS)
 
    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);
 
@@ -399,14 +401,19 @@ numeric_recv(PG_FUNCTION_ARGS)
    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;
    }
 
@@ -1610,14 +1617,18 @@ numeric_int4(PG_FUNCTION_ARGS)
 
    /* 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);
 
@@ -1626,7 +1637,9 @@ numeric_int4(PG_FUNCTION_ARGS)
 
    /* 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);
 }
@@ -1660,14 +1673,18 @@ numeric_int8(PG_FUNCTION_ARGS)
 
    /* 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);
 
@@ -1704,14 +1721,18 @@ numeric_int2(PG_FUNCTION_ARGS)
 
    /* 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);
 
@@ -1720,7 +1741,9 @@ numeric_int2(PG_FUNCTION_ARGS)
 
    /* 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);
 }
@@ -1903,7 +1926,7 @@ do_numeric_accum(ArrayType *transarray, Numeric newval)
                      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];
@@ -1994,7 +2017,7 @@ numeric_avg(PG_FUNCTION_ARGS)
                      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 */
@@ -2030,7 +2053,7 @@ numeric_variance(PG_FUNCTION_ARGS)
                      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]);
@@ -2106,7 +2129,7 @@ numeric_stddev(PG_FUNCTION_ARGS)
                      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]);
@@ -2296,7 +2319,7 @@ int2_avg_accum(PG_FUNCTION_ARGS)
     * 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++;
@@ -2316,7 +2339,7 @@ int4_avg_accum(PG_FUNCTION_ARGS)
     * 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++;
@@ -2334,7 +2357,7 @@ int8_avg(PG_FUNCTION_ARGS)
                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 */
@@ -2542,7 +2565,9 @@ set_var_from_str(const char *str, NumericVar *dest)
    }
 
    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);
 
@@ -2563,7 +2588,10 @@ set_var_from_str(const char *str, NumericVar *dest)
        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++;
        }
@@ -2584,11 +2612,17 @@ set_var_from_str(const char *str, NumericVar *dest)
        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)
@@ -2599,7 +2633,10 @@ set_var_from_str(const char *str, NumericVar *dest)
    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++;
    }
 
@@ -2893,7 +2930,9 @@ make_result(NumericVar *var)
    /* 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;
@@ -2961,9 +3000,11 @@ apply_typmod(NumericVar *var, int32 typmod)
 #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;
@@ -3098,7 +3139,10 @@ numeric_to_double_no_overflow(Numeric num)
    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);
@@ -3121,7 +3165,10 @@ numericvar_to_double_no_overflow(NumericVar *var)
    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);
@@ -3613,7 +3660,9 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result,
     * 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
@@ -4006,7 +4055,9 @@ sqrt_var(NumericVar *arg, NumericVar *result, int rscale)
    }
 
    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);
@@ -4094,7 +4145,9 @@ exp_var(NumericVar *arg, NumericVar *result, int rscale)
        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 */
@@ -4218,7 +4271,9 @@ ln_var(NumericVar *arg, NumericVar *result, int rscale)
    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;
 
@@ -4462,7 +4517,9 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale)
    {
        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;
index a88330cec1764ed26ffe452c60905e4e5e6bba4d..a73842785e52c90b43f577bb8ebd9d3496fb3341 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * 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;
 }
index 1a0a89605bb17bcbd365bdfd77a9471ac9f62bdc..aa070c2694cf6aaeb73c65cf58629709455cdf96 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.48 2003/05/09 15:44:40 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.49 2003/07/27 04:53:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -34,7 +34,6 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
    Oid         result;
 
    errno = 0;
-
    cvt = strtoul(s, &endptr, 10);
 
    /*
@@ -44,12 +43,21 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
     * Note that for historical reasons we accept an empty string as
     * 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)
    {
@@ -62,8 +70,10 @@ oidin_subr(const char *funcname, const char *s, char **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;
@@ -83,8 +93,9 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
 #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;
@@ -160,7 +171,9 @@ oidvectorin(PG_FUNCTION_ARGS)
    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;
 
index 5cfc215d71309f495bfc2b6de428ddc64af25e2f..8fd63164f0eedb7cabed39853113d0315693272f 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.45 2003/07/27 03:16:20 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.46 2003/07/27 04:53:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -201,7 +201,9 @@ lpad(PG_FUNCTION_ARGS)
 
    /* 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);
 
@@ -296,7 +298,9 @@ rpad(PG_FUNCTION_ARGS)
 
    /* 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;
@@ -917,7 +921,9 @@ repeat(PG_FUNCTION_ARGS)
        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);
index 2ebea73036a7f3b0821ce7ce6397e4146b7f702f..26bde944fa8d8c2a18bc13fd0e37926c0ab6950c 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Portions Copyright (c) 2002, PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.20 2002/10/18 20:44:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.21 2003/07/27 04:53:07 tgl Exp $
  *
  *-----------------------------------------------------------------------
  */
@@ -157,7 +157,7 @@ lc_collate_is_c(void)
        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;
index 083bb1374a429eff06b8917c8a759c84972177d8..df8c8e92cc513fa40d672bdebbed30c7d0a4e8d3 100644 (file)
@@ -186,12 +186,16 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
 
    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;
index 1a997ed97798774c9253a446464a9fb628272752..480c334b15b655fa8e55c8ec6a6f7ac7a088800c 100644 (file)
@@ -16,7 +16,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.7 2003/05/13 18:03:07 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.8 2003/07/27 04:53:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -33,7 +33,9 @@
 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 */
 }
@@ -44,7 +46,9 @@ record_in(PG_FUNCTION_ARGS)
 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 */
 }
@@ -55,7 +59,9 @@ record_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -66,7 +72,9 @@ record_recv(PG_FUNCTION_ARGS)
 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 */
 }
@@ -134,7 +142,9 @@ cstring_send(PG_FUNCTION_ARGS)
 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 */
 }
@@ -145,7 +155,9 @@ any_in(PG_FUNCTION_ARGS)
 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 */
 }
@@ -157,7 +169,9 @@ any_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -183,7 +197,9 @@ anyarray_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -231,7 +247,9 @@ void_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -242,7 +260,9 @@ trigger_in(PG_FUNCTION_ARGS)
 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 */
 }
@@ -254,7 +274,9 @@ trigger_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -265,7 +287,9 @@ language_handler_in(PG_FUNCTION_ARGS)
 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 */
 }
@@ -277,7 +301,9 @@ language_handler_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -288,7 +314,9 @@ internal_in(PG_FUNCTION_ARGS)
 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 */
 }
@@ -300,7 +328,9 @@ internal_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -311,7 +341,9 @@ opaque_in(PG_FUNCTION_ARGS)
 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 */
 }
@@ -323,7 +355,9 @@ opaque_out(PG_FUNCTION_ARGS)
 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 */
 }
@@ -334,7 +368,9 @@ anyelement_in(PG_FUNCTION_ARGS)
 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 */
 }
index 56f78422bcc293f9e3b28cd0b9c9a542eed531cf..8853308663294311615c5bc742ad2fedd66cf3e1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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
@@ -171,7 +171,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
 
        pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
        /* XXX should we pg_regfree here? */
-       elog(ERROR, "Invalid regular expression: %s", errMsg);
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
+                errmsg("invalid regular expression: %s", errMsg)));
    }
 
    /*
@@ -182,7 +184,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
    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;
@@ -450,7 +454,10 @@ similar_escape(PG_FUNCTION_ARGS)
        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 */
index 09dba50cde36f64d177f74b2d28dfa09e48cb644..fb9d5a2e458a460b802af2bcec7d89ce933e35ea 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.77 2003/05/12 23:08:50 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.78 2003/07/27 04:53:09 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -112,10 +112,16 @@ regprocin(PG_FUNCTION_ARGS)
        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);
    }
 
@@ -127,10 +133,14 @@ regprocin(PG_FUNCTION_ARGS)
    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;
 
@@ -275,7 +285,9 @@ regprocedurein(PG_FUNCTION_ARGS)
    }
 
    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;
 
@@ -450,10 +462,15 @@ regoperin(PG_FUNCTION_ARGS)
        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);
    }
 
@@ -465,10 +482,14 @@ regoperin(PG_FUNCTION_ARGS)
    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;
 
@@ -613,9 +634,15 @@ regoperatorin(PG_FUNCTION_ARGS)
    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';
@@ -633,7 +660,9 @@ regoperatorin(PG_FUNCTION_ARGS)
    }
 
    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;
 
@@ -803,7 +832,9 @@ regclassin(PG_FUNCTION_ARGS)
        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 */
 
@@ -967,7 +998,9 @@ regtypein(PG_FUNCTION_ARGS)
        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 */
 
@@ -1072,10 +1105,14 @@ stringToQualifiedNameList(const char *string, const char *caller)
    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)
    {
@@ -1132,7 +1169,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
            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';
@@ -1146,7 +1185,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
            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 */
@@ -1162,7 +1204,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
        {
            /* 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;
@@ -1192,7 +1236,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
            }
        }
        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 == ',')
        {
@@ -1224,7 +1271,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
            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)++;
    }
index 63d5fee0af19a65837053a8189b461aff3685a90..8f896084954af143173578233df52b9477ab48e4 100644 (file)
@@ -3,7 +3,7 @@
  *             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.
  *
@@ -197,7 +197,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
     * 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
@@ -212,7 +212,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
        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);
    }
 
@@ -223,11 +223,11 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
    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] = '-';
@@ -252,7 +252,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
     * 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?
@@ -313,7 +313,7 @@ pg_do_getviewdef(Oid viewoid)
     * 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
@@ -329,7 +329,7 @@ pg_do_getviewdef(Oid viewoid)
        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);
    }
 
@@ -365,7 +365,7 @@ pg_do_getviewdef(Oid viewoid)
     * Disconnect from SPI manager
     */
    if (SPI_finish() != SPI_OK_FINISH)
-       elog(ERROR, "get_viewdef: SPI_finish() failed");
+       elog(ERROR, "SPI_finish failed");
 
    return ruledef;
 }
@@ -404,8 +404,7 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
    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);
 
@@ -552,7 +551,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
                            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;
@@ -565,7 +564,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
                               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);
 
    /*
@@ -575,7 +574,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
                           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);
 
    /*
@@ -745,7 +745,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
 
    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);
@@ -765,7 +765,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                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);
@@ -778,7 +778,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                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);
@@ -798,8 +798,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                        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;
                }
@@ -824,8 +824,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                        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;
                }
@@ -850,8 +850,8 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                        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;
                }
@@ -881,7 +881,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                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);
@@ -908,7 +908,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                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));
@@ -942,8 +942,10 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
                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;
    }
 
@@ -1344,8 +1346,10 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
            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;
    }
 
@@ -1546,7 +1550,7 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
            break;
 
        default:
-           elog(ERROR, "get_query_def: unknown query command type %d",
+           elog(ERROR, "unrecognized query command type: %d",
                 query->commandType);
            break;
    }
@@ -1781,7 +1785,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
                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)
@@ -1793,7 +1797,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
    }
    else
    {
-       elog(ERROR, "get_setop_query: unexpected node %d",
+       elog(ERROR, "unrecognized node type: %d",
             (int) nodeTag(setOp));
    }
 }
@@ -1853,7 +1857,7 @@ get_insert_query_def(Query *query, deparse_context *context)
        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;
    }
 
@@ -2005,7 +2009,10 @@ get_utility_query_def(Query *query, deparse_context *context)
                                              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");
+   }
 }
 
 
@@ -2036,8 +2043,7 @@ get_names_for_var(Var *var, deparse_context *context,
    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 */
@@ -2050,8 +2056,7 @@ get_names_for_var(Var *var, deparse_context *context,
    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 */
@@ -2360,7 +2365,7 @@ get_rule_expr(Node *node, deparse_context *context,
                        break;
 
                    default:
-                       elog(ERROR, "get_rule_expr: unknown boolop %d",
+                       elog(ERROR, "unrecognized boolop: %d",
                             (int) expr->boolop);
                }
            }
@@ -2394,7 +2399,7 @@ get_rule_expr(Node *node, deparse_context *context,
                /* 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);
@@ -2536,7 +2541,7 @@ get_rule_expr(Node *node, deparse_context *context,
                        appendStringInfo(buf, " IS NOT NULL)");
                        break;
                    default:
-                       elog(ERROR, "get_rule_expr: unexpected nulltesttype %d",
+                       elog(ERROR, "unrecognized nulltesttype: %d",
                             (int) ntest->nulltesttype);
                }
            }
@@ -2569,7 +2574,7 @@ get_rule_expr(Node *node, deparse_context *context,
                        appendStringInfo(buf, " IS NOT UNKNOWN)");
                        break;
                    default:
-                       elog(ERROR, "get_rule_expr: unexpected booltesttype %d",
+                       elog(ERROR, "unrecognized booltesttype: %d",
                             (int) btest->booltesttype);
                }
            }
@@ -2611,7 +2616,7 @@ get_rule_expr(Node *node, deparse_context *context,
            break;
 
        default:
-           elog(ERROR, "get_rule_expr: unknown node type %d", nodeTag(node));
+           elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
            break;
    }
 }
@@ -2652,7 +2657,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
                            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)
        {
@@ -2671,7 +2676,7 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
                                                        InvalidOid));
                break;
            default:
-               elog(ERROR, "get_rule_expr: bogus oprkind");
+               elog(ERROR, "bogus oprkind: %d", optup->oprkind);
        }
        ReleaseSysCache(tp);
    }
@@ -2849,7 +2854,7 @@ get_const_expr(Const *constval, deparse_context *context)
                             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);
 
@@ -3039,8 +3044,8 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
            break;
 
        default:
-           elog(ERROR, "get_sublink_expr: unsupported sublink type %d",
-                sublink->subLinkType);
+           elog(ERROR, "unrecognized sublink type: %d",
+                (int) sublink->subLinkType);
            break;
    }
 
@@ -3132,7 +3137,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
                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)
@@ -3204,7 +3209,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
                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);
@@ -3254,8 +3259,8 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
        }
    }
    else
-       elog(ERROR, "get_from_clause_item: unexpected node type %d",
-            nodeTag(jtnode));
+       elog(ERROR, "unrecognized node type: %d",
+            (int) nodeTag(jtnode));
 }
 
 /*
@@ -3361,7 +3366,8 @@ tleIsArrayAssign(TargetEntry *tle)
     */
    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;
 }
 
@@ -3483,7 +3489,7 @@ generate_relation_name(Oid relid)
                        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 */
@@ -3525,7 +3531,7 @@ generate_function_name(Oid funcid, int nargs, Oid *argtypes)
                             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);
@@ -3579,7 +3585,7 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2)
                             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);
 
@@ -3600,8 +3606,7 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2)
            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;
    }
@@ -3664,7 +3669,7 @@ get_relid_attribute_name(Oid relid, AttrNumber attnum)
 
    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;
 }
index 917bdc2fe20dbcbf673b75e9601a230f0ab1439e..79c4af76a65378cf92198b69753939c494423228 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.141 2003/07/17 22:20:14 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.142 2003/07/27 04:53:09 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -939,7 +939,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
                                                             prefix->constvalue));
                break;
            default:
-               elog(ERROR, "patternsel: unexpected consttype %u",
+               elog(ERROR, "unrecognized consttype: %u",
                     prefix->consttype);
                return DEFAULT_MATCH_SEL;
        }
@@ -956,7 +956,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
        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),
@@ -1136,7 +1136,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
                                                          varRelid, jointype);
                break;
            default:
-               elog(ERROR, "booltestsel: unexpected booltesttype %d",
+               elog(ERROR, "unrecognized booltesttype: %d",
                     (int) booltesttype);
                selec = 0.0;    /* Keep compiler quiet */
                break;
@@ -1213,7 +1213,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
                    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;
@@ -1254,7 +1254,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
                    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;
@@ -1284,7 +1284,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
                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;
@@ -1319,7 +1319,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
            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 */
    }
@@ -1373,7 +1373,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
                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 */
        }
@@ -2500,7 +2500,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
     * 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;
 }
 
@@ -2684,7 +2684,7 @@ convert_string_datum(Datum value, Oid typid)
             * 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;
    }
 
@@ -2882,7 +2882,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
     * 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;
 }
 
@@ -3111,7 +3111,9 @@ like_fixed_prefix(Const *patt_const, bool case_insensitive,
    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)
    {
@@ -3194,7 +3196,9 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive,
     * 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));
@@ -3337,7 +3341,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype,
            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;
    }
@@ -3368,8 +3372,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon)
 
    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,
@@ -3390,8 +3393,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon)
 
        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,
@@ -3472,7 +3474,9 @@ like_selectivity(Const *patt_const, bool case_insensitive)
    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)
    {
@@ -3618,7 +3622,9 @@ regex_selectivity(Const *patt_const, bool case_insensitive)
     * 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));
@@ -3662,7 +3668,7 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
            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;
    }
index 6cb06735b15f8f4783c19fc678bb330f739580f5..a611f7271a800787b90afe4ab57648943e2486b7 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.55 2002/12/13 19:45:56 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.56 2003/07/27 04:53:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -83,7 +83,7 @@ SetDefine(char *querystr, Oid elemType)
                         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
@@ -201,7 +201,10 @@ seteval(PG_FUNCTION_ARGS)
        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);
index 8df09b2464bd944b7925ba3e1e858ce24c095ca6..0108eb3f705f0f51cb08cc9209ce8093736dbecc 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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().
@@ -61,17 +61,27 @@ tidin(PG_FUNCTION_ARGS)
            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));
@@ -216,8 +226,9 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
        }
    }
    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++)
    {
@@ -231,12 +242,13 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
                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)
@@ -249,7 +261,7 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
            break;
        }
    }
-   elog(ERROR, "currtid can't handle this view");
+   elog(ERROR, "currtid cannot handle this view");
    return (Datum) 0;
 }
 
index cef46084a1c4612b9d3f00a8e325b73cf6f1718f..fb84596beeabd6f48aff5e54d76718253d57f1c6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.87 2003/07/26 15:17:36 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.88 2003/07/27 04:53:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -78,17 +78,25 @@ timestamp_in(PG_FUNCTION_ARGS)
    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:
@@ -104,12 +112,16 @@ timestamp_in(PG_FUNCTION_ARGS)
            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);
    }
 
@@ -137,7 +149,9 @@ timestamp_out(PG_FUNCTION_ARGS)
    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);
@@ -238,8 +252,10 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
        && (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
@@ -291,18 +307,25 @@ timestamptz_in(PG_FUNCTION_ARGS)
    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:
@@ -318,12 +341,16 @@ timestamptz_in(PG_FUNCTION_ARGS)
            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);
    }
 
@@ -352,7 +379,9 @@ timestamptz_out(PG_FUNCTION_ARGS)
    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);
@@ -448,11 +477,17 @@ interval_in(PG_FUNCTION_ARGS)
    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));
 
@@ -460,16 +495,21 @@ interval_in(PG_FUNCTION_ARGS)
    {
        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);
@@ -489,10 +529,10 @@ interval_out(PG_FUNCTION_ARGS)
    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);
@@ -781,14 +821,16 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
 #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
@@ -1045,7 +1087,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
    }
 
    return 0;
-}  /* timestamp2tm() */
+}
 
 
 /* tm2timestamp()
@@ -1053,7 +1095,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
  * Note that year is _not_ 1900-based, but is an explicit full value.
  * 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)
@@ -1088,7 +1130,7 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
        *result = dt2local(*result, -(*tzp));
 
    return 0;
-}  /* tm2timestamp() */
+}
 
 
 /* interval2tm()
@@ -1136,7 +1178,7 @@ interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
 #endif
 
    return 0;
-}  /* interval2tm() */
+}
 
 int
 tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
@@ -1156,7 +1198,7 @@ tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
 #endif
 
    return 0;
-}  /* tm2interval() */
+}
 
 #ifdef HAVE_INT64_TIMESTAMP
 static int64
@@ -1240,6 +1282,7 @@ SetEpochTimestamp(void)
               *tm = &tt;
 
    GetEpochTime(tm);
+   /* we don't bother to test for failure ... */
    tm2timestamp(tm, 0, NULL, &dt);
 
    return dt;
@@ -1605,7 +1648,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
 
    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
@@ -1647,37 +1693,31 @@ timestamp_pl_span(PG_FUNCTION_ARGS)
                       *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, &timestamp) != 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, &timestamp) != 0)
+               ereport(ERROR,
+                       (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+                        errmsg("timestamp out of range")));
        }
 
        timestamp += span->time;
@@ -1731,35 +1771,33 @@ timestamptz_pl_span(PG_FUNCTION_ARGS)
                       *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, &timestamp) != 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, &timestamp) != 0)
+               ereport(ERROR,
+                       (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+                        errmsg("timestamp out of range")));
        }
 
        timestamp += span->time;
@@ -1986,7 +2024,9 @@ interval_div(PG_FUNCTION_ARGS)
    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);
@@ -2031,7 +2071,7 @@ interval_accum(PG_FUNCTION_ARGS)
                      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
@@ -2073,7 +2113,7 @@ interval_avg(PG_FUNCTION_ARGS)
                      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
@@ -2195,12 +2235,14 @@ timestamp_age(PG_FUNCTION_ARGS)
        }
 
        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);
 }
@@ -2304,10 +2346,14 @@ timestamptz_age(PG_FUNCTION_ARGS)
        }
 
        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);
 }
@@ -2360,7 +2406,11 @@ text_timestamp(PG_FUNCTION_ARGS)
                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;
@@ -2416,7 +2466,11 @@ text_timestamptz(PG_FUNCTION_ARGS)
                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;
@@ -2473,7 +2527,12 @@ text_interval(PG_FUNCTION_ARGS)
                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++)
@@ -2506,9 +2565,12 @@ timestamp_trunc(PG_FUNCTION_ARGS)
               *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++)
@@ -2520,8 +2582,13 @@ timestamp_trunc(PG_FUNCTION_ARGS)
    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:
@@ -2561,16 +2628,24 @@ timestamp_trunc(PG_FUNCTION_ARGS)
                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;
    }
 
@@ -2599,9 +2674,11 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
               *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++)
@@ -2613,8 +2690,13 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
    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:
@@ -2653,19 +2735,27 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
                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);
@@ -2693,9 +2783,11 @@ interval_trunc(PG_FUNCTION_ARGS)
    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++)
@@ -2746,24 +2838,29 @@ interval_trunc(PG_FUNCTION_ARGS)
                    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;
    }
 
@@ -2783,7 +2880,9 @@ isoweek2date(int woy, int *year, int *mon, int *mday)
                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);
@@ -2870,9 +2969,11 @@ timestamp_part(PG_FUNCTION_ARGS)
               *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++)
@@ -2889,9 +2990,13 @@ timestamp_part(PG_FUNCTION_ARGS)
        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:
@@ -2973,7 +3078,10 @@ timestamp_part(PG_FUNCTION_ARGS)
            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;
        }
    }
@@ -2988,12 +3096,16 @@ timestamp_part(PG_FUNCTION_ARGS)
 
                /* 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, &timestamptz) != 0)
-                   elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE");
+                   ereport(ERROR,
+                           (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+                            errmsg("timestamp out of range")));
 
 #ifdef HAVE_INT64_TIMESTAMP
                result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);