<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/sources.sgml,v 2.8 2003/06/22 16:17:01 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/sources.sgml,v 2.9 2003/07/18 23:20:32 tgl Exp $
-->
<chapter id="source">
Here is a more complex example:
<programlisting>
ereport(ERROR,
- (errmsg("Unable to identify an operator %s %s %s",
- format_type_be(arg1),
- NameListToString(op),
- format_type_be(arg2)),
- errhint("Try explicitly casting the arguments to appropriate types")));
+ (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
+ errmsg("function %s is not unique",
+ func_signature_string(funcname, nargs,
+ actual_arg_types)),
+ errhint("Unable to choose a best candidate function. "
+ "You may need to add explicit typecasts.")));
</programlisting>
This illustrates the use of format codes to embed run-time values into
a message text. Also, an optional <quote>hint</> message is provided.
<listitem>
<para>
<function>errcode</>(sqlerrcode) specifies the SQLSTATE error identifier
- code for the condition. If this is not specified, it defaults to
- <literal>ERRCODE_INTERNAL_ERROR</>, which is a convenient default since
- a large number of <function>ereport</> calls are in fact for internal
- <quote>can't happen</> conditions. But never use this default when
- reporting user mistakes.
+ code for the condition. If this routine is not called, the error
+ identifier defaults to
+ <literal>ERRCODE_INTERNAL_ERROR</> when the error level is
+ <literal>ERROR</> or higher, <literal>ERRCODE_WARNING</> when the
+ error level is <literal>WARNING</>, otherwise (for <literal>NOTICE</>
+ and below) <literal>ERRCODE_SUCCESSFUL_COMPLETION</>.
+ While these defaults are often convenient, always think whether they
+ are appropriate before omitting the <function>errcode</>() call.
</para>
</listitem>
<listitem>
query processing.
</para>
</listitem>
+ <listitem>
+ <para>
+ <function>errcode_for_file_access</>() is a convenience function that
+ selects an appropriate SQLSTATE error identifier for a failure in a
+ file-access-related system call. It uses the saved
+ <literal>errno</> to determine which error code to generate.
+ Usually this should be used in combination with <literal>%m</> in the
+ primary error message text.
+ </para>
+ </listitem>
</itemizedlist>
</para>
<para>
You may also see uses of the older function <function>elog</>. This
is equivalent to an <function>ereport</> call specifying only severity
- level and primary message. Because the error code always defaults to
- <literal>ERRCODE_INTERNAL_ERROR</>, <function>elog</> should only be
- used for internal errors.
+ level and primary message. <function>elog</> should only be used if
+ the default errcode assignment is appropriate; this generally restricts
+ its use to internal errors and debug logging output.
</para>
<para>
write
<programlisting>
Primary: could not create shared memory segment: %m
- Detail: Failed syscall was shmget(key=%d, size=%u, 0%o)
+ Detail: Failed syscall was shmget(key=%d, size=%u, 0%o).
Hint: the addendum
</programlisting>
</para>
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.99 2003/07/01 01:28:32 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.100 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Assert(PointerIsValid(probin));
if (parameterCount < 0 || parameterCount > FUNC_MAX_ARGS)
- elog(ERROR, "functions cannot have more than %d arguments",
- FUNC_MAX_ARGS);
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
+ errmsg("functions cannot have more than %d arguments",
+ FUNC_MAX_ARGS)));
/*
* Do not allow return type ANYARRAY or ANYELEMENT unless at least one
}
if (!genericParam)
- elog(ERROR, "functions returning ANYARRAY or ANYELEMENT must " \
- "have at least one argument of either type");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("functions returning ANYARRAY or ANYELEMENT must have at least one argument of either type")));
}
/* Make sure we have a zero-padded param type array */
* existing attributes of the type
*/
if (parameterCount == 1 && OidIsValid(typev[0]) &&
- (relid = typeidTypeRelid(typev[0])) != 0 &&
+ (relid = typeidTypeRelid(typev[0])) != InvalidOid &&
get_attnum(relid, (char *) procedureName) != InvalidAttrNumber)
- elog(ERROR, "method %s already an attribute of type %s",
- procedureName, format_type_be(typev[0]));
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_COLUMN),
+ errmsg("\"%s\" is already an attribute of type %s",
+ procedureName, format_type_be(typev[0]))));
/*
* All seems OK; prepare the data to be inserted into pg_proc.
Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup);
if (!replace)
- elog(ERROR, "function %s already exists with same argument types",
- procedureName);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_FUNCTION),
+ errmsg("function \"%s\" already exists with same argument types",
+ procedureName)));
if (GetUserId() != oldproc->proowner && !superuser())
- elog(ERROR, "ProcedureCreate: you do not have permission to replace function %s",
- procedureName);
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("you do not have permission to replace function \"%s\"",
+ procedureName)));
/*
* Not okay to change the return type of the existing proc, since
*/
if (returnType != oldproc->prorettype ||
returnsSet != oldproc->proretset)
- elog(ERROR, "ProcedureCreate: cannot change return type of existing function."
- "\n\tUse DROP FUNCTION first.");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("cannot change return type of existing function"),
+ errhint("Use DROP FUNCTION first.")));
/* Can't change aggregate status, either */
if (oldproc->proisagg != isAgg)
{
if (oldproc->proisagg)
- elog(ERROR, "function %s is an aggregate",
- procedureName);
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("function \"%s\" is an aggregate",
+ procedureName)));
else
- elog(ERROR, "function %s is not an aggregate",
- procedureName);
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("function \"%s\" is not an aggregate",
+ procedureName)));
}
/* do not change existing ownership or permissions, either */
if (queryTreeList == NIL)
{
if (rettype != VOIDOID)
- elog(ERROR, "function declared to return %s, but no SELECT provided",
- format_type_be(rettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Function's final statement must be a SELECT.")));
return;
}
if (rettype == VOIDOID)
{
if (cmd == CMD_SELECT)
- elog(ERROR, "function declared to return void, but final statement is a SELECT");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Function's final statement must not be a SELECT.")));
return;
}
/* by here, the function is declared to return some type */
if (cmd != CMD_SELECT)
- elog(ERROR, "function declared to return %s, but final statement is not a SELECT",
- format_type_be(rettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Function's final statement must be a SELECT.")));
/*
* Count the non-junk entries in the result targetlist.
* (As of Postgres 7.2, we accept binary-compatible types too.)
*/
if (tlistlen != 1)
- elog(ERROR, "function declared to return %s returns multiple columns in final SELECT",
- format_type_be(rettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Final SELECT must return exactly one column.")));
restype = ((TargetEntry *) lfirst(tlist))->resdom->restype;
if (!IsBinaryCoercible(restype, rettype))
- elog(ERROR, "return type mismatch in function: declared to return %s, returns %s",
- format_type_be(rettype), format_type_be(restype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Actual return type is %s.",
+ format_type_be(restype))));
}
else if (fn_typtype == 'c')
{
{
colindex++;
if (colindex > relnatts)
- elog(ERROR, "function declared to return %s does not SELECT the right number of columns (%d)",
- format_type_be(rettype), rellogcols);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Final SELECT returns too many columns.")));
attr = reln->rd_att->attrs[colindex - 1];
} while (attr->attisdropped);
rellogcols++;
tletype = exprType((Node *) tle->expr);
atttype = attr->atttypid;
if (!IsBinaryCoercible(tletype, atttype))
- elog(ERROR, "function declared to return %s returns %s instead of %s at column %d",
- format_type_be(rettype),
- format_type_be(tletype),
- format_type_be(atttype),
- rellogcols);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Final SELECT returns %s instead of %s at column %d.",
+ format_type_be(tletype),
+ format_type_be(atttype),
+ rellogcols)));
}
for (;;)
}
if (tlistlen != rellogcols)
- elog(ERROR, "function declared to return %s does not SELECT the right number of columns (%d)",
- format_type_be(rettype), rellogcols);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type mismatch in function declared to return %s",
+ format_type_be(rettype)),
+ errdetail("Final SELECT returns too few columns.")));
relation_close(reln, AccessShareLock);
}
}
else if (rettype == ANYARRAYOID || rettype == ANYELEMENTOID)
{
- /*
- * This should already have been caught ...
- */
- elog(ERROR, "functions returning ANYARRAY or ANYELEMENT must " \
- "have at least one argument of either type");
+ /* This should already have been caught ... */
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("functions returning ANYARRAY or ANYELEMENT must have at least one argument of either type")));
}
else
- elog(ERROR, "return type %s is not supported for SQL functions",
- format_type_be(rettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("return type %s is not supported for SQL functions",
+ format_type_be(rettype))));
}
ObjectIdGetDatum(funcoid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cache lookup of function %u failed", funcoid);
+ elog(ERROR, "cache lookup failed for function %u", funcoid);
proc = (Form_pg_proc) GETSTRUCT(tuple);
tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
prosrc = DatumGetCString(DirectFunctionCall1(textout, tmp));
if (fmgr_internal_function(prosrc) == InvalidOid)
- elog(ERROR, "there is no built-in function named \"%s\"", prosrc);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("there is no built-in function named \"%s\"",
+ prosrc)));
ReleaseSysCache(tuple);
ObjectIdGetDatum(funcoid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cache lookup of function %u failed", funcoid);
+ elog(ERROR, "cache lookup failed for function %u", funcoid);
proc = (Form_pg_proc) GETSTRUCT(tuple);
tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
ObjectIdGetDatum(funcoid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cache lookup of function %u failed", funcoid);
+ elog(ERROR, "cache lookup failed for function %u", funcoid);
proc = (Form_pg_proc) GETSTRUCT(tuple);
functyptype = get_typtype(proc->prorettype);
proc->prorettype != VOIDOID &&
proc->prorettype != ANYARRAYOID &&
proc->prorettype != ANYELEMENTOID)
- elog(ERROR, "SQL functions cannot return type %s",
- format_type_be(proc->prorettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("SQL functions cannot return type %s",
+ format_type_be(proc->prorettype))));
/* Disallow pseudotypes in arguments */
/* except for ANYARRAY or ANYELEMENT */
proc->proargtypes[i] == ANYELEMENTOID)
haspolyarg = true;
else
- elog(ERROR, "SQL functions cannot have arguments of type %s",
- format_type_be(proc->proargtypes[i]));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("SQL functions cannot have arguments of type %s",
+ format_type_be(proc->proargtypes[i]))));
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.116 2003/06/27 14:45:27 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.117 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (strcmp(defel->defname, "owner") == 0)
{
if (downer)
- elog(ERROR, "CREATE DATABASE: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
downer = defel;
}
else if (strcmp(defel->defname, "location") == 0)
{
if (dpath)
- elog(ERROR, "CREATE DATABASE: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dpath = defel;
}
else if (strcmp(defel->defname, "template") == 0)
{
if (dtemplate)
- elog(ERROR, "CREATE DATABASE: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dtemplate = defel;
}
else if (strcmp(defel->defname, "encoding") == 0)
{
if (dencoding)
- elog(ERROR, "CREATE DATABASE: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dencoding = defel;
}
else
- elog(ERROR, "CREATE DATABASE: option \"%s\" not recognized",
+ elog(ERROR, "option \"%s\" not recognized",
defel->defname);
}
encoding_name = pg_encoding_to_char(encoding);
if (strcmp(encoding_name, "") == 0 ||
pg_valid_server_encoding(encoding_name) < 0)
- elog(ERROR, "%d is not a valid encoding code", encoding);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("%d is not a valid encoding code",
+ encoding)));
}
else if (IsA(dencoding->arg, String))
{
encoding_name = strVal(dencoding->arg);
if (pg_valid_server_encoding(encoding_name) < 0)
- elog(ERROR, "%s is not a valid encoding name", encoding_name);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("%s is not a valid encoding name",
+ encoding_name)));
encoding = pg_char_to_encoding(encoding_name);
}
else
- elog(ERROR, "CREATE DATABASE: bogus encoding parameter");
+ elog(ERROR, "unrecognized node type: %d",
+ nodeTag(dencoding->arg));
}
/* obtain sysid of proposed owner */
if (dbowner)
- datdba = get_usesysid(dbowner); /* will elog if no such user */
+ datdba = get_usesysid(dbowner); /* will ereport if no such user */
else
datdba = GetUserId();
{
/* creating database for self: can be superuser or createdb */
if (!superuser() && !have_createdb_privilege())
- elog(ERROR, "CREATE DATABASE: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
}
else
{
/* creating database for someone else: must be superuser */
/* note that the someone else need not have any permissions */
if (!superuser())
- elog(ERROR, "CREATE DATABASE: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
}
/* don't call this in a transaction block */
PreventTransactionChain((void *) stmt, "CREATE DATABASE");
+ /* alternate location requires symlinks */
#ifndef HAVE_SYMLINK
if (dbpath != NULL)
- elog(ERROR, "CREATE DATABASE: may not use an alternate location on this platform");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot use an alternate location on this platform")));
#endif
/*
* after we grab the exclusive lock.
*/
if (get_db_info(dbname, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
- elog(ERROR, "CREATE DATABASE: database \"%s\" already exists", dbname);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_DATABASE),
+ errmsg("database \"%s\" already exists", dbname)));
/*
* Lookup database (template) to be cloned.
&src_istemplate, &src_lastsysoid,
&src_vacuumxid, &src_frozenxid,
src_dbpath))
- elog(ERROR, "CREATE DATABASE: template \"%s\" does not exist",
- dbtemplate);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
+ errmsg("template \"%s\" does not exist", dbtemplate)));
/*
* Permission check: to copy a DB that's not marked datistemplate, you
if (!src_istemplate)
{
if (!superuser() && GetUserId() != src_owner)
- elog(ERROR, "CREATE DATABASE: permission to copy \"%s\" denied",
- dbtemplate);
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission to copy \"%s\" denied",
+ dbtemplate)));
}
/*
* bulletproof, since someone might connect while we are copying...
*/
if (DatabaseHasActiveBackends(src_dboid, true))
- elog(ERROR, "CREATE DATABASE: source database \"%s\" is being accessed by other users", dbtemplate);
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("source database \"%s\" is being accessed by other users",
+ dbtemplate)));
/* If encoding is defaulted, use source's encoding */
if (encoding < 0)
/* Some encodings are client only */
if (!PG_VALID_BE_ENCODING(encoding))
- elog(ERROR, "CREATE DATABASE: invalid backend encoding");
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("invalid backend encoding %d", encoding)));
/*
* Preassign OID for pg_database tuple, so that we can compute db
}
if (strchr(nominal_loc, '\''))
- elog(ERROR, "database path may not contain single quotes");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("database path may not contain single quotes")));
if (alt_loc && strchr(alt_loc, '\''))
- elog(ERROR, "database path may not contain single quotes");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("database path may not contain single quotes")));
if (strchr(src_loc, '\''))
- elog(ERROR, "database path may not contain single quotes");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("database path may not contain single quotes")));
/* ... otherwise we'd be open to shell exploits below */
/*
target_dir = alt_loc ? alt_loc : nominal_loc;
if (mkdir(target_dir, S_IRWXU) != 0)
- elog(ERROR, "CREATE DATABASE: unable to create database directory '%s': %m",
- target_dir);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("unable to create database directory \"%s\": %m",
+ target_dir)));
if (rmdir(target_dir) != 0)
- elog(ERROR, "CREATE DATABASE: unable to remove temp directory '%s': %m",
- target_dir);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("unable to remove temp directory \"%s\": %m",
+ target_dir)));
/* Make the symlink, if needed */
if (alt_loc)
#ifdef HAVE_SYMLINK /* already throws error above */
if (symlink(alt_loc, nominal_loc) != 0)
#endif
- elog(ERROR, "CREATE DATABASE: could not link '%s' to '%s': %m",
- nominal_loc, alt_loc);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not link \"%s\" to \"%s\": %m",
+ nominal_loc, alt_loc)));
}
/* Copy the template database to the new location */
#endif
{
if (remove_dbdirs(nominal_loc, alt_loc))
- elog(ERROR, "CREATE DATABASE: could not initialize database directory");
+ elog(ERROR, "could not initialize database directory");
else
- elog(ERROR, "CREATE DATABASE: could not initialize database directory; delete failed as well");
+ elog(ERROR, "could not initialize database directory; delete failed as well");
}
/*
/* Don't hold lock while doing recursive remove */
heap_close(pg_database_rel, AccessExclusiveLock);
remove_dbdirs(nominal_loc, alt_loc);
- elog(ERROR, "CREATE DATABASE: database \"%s\" already exists", dbname);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_DATABASE),
+ errmsg("database \"%s\" already exists", dbname)));
}
/*
AssertArg(dbname);
if (strcmp(dbname, get_database_name(MyDatabaseId)) == 0)
- elog(ERROR, "DROP DATABASE: cannot be executed on the currently open database");
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("cannot drop the currently open database")));
PreventTransactionChain((void *) dbname, "DROP DATABASE");
if (!get_db_info(dbname, &db_id, &db_owner, NULL,
&db_istemplate, NULL, NULL, NULL, dbpath))
- elog(ERROR, "DROP DATABASE: database \"%s\" does not exist", dbname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
+ errmsg("database \"%s\" does not exist", dbname)));
if (GetUserId() != db_owner && !superuser())
- elog(ERROR, "DROP DATABASE: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
/*
* Disallow dropping a DB that is marked istemplate. This is just to
* they can do so if they're really determined ...
*/
if (db_istemplate)
- elog(ERROR, "DROP DATABASE: database is marked as a template");
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("cannot drop a template database")));
nominal_loc = GetDatabasePath(db_id);
alt_loc = resolve_alt_dbpath(dbpath, db_id);
* Check for active backends in the target database.
*/
if (DatabaseHasActiveBackends(db_id, false))
- elog(ERROR, "DROP DATABASE: database \"%s\" is being accessed by other users", dbname);
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("database \"%s\" is being accessed by other users",
+ dbname)));
/*
* Find the database's tuple by OID (should be unique).
* This error should never come up since the existence of the
* database is checked earlier
*/
- elog(ERROR, "DROP DATABASE: Database \"%s\" doesn't exist despite earlier reports to the contrary",
+ elog(ERROR, "database \"%s\" doesn't exist despite earlier reports to the contrary",
dbname);
}
tup = systable_getnext(scan);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", oldname)));
/*
*/
if (HeapTupleGetOid(tup) == MyDatabaseId)
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("current database may not be renamed")));
/*
* operations.
*/
if (DatabaseHasActiveBackends(HeapTupleGetOid(tup), false))
- elog(ERROR, "database \"%s\" is being accessed by other users", oldname);
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("database \"%s\" is being accessed by other users",
+ oldname)));
/* make sure the new name doesn't exist */
ScanKeyEntryInitialize(&key2, 0, Anum_pg_database_datname,
F_NAMEEQ, NameGetDatum(newname));
scan2 = systable_beginscan(rel, DatabaseNameIndex, true, SnapshotNow, 1, &key2);
if (HeapTupleIsValid(systable_getnext(scan2)))
- {
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_DUPLICATE_DATABASE),
errmsg("database \"%s\" already exists", newname)));
- }
systable_endscan(scan2);
/* must be owner */
/* must have createdb */
if (!have_createdb_privilege())
- {
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied")));
- }
/* rename */
newtup = heap_copytuple(tup);
scan = systable_beginscan(rel, DatabaseNameIndex, true, SnapshotNow, 1, &scankey);
tuple = systable_getnext(scan);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "database \"%s\" does not exist", stmt->dbname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
+ errmsg("database \"%s\" does not exist", stmt->dbname)));
if (!(superuser()
- || ((Form_pg_database) GETSTRUCT(tuple))->datdba == GetUserId()))
- elog(ERROR, "ALTER DATABASE SET: permission denied");
+ || ((Form_pg_database) GETSTRUCT(tuple))->datdba == GetUserId()))
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
MemSet(repl_repl, ' ', sizeof(repl_repl));
repl_repl[Anum_pg_database_datconfig - 1] = 'r';
if (first_path_separator(dbpath))
{
if (!is_absolute_path(dbpath))
- elog(ERROR, "Relative paths are not allowed as database locations");
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("relative paths are not allowed as database locations")));
#ifndef ALLOW_ABSOLUTE_DBPATHS
- elog(ERROR, "Absolute paths are not allowed as database locations");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("absolute paths are not allowed as database locations")));
#endif
prefix = dbpath;
}
char *var = getenv(dbpath);
if (!var)
- elog(ERROR, "Postmaster environment variable '%s' not set", dbpath);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("postmaster environment variable \"%s\" not found",
+ dbpath)));
if (!is_absolute_path(var))
- elog(ERROR, "Postmaster environment variable '%s' must be absolute path", dbpath);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("postmaster environment variable \"%s\" must be absolute path",
+ dbpath)));
prefix = var;
}
len = strlen(prefix) + 6 + sizeof(Oid) * 8 + 1;
if (len >= MAXPGPATH - 100)
- elog(ERROR, "Alternate path is too long");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("alternate path is too long")));
ret = palloc(len);
snprintf(ret, len, "%s/base/%u", prefix, dboid);
/* remove symlink */
if (unlink(nominal_loc) != 0)
{
- elog(WARNING, "could not remove '%s': %m", nominal_loc);
+ ereport(WARNING,
+ (errcode_for_file_access(),
+ errmsg("could not remove \"%s\": %m", nominal_loc)));
success = false;
}
}
if (system(buf) != 0)
{
- elog(WARNING, "database directory '%s' could not be removed",
- target_dir);
+ ereport(WARNING,
+ (errcode_for_file_access(),
+ errmsg("could not remove database directory \"%s\": %m",
+ target_dir)));
success = false;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.27 2003/07/04 02:51:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.28 2003/07/18 23:20:32 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
if (!get_typisdefined(rettype))
{
if (languageOid == SQLlanguageId)
- elog(ERROR, "SQL function cannot return shell type \"%s\"",
- TypeNameToString(returnType));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("SQL function cannot return shell type %s",
+ TypeNameToString(returnType))));
else
- elog(NOTICE, "Return type \"%s\" is only a shell",
- TypeNameToString(returnType));
+ ereport(NOTICE,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("return type %s is only a shell",
+ TypeNameToString(returnType))));
}
}
else
*/
if (languageOid != INTERNALlanguageId &&
languageOid != ClanguageId)
- elog(ERROR, "Type \"%s\" does not exist", typnam);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type %s does not exist", typnam)));
/* Otherwise, go ahead and make a shell type */
- elog(NOTICE, "ProcedureCreate: type %s is not yet defined",
- typnam);
+ ereport(NOTICE,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type %s is not yet defined", typnam),
+ errdetail("Creating a shell type definition.")));
namespaceId = QualifiedNameGetCreationNamespace(returnType->names,
&typname);
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(),
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, get_namespace_name(namespaceId));
rettype = TypeShellMake(typname, namespaceId);
- if (!OidIsValid(rettype))
- elog(ERROR, "could not create type %s", typnam);
+ Assert(OidIsValid(rettype));
}
*prorettype_p = rettype;
Oid toid;
if (parameterCount >= FUNC_MAX_ARGS)
- elog(ERROR, "functions cannot have more than %d arguments",
- FUNC_MAX_ARGS);
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
+ errmsg("functions cannot have more than %d arguments",
+ FUNC_MAX_ARGS)));
toid = LookupTypeName(t);
if (OidIsValid(toid))
{
/* As above, hard error if language is SQL */
if (languageOid == SQLlanguageId)
- elog(ERROR, "SQL function cannot accept shell type \"%s\"",
- TypeNameToString(t));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("SQL function cannot accept shell type %s",
+ TypeNameToString(t))));
else
- elog(NOTICE, "Argument type \"%s\" is only a shell",
- TypeNameToString(t));
+ ereport(NOTICE,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("argument type %s is only a shell",
+ TypeNameToString(t))));
}
}
else
{
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(t));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type %s does not exist",
+ TypeNameToString(t))));
}
if (t->setof)
- elog(ERROR, "Functions cannot accept set arguments");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("functions cannot accept set arguments")));
parameterTypes[parameterCount++] = toid;
}
if (strcmp(defel->defname, "as") == 0)
{
if (as_item)
- elog(ERROR, "conflicting or redundant options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
as_item = defel;
}
else if (strcmp(defel->defname, "language") == 0)
{
if (language_item)
- elog(ERROR, "conflicting or redundant options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
language_item = defel;
}
else if (strcmp(defel->defname, "volatility") == 0)
{
if (volatility_item)
- elog(ERROR, "conflicting or redundant options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
volatility_item = defel;
}
else if (strcmp(defel->defname, "strict") == 0)
{
if (strict_item)
- elog(ERROR, "conflicting or redundant options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
strict_item = defel;
}
else if (strcmp(defel->defname, "security") == 0)
{
if (security_item)
- elog(ERROR, "conflicting or redundant options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
security_item = defel;
}
else
- elog(ERROR, "invalid CREATE FUNCTION option");
+ elog(ERROR, "option \"%s\" not recognized",
+ defel->defname);
}
if (as_item)
*as = (List *) as_item->arg;
else
- elog(ERROR, "no function body specified");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("no function body specified")));
if (language_item)
*language = strVal(language_item->arg);
else
- elog(ERROR, "no language specified");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("no language specified")));
if (volatility_item)
{
else if (strcmp(strVal(volatility_item->arg), "volatile") == 0)
*volatility_p = PROVOLATILE_VOLATILE;
else
- elog(ERROR, "invalid volatility");
+ elog(ERROR, "invalid volatility \"%s\"",
+ strVal(volatility_item->arg));
}
if (strict_item)
*volatility_p = PROVOLATILE_IMMUTABLE;
}
else
- elog(WARNING, "Unrecognized function attribute '%s' ignored",
- param->defname);
+ ereport(WARNING,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("unrecognized function attribute \"%s\" ignored",
+ param->defname)));
}
}
*probin_str_p = "-";
if (lnext(as) != NIL)
- elog(ERROR, "CREATE FUNCTION: only one AS item needed for %s language",
- languageName);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("only one AS item needed for language \"%s\"",
+ languageName)));
}
}
PointerGetDatum(languageName),
0, 0, 0);
if (!HeapTupleIsValid(languageTuple))
- elog(ERROR, "language \"%s\" does not exist", languageName);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("language \"%s\" does not exist", languageName)));
languageOid = HeapTupleGetOid(languageTuple);
languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
ObjectIdGetDatum(funcOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "RemoveFunction: couldn't find tuple for function %s",
- NameListToString(functionName));
+ elog(ERROR, "cache lookup failed for function %u", funcOid);
/* Permission check: must own func or its namespace */
if (!pg_proc_ownercheck(funcOid, GetUserId()) &&
aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(functionName));
if (((Form_pg_proc) GETSTRUCT(tup))->proisagg)
- elog(ERROR, "RemoveFunction: function '%s' is an aggregate"
- "\n\tUse DROP AGGREGATE to remove it",
- NameListToString(functionName));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("\"%s\" is an aggregate function",
+ NameListToString(functionName)),
+ errhint("Use DROP AGGREGATE to drop aggregate functions.")));
if (((Form_pg_proc) GETSTRUCT(tup))->prolang == INTERNALlanguageId)
{
/* "Helpful" NOTICE when removing a builtin function ... */
- elog(NOTICE, "Removing built-in function \"%s\"",
- NameListToString(functionName));
+ ereport(NOTICE,
+ (errcode(ERRCODE_WARNING),
+ errmsg("removing built-in function \"%s\"",
+ NameListToString(functionName))));
}
ReleaseSysCache(tup);
ObjectIdGetDatum(funcOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "RemoveFunctionById: couldn't find tuple for function %u",
- funcOid);
+ elog(ERROR, "cache lookup failed for function %u", funcOid);
isagg = ((Form_pg_proc) GETSTRUCT(tup))->proisagg;
ObjectIdGetDatum(funcOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "RemoveFunctionById: couldn't find pg_aggregate tuple for %u",
- funcOid);
+ elog(ERROR, "cache lookup failed for pg_aggregate tuple for function %u", funcOid);
simple_heap_delete(relation, &tup->t_self);
{
Oid procOid;
Oid namespaceOid;
- Oid oid_array[FUNC_MAX_ARGS];
HeapTuple tup;
+ Form_pg_proc procForm;
Relation rel;
AclResult aclresult;
- int16 nargs;
rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
ObjectIdGetDatum(procOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "RenameFunction: couldn't find pg_proc tuple for %s",
- NameListToString(name));
+ elog(ERROR, "cache lookup failed for function %u", procOid);
+ procForm = (Form_pg_proc) GETSTRUCT(tup);
- if (((Form_pg_proc) GETSTRUCT(tup))->proisagg)
+ if (procForm->proisagg)
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
- errmsg("%s is an aggregate function", NameListToString(name)),
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("\"%s\" is an aggregate function",
+ NameListToString(name)),
errhint("Use ALTER AGGREGATE to rename aggregate functions.")));
- namespaceOid = ((Form_pg_proc) GETSTRUCT(tup))->pronamespace;
+ namespaceOid = procForm->pronamespace;
/* make sure the new name doesn't exist */
- nargs = compute_parameter_types(argtypes, ((Form_pg_proc) GETSTRUCT(tup))->prolang, oid_array);
if (SearchSysCacheExists(PROCNAMENSP,
CStringGetDatum(newname),
- Int16GetDatum(nargs),
- PointerGetDatum(oid_array),
+ Int16GetDatum(procForm->pronargs),
+ PointerGetDatum(procForm->proargtypes),
ObjectIdGetDatum(namespaceOid)))
{
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
- errmsg("function %s with the same argument types already exists in schema %s",
- newname, get_namespace_name(namespaceOid))));
+ (errcode(ERRCODE_DUPLICATE_FUNCTION),
+ errmsg("function %s already exists",
+ func_signature_string(name,
+ procForm->pronargs,
+ procForm->proargtypes))));
}
/* must be owner */
aclcheck_error(aclresult, get_namespace_name(namespaceOid));
/* rename */
- namestrcpy(&(((Form_pg_proc) GETSTRUCT(tup))->proname), newname);
+ namestrcpy(&(procForm->proname), newname);
simple_heap_update(rel, &tup->t_self, tup);
CatalogUpdateIndexes(rel, tup);
ObjectIdGetDatum(funcOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "SetFunctionReturnType: couldn't find tuple for function %u",
- funcOid);
+ elog(ERROR, "cache lookup failed for function %u", funcOid);
procForm = (Form_pg_proc) GETSTRUCT(tup);
- if (procForm->prorettype != OPAQUEOID)
- elog(ERROR, "SetFunctionReturnType: function %u doesn't return OPAQUE",
- funcOid);
+ if (procForm->prorettype != OPAQUEOID) /* caller messed up */
+ elog(ERROR, "function %u doesn't return OPAQUE", funcOid);
/* okay to overwrite copied tuple */
procForm->prorettype = newRetType;
ObjectIdGetDatum(funcOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "SetFunctionArgType: couldn't find tuple for function %u",
- funcOid);
+ elog(ERROR, "cache lookup failed for function %u", funcOid);
procForm = (Form_pg_proc) GETSTRUCT(tup);
if (argIndex < 0 || argIndex >= procForm->pronargs ||
procForm->proargtypes[argIndex] != OPAQUEOID)
- elog(ERROR, "SetFunctionArgType: function %u doesn't take OPAQUE",
- funcOid);
+ elog(ERROR, "function %u doesn't take OPAQUE", funcOid);
/* okay to overwrite copied tuple */
procForm->proargtypes[argIndex] = newArgType;
sourcetypeid = LookupTypeName(stmt->sourcetype);
if (!OidIsValid(sourcetypeid))
- elog(ERROR, "source data type %s does not exist",
- TypeNameToString(stmt->sourcetype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("source data type %s does not exist",
+ TypeNameToString(stmt->sourcetype))));
targettypeid = LookupTypeName(stmt->targettype);
if (!OidIsValid(targettypeid))
- elog(ERROR, "target data type %s does not exist",
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("target data type %s does not exist",
+ TypeNameToString(stmt->targettype))));
if (sourcetypeid == targettypeid)
- elog(ERROR, "source data type and target data type are the same");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("source data type and target data type are the same")));
/* No shells, no pseudo-types allowed */
if (!get_typisdefined(sourcetypeid))
- elog(ERROR, "source data type %s is only a shell",
- TypeNameToString(stmt->sourcetype));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("source data type %s is only a shell",
+ TypeNameToString(stmt->sourcetype))));
if (!get_typisdefined(targettypeid))
- elog(ERROR, "target data type %s is only a shell",
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("target data type %s is only a shell",
+ TypeNameToString(stmt->targettype))));
if (get_typtype(sourcetypeid) == 'p')
- elog(ERROR, "source data type %s is a pseudo-type",
- TypeNameToString(stmt->sourcetype));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("source data type %s is a pseudo-type",
+ TypeNameToString(stmt->sourcetype))));
if (get_typtype(targettypeid) == 'p')
- elog(ERROR, "target data type %s is a pseudo-type",
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("target data type %s is a pseudo-type",
+ TypeNameToString(stmt->targettype))));
+ /* Permission check */
if (!pg_type_ownercheck(sourcetypeid, GetUserId())
&& !pg_type_ownercheck(targettypeid, GetUserId()))
- elog(ERROR, "must be owner of type %s or type %s",
- TypeNameToString(stmt->sourcetype),
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be owner of type %s or type %s",
+ TypeNameToString(stmt->sourcetype),
+ TypeNameToString(stmt->targettype))));
if (stmt->func != NULL)
{
ObjectIdGetDatum(funcid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cache lookup of function %u failed", funcid);
+ elog(ERROR, "cache lookup failed for function %u", funcid);
procstruct = (Form_pg_proc) GETSTRUCT(tuple);
if (procstruct->pronargs != 1)
- elog(ERROR, "cast function must take 1 argument");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("cast function must take 1 argument")));
if (procstruct->proargtypes[0] != sourcetypeid)
- elog(ERROR, "argument of cast function must match source data type");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("argument of cast function must match source data type")));
if (procstruct->prorettype != targettypeid)
- elog(ERROR, "return data type of cast function must match target data type");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("return data type of cast function must match target data type")));
/*
* Restricting the volatility of a cast function may or may not be
* a good idea in the abstract, but it definitely breaks many old
*/
#ifdef NOT_USED
if (procstruct->provolatile == PROVOLATILE_VOLATILE)
- elog(ERROR, "cast function must not be volatile");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("cast function must not be volatile")));
#endif
if (procstruct->proisagg)
- elog(ERROR, "cast function must not be an aggregate function");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("cast function must not be an aggregate function")));
if (procstruct->proretset)
- elog(ERROR, "cast function must not return a set");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("cast function must not return a set")));
ReleaseSysCache(tuple);
}
* erroneous casts can easily crash the backend.
*/
if (!superuser())
- elog(ERROR, "Must be superuser to create a cast WITHOUT FUNCTION");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to create a cast WITHOUT FUNCTION")));
/*
* Also, insist that the types match as to size, alignment, and
if (typ1len != typ2len ||
typ1byval != typ2byval ||
typ1align != typ2align)
- elog(ERROR, "source and target datatypes are not physically compatible");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("source and target datatypes are not physically compatible")));
}
/* convert CoercionContext enum to char value for castcontext */
castcontext = COERCION_CODE_EXPLICIT;
break;
default:
- elog(ERROR, "CreateCast: bogus CoercionContext %c", stmt->context);
+ elog(ERROR, "unrecognized CoercionContext: %d", stmt->context);
castcontext = 0; /* keep compiler quiet */
break;
}
ObjectIdGetDatum(targettypeid),
0, 0);
if (HeapTupleIsValid(tuple))
- elog(ERROR, "cast from data type %s to data type %s already exists",
- TypeNameToString(stmt->sourcetype),
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("cast from data type %s to data type %s already exists",
+ TypeNameToString(stmt->sourcetype),
+ TypeNameToString(stmt->targettype))));
/* ready to go */
values[Anum_pg_cast_castsource - 1] = ObjectIdGetDatum(sourcetypeid);
sourcetypeid = LookupTypeName(stmt->sourcetype);
if (!OidIsValid(sourcetypeid))
- elog(ERROR, "source data type %s does not exist",
- TypeNameToString(stmt->sourcetype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("source data type %s does not exist",
+ TypeNameToString(stmt->sourcetype))));
targettypeid = LookupTypeName(stmt->targettype);
if (!OidIsValid(targettypeid))
- elog(ERROR, "target data type %s does not exist",
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("target data type %s does not exist",
+ TypeNameToString(stmt->targettype))));
tuple = SearchSysCache(CASTSOURCETARGET,
ObjectIdGetDatum(sourcetypeid),
ObjectIdGetDatum(targettypeid),
0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cast from type %s to type %s does not exist",
- TypeNameToString(stmt->sourcetype),
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("cast from type %s to type %s does not exist",
+ TypeNameToString(stmt->sourcetype),
+ TypeNameToString(stmt->targettype))));
/* Permission check */
if (!pg_type_ownercheck(sourcetypeid, GetUserId())
&& !pg_type_ownercheck(targettypeid, GetUserId()))
- elog(ERROR, "must be owner of type %s or type %s",
- TypeNameToString(stmt->sourcetype),
- TypeNameToString(stmt->targettype));
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be owner of type %s or type %s",
+ TypeNameToString(stmt->sourcetype),
+ TypeNameToString(stmt->targettype))));
/*
* Do the deletion
1, F_OIDEQ, ObjectIdGetDatum(castOid));
scan = index_beginscan(relation, index, SnapshotNow, 1, &scankey);
tuple = index_getnext(scan, ForwardScanDirection);
- if (HeapTupleIsValid(tuple))
- simple_heap_delete(relation, &tuple->t_self);
- else
+ if (!HeapTupleIsValid(tuple))
elog(ERROR, "could not find tuple for cast %u", castOid);
+ simple_heap_delete(relation, &tuple->t_self);
index_endscan(scan);
index_close(index);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.11 2003/07/04 02:51:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.12 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
CStringGetDatum(stmt->amname),
0, 0, 0);
if (!HeapTupleIsValid(tup))
- elog(ERROR, "DefineOpClass: access method \"%s\" not found",
- stmt->amname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("access method \"%s\" does not exist",
+ stmt->amname)));
amoid = HeapTupleGetOid(tup);
numOperators = ((Form_pg_am) GETSTRUCT(tup))->amstrategies;
* if it can be done without solving the halting problem :-(
*/
if (!superuser())
- elog(ERROR, "Must be superuser to create an operator class");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to create an operator class")));
/* Look up the datatype */
typeoid = typenameTypeId(stmt->datatype);
{
case OPCLASS_ITEM_OPERATOR:
if (item->number <= 0 || item->number > numOperators)
- elog(ERROR, "DefineOpClass: invalid operator number %d,"
- " must be between 1 and %d",
- item->number, numOperators);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("invalid operator number %d,"
+ " must be between 1 and %d",
+ item->number, numOperators)));
if (operators[item->number - 1] != InvalidOid)
- elog(ERROR, "DefineOpClass: operator number %d appears more than once",
- item->number);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("operator number %d appears more than once",
+ item->number)));
if (item->args != NIL)
{
TypeName *typeName1 = (TypeName *) lfirst(item->args);
break;
case OPCLASS_ITEM_FUNCTION:
if (item->number <= 0 || item->number > numProcs)
- elog(ERROR, "DefineOpClass: invalid procedure number %d,"
- " must be between 1 and %d",
- item->number, numProcs);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("invalid procedure number %d,"
+ " must be between 1 and %d",
+ item->number, numProcs)));
if (procedures[item->number - 1] != InvalidOid)
- elog(ERROR, "DefineOpClass: procedure number %d appears more than once",
- item->number);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("DefineOpClass: procedure number %d appears more than once",
+ item->number)));
funcOid = LookupFuncNameTypeNames(item->name, item->args,
false);
/* Caller must have execute permission on functions */
break;
case OPCLASS_ITEM_STORAGETYPE:
if (OidIsValid(storageoid))
- elog(ERROR, "DefineOpClass: storage type specified more than once");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("storage type specified more than once")));
storageoid = typenameTypeId(item->storedtype);
break;
default:
- elog(ERROR, "DefineOpClass: bogus item type %d",
- item->itemtype);
+ elog(ERROR, "unrecognized item type: %d", item->itemtype);
break;
}
}
* favor of adding another boolean column to pg_am ...
*/
if (amoid != GIST_AM_OID)
- elog(ERROR, "Storage type may not be different from datatype for access method %s",
- stmt->amname);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("storage type may not be different from datatype for access method \"%s\"",
+ stmt->amname)));
}
}
CStringGetDatum(opcname),
ObjectIdGetDatum(namespaceoid),
0))
- elog(ERROR, "Operator class \"%s\" already exists for access method \"%s\"",
- opcname, stmt->amname);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("operator class \"%s\" already exists for access method \"%s\"",
+ opcname, stmt->amname)));
/*
* If we are creating a default opclass, check there isn't one
Form_pg_opclass opclass = (Form_pg_opclass) GETSTRUCT(tup);
if (opclass->opcintype == typeoid && opclass->opcdefault)
- elog(ERROR, "Can't add class \"%s\" as default for type %s"
- "\n\tclass \"%s\" already is the default",
- opcname,
- TypeNameToString(stmt->datatype),
- NameStr(opclass->opcname));
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("cannot make class \"%s\" be default for type %s",
+ opcname,
+ TypeNameToString(stmt->datatype)),
+ errdetail("class \"%s\" already is the default",
+ NameStr(opclass->opcname))));
}
systable_endscan(scan);
CStringGetDatum(stmt->amname),
0, 0, 0);
if (!OidIsValid(amID))
- elog(ERROR, "RemoveOpClass: access method \"%s\" not found",
- stmt->amname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("access method \"%s\" does not exist",
+ stmt->amname)));
/*
* Look up the opclass.
/* Unqualified opclass name, so search the search path */
opcID = OpclassnameGetOpcid(amID, opcname);
if (!OidIsValid(opcID))
- elog(ERROR, "RemoveOpClass: operator class \"%s\" not supported by access method \"%s\"",
- opcname, stmt->amname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("operator class \"%s\" does not exist for access method \"%s\"",
+ opcname, stmt->amname)));
tuple = SearchSysCache(CLAOID,
ObjectIdGetDatum(opcID),
0, 0, 0);
}
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "RemoveOpClass: operator class \"%s\" not supported by access method \"%s\"",
- NameListToString(stmt->opclassname), stmt->amname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("operator class \"%s\" does not exist for access method \"%s\"",
+ NameListToString(stmt->opclassname), stmt->amname)));
opcID = HeapTupleGetOid(tuple);
ObjectIdGetDatum(opclassOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "RemoveOpClassById: couldn't find pg_opclass entry %u",
- opclassOid);
+ elog(ERROR, "cache lookup failed for opclass %u", opclassOid);
simple_heap_delete(rel, &tup->t_self);
CStringGetDatum(access_method),
0, 0, 0);
if (!OidIsValid(amOid))
- elog(ERROR, "access method \"%s\" not found", access_method);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("access method \"%s\" does not exist",
+ access_method)));
rel = heap_openr(OperatorClassRelationName, RowExclusiveLock);
ObjectIdGetDatum(namespaceOid),
0);
if (!HeapTupleIsValid(tup))
- elog(ERROR, "operator class \"%s\" for access method \"%s\" does not exist",
- opcname, access_method);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("operator class \"%s\" does not exist for access method \"%s\"",
+ opcname, access_method)));
opcOid = HeapTupleGetOid(tup);
}
{
opcOid = OpclassnameGetOpcid(amOid, opcname);
if (!OidIsValid(opcOid))
- elog(ERROR, "operator class \"%s\" for access method \"%s\" does not exist",
- opcname, access_method);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("operator class \"%s\" does not exist for access method \"%s\"",
+ opcname, access_method)));
tup = SearchSysCacheCopy(CLAOID,
ObjectIdGetDatum(opcOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "couldn't find pg_opclass tuple for %u", opcOid);
+ elog(ERROR, "cache lookup failed for opclass %u", opcOid);
namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
}
0))
{
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("operator class \"%s\" for access method \"%s\" already exists in schema \"%s\"",
- newname, access_method, get_namespace_name(namespaceOid))));
+ newname, access_method,
+ get_namespace_name(namespaceOid))));
}
/* must be owner */
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.45 2003/07/04 02:51:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.46 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Check permission
*/
if (!superuser())
- elog(ERROR, "Only users with superuser privilege are "
- "permitted to create procedural languages");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to create procedural language")));
/*
* Translate the language name and check that this language doesn't
if (SearchSysCacheExists(LANGNAME,
PointerGetDatum(languageName),
0, 0, 0))
- elog(ERROR, "Language %s already exists", languageName);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("language \"%s\" already exists", languageName)));
/*
* Lookup the PL handler function and check that it is of the expected
*/
if (funcrettype == OPAQUEOID)
{
- elog(NOTICE, "CreateProceduralLanguage: changing return type of function %s() from OPAQUE to LANGUAGE_HANDLER",
- NameListToString(stmt->plhandler));
+ ereport(NOTICE,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("changing return type of function %s() from OPAQUE to LANGUAGE_HANDLER",
+ NameListToString(stmt->plhandler))));
SetFunctionReturnType(procOid, LANGUAGE_HANDLEROID);
}
else
- elog(ERROR, "CreateProceduralLanguage: function %s() must return LANGUAGE_HANDLER",
- NameListToString(stmt->plhandler));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("function %s() must return LANGUAGE_HANDLER",
+ NameListToString(stmt->plhandler))));
}
/* validate the validator function */
* Check permission
*/
if (!superuser())
- elog(ERROR, "Only users with superuser privilege are "
- "permitted to drop procedural languages");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to drop procedural language")));
/*
* Translate the language name, check that this language exist and is
CStringGetDatum(languageName),
0, 0, 0);
if (!HeapTupleIsValid(langTup))
- elog(ERROR, "Language %s doesn't exist", languageName);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("language \"%s\" does not exist", languageName)));
object.classId = get_system_catalog_relid(LanguageRelationName);
object.objectId = HeapTupleGetOid(langTup);
langTup = SearchSysCache(LANGOID,
ObjectIdGetDatum(langOid),
0, 0, 0);
- if (!HeapTupleIsValid(langTup))
- elog(ERROR, "DropProceduralLanguageById: language %u not found",
- langOid);
+ if (!HeapTupleIsValid(langTup)) /* should not happen */
+ elog(ERROR, "cache lookup failed for language %u", langOid);
simple_heap_delete(rel, &langTup->t_self);
0, 0, 0);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", oldname)));
/* make sure the new name doesn't exist */
if (SearchSysCacheExists(LANGNAME,
CStringGetDatum(newname),
0, 0, 0))
- {
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("language \"%s\" already exists", newname)));
- }
/* must be superuser */
if (!superuser())
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied")));
/* rename */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.11 2003/06/27 17:05:46 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.12 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
SetUserId(owner_userid);
}
else
-/* not superuser */
{
+ /* not superuser */
owner_userid = saved_userid;
owner_name = GetUserNameFromId(owner_userid);
if (strcmp(authId, owner_name) != 0)
- elog(ERROR, "CREATE SCHEMA: permission denied"
- "\n\t\"%s\" is not a superuser, so cannot create a schema for \"%s\"",
- owner_name, authId);
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied"),
+ errdetail("\"%s\" is not a superuser, so cannot create a schema for \"%s\"",
+ owner_name, authId)));
}
/*
aclcheck_error(aclresult, get_database_name(MyDatabaseId));
if (!allowSystemTableMods && IsReservedName(schemaName))
- elog(ERROR, "CREATE SCHEMA: Illegal schema name: \"%s\" -- pg_ is reserved for system schemas",
- schemaName);
+ ereport(ERROR,
+ (errcode(ERRCODE_RESERVED_NAME),
+ errmsg("unacceptable schema name \"%s\"", schemaName),
+ errdetail("The prefix pg_ is reserved for system schemas.")));
/* Create the schema's namespace */
namespaceId = NamespaceCreate(schemaName, owner_userid);
ObjectAddress object;
if (length(names) != 1)
- elog(ERROR, "Schema name may not be qualified");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("schema name may not be qualified")));
namespaceName = strVal(lfirst(names));
namespaceId = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(namespaceName),
0, 0, 0);
if (!OidIsValid(namespaceId))
- elog(ERROR, "Schema \"%s\" does not exist", namespaceName);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_SCHEMA),
+ errmsg("schema \"%s\" does not exist", namespaceName)));
/* Permission check */
if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
tup = SearchSysCache(NAMESPACEOID,
ObjectIdGetDatum(schemaOid),
0, 0, 0);
- if (!HeapTupleIsValid(tup))
- elog(ERROR, "RemoveSchemaById: schema %u not found",
- schemaOid);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "cache lookup failed for schema %u", schemaOid);
simple_heap_delete(relation, &tup->t_self);
0, 0, 0);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", oldname)));
/* make sure the new name doesn't exist */
SearchSysCache(NAMESPACENAME,
CStringGetDatum(newname),
0, 0, 0)))
- {
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_DUPLICATE_SCHEMA),
errmsg("schema \"%s\" already exists", newname)));
- }
/* must be owner */
if (!pg_namespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
aclcheck_error(aclresult, get_database_name(MyDatabaseId));
if (!allowSystemTableMods && IsReservedName(newname))
- elog(ERROR, "illegal schema name: \"%s\" -- pg_ is reserved for system schemas",
- newname);
+ ereport(ERROR,
+ (errcode(ERRCODE_RESERVED_NAME),
+ errmsg("unacceptable schema name \"%s\"", newname),
+ errdetail("The prefix pg_ is reserved for system schemas.")));
/* rename */
namestrcpy(&(((Form_pg_namespace) GETSTRUCT(tup))->nspname), newname);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.118 2003/06/27 14:45:27 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.119 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
fp = AllocateFile(tempname, "w");
umask(oumask);
if (fp == NULL)
- elog(ERROR, "write_group_file: unable to write %s: %m", tempname);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("unable to write temp file \"%s\": %m", tempname)));
/*
* Read pg_group and write the file. Note we use SnapshotSelf to ensure
i = strcspn(groname, "\n");
if (groname[i] != '\0')
{
- elog(LOG, "Invalid group name '%s'", groname);
+ elog(LOG, "invalid group name \"%s\"", groname);
continue;
}
j = strcspn(usename, "\n");
if (usename[j] != '\0')
{
- elog(LOG, "Invalid user name '%s'", usename);
+ elog(LOG, "invalid user name \"%s\"", usename);
continue;
}
fflush(fp);
if (ferror(fp))
- elog(ERROR, "%s: %m", tempname);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("unable to write temp file \"%s\": %m", tempname)));
FreeFile(fp);
/*
* expect that rename(2) is an atomic action.
*/
if (rename(tempname, filename))
- elog(ERROR, "rename %s to %s: %m", tempname, filename);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not rename \"%s\" to \"%s\": %m",
+ tempname, filename)));
pfree((void *) tempname);
pfree((void *) filename);
fp = AllocateFile(tempname, "w");
umask(oumask);
if (fp == NULL)
- elog(ERROR, "write_user_file: unable to write %s: %m", tempname);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("unable to write temp file \"%s\": %m", tempname)));
/*
* Read pg_shadow and write the file. Note we use SnapshotSelf to ensure
i = strcspn(usename, "\n");
if (usename[i] != '\0')
{
- elog(LOG, "Invalid user name '%s'", usename);
+ elog(LOG, "invalid user name \"%s\"", usename);
continue;
}
i = strcspn(passwd, "\n");
if (passwd[i] != '\0')
{
- elog(LOG, "Invalid user password '%s'", passwd);
+ elog(LOG, "invalid user password \"%s\"", passwd);
continue;
}
fflush(fp);
if (ferror(fp))
- elog(ERROR, "%s: %m", tempname);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("unable to write temp file \"%s\": %m", tempname)));
FreeFile(fp);
/*
* expect that rename(2) is an atomic action.
*/
if (rename(tempname, filename))
- elog(ERROR, "rename %s to %s: %m", tempname, filename);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not rename \"%s\" to \"%s\": %m",
+ tempname, filename)));
pfree((void *) tempname);
pfree((void *) filename);
strcmp(defel->defname, "unencryptedPassword") == 0)
{
if (dpassword)
- elog(ERROR, "CREATE USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dpassword = defel;
if (strcmp(defel->defname, "encryptedPassword") == 0)
encrypt_password = true;
else if (strcmp(defel->defname, "sysid") == 0)
{
if (dsysid)
- elog(ERROR, "CREATE USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dsysid = defel;
}
else if (strcmp(defel->defname, "createdb") == 0)
{
if (dcreatedb)
- elog(ERROR, "CREATE USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dcreatedb = defel;
}
else if (strcmp(defel->defname, "createuser") == 0)
{
if (dcreateuser)
- elog(ERROR, "CREATE USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dcreateuser = defel;
}
else if (strcmp(defel->defname, "groupElts") == 0)
{
if (dgroupElts)
- elog(ERROR, "CREATE USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dgroupElts = defel;
}
else if (strcmp(defel->defname, "validUntil") == 0)
{
if (dvalidUntil)
- elog(ERROR, "CREATE USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dvalidUntil = defel;
}
else
- elog(ERROR, "CREATE USER: option \"%s\" not recognized",
+ elog(ERROR, "option \"%s\" not recognized",
defel->defname);
}
{
sysid = intVal(dsysid->arg);
if (sysid <= 0)
- elog(ERROR, "user id must be positive");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("user id must be positive")));
havesysid = true;
}
if (dvalidUntil)
CheckPgUserAclNotNull();
if (!superuser())
- elog(ERROR, "CREATE USER: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
if (strcmp(stmt->user, "public") == 0)
- elog(ERROR, "CREATE USER: user name \"%s\" is reserved",
- stmt->user);
+ ereport(ERROR,
+ (errcode(ERRCODE_RESERVED_NAME),
+ errmsg("user name \"%s\" is reserved",
+ stmt->user)));
/*
* Scan the pg_shadow relation to be certain the user or id doesn't
heap_endscan(scan);
if (user_exists)
- elog(ERROR, "CREATE USER: user name \"%s\" already exists",
- stmt->user);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("user \"%s\" already exists",
+ stmt->user)));
if (sysid_exists)
- elog(ERROR, "CREATE USER: sysid %d is already assigned", sysid);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("sysid %d is already assigned", sysid)));
/* If no sysid given, use max existing id + 1 */
if (!havesysid)
{
if (!EncryptMD5(password, stmt->user, strlen(stmt->user),
encrypted_password))
- elog(ERROR, "CREATE USER: password encryption failed");
+ elog(ERROR, "password encryption failed");
new_record[Anum_pg_shadow_passwd - 1] =
DirectFunctionCall1(textin, CStringGetDatum(encrypted_password));
}
strcmp(defel->defname, "unencryptedPassword") == 0)
{
if (dpassword)
- elog(ERROR, "ALTER USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dpassword = defel;
if (strcmp(defel->defname, "encryptedPassword") == 0)
encrypt_password = true;
else if (strcmp(defel->defname, "createdb") == 0)
{
if (dcreatedb)
- elog(ERROR, "ALTER USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dcreatedb = defel;
}
else if (strcmp(defel->defname, "createuser") == 0)
{
if (dcreateuser)
- elog(ERROR, "ALTER USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dcreateuser = defel;
}
else if (strcmp(defel->defname, "validUntil") == 0)
{
if (dvalidUntil)
- elog(ERROR, "ALTER USER: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dvalidUntil = defel;
}
else
- elog(ERROR, "ALTER USER: option \"%s\" not recognized",
+ elog(ERROR, "option \"%s\" not recognized",
defel->defname);
}
!validUntil &&
password &&
strcmp(GetUserNameFromId(GetUserId()), stmt->user) == 0))
- elog(ERROR, "ALTER USER: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
/*
* Scan the pg_shadow relation to be certain the user exists. Note we
PointerGetDatum(stmt->user),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "ALTER USER: user \"%s\" does not exist", stmt->user);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("user \"%s\" does not exist", stmt->user)));
/*
* Build an updated tuple, perusing the information just obtained
{
if (!EncryptMD5(password, stmt->user, strlen(stmt->user),
encrypted_password))
- elog(ERROR, "CREATE USER: password encryption failed");
+ elog(ERROR, "password encryption failed");
new_record[Anum_pg_shadow_passwd - 1] =
DirectFunctionCall1(textin, CStringGetDatum(encrypted_password));
}
PointerGetDatum(stmt->user),
0, 0, 0);
if (!HeapTupleIsValid(oldtuple))
- elog(ERROR, "user \"%s\" does not exist", stmt->user);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("user \"%s\" does not exist", stmt->user)));
if (!(superuser()
|| ((Form_pg_shadow) GETSTRUCT(oldtuple))->usesysid == GetUserId()))
- elog(ERROR, "ALTER USER SET: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
for (i = 0; i < Natts_pg_shadow; i++)
repl_repl[i] = ' ';
List *item;
if (!superuser())
- elog(ERROR, "DROP USER: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
/*
* Scan the pg_shadow relation to find the usesysid of the user to be
PointerGetDatum(user),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- {
- if (length(stmt->users) > 1)
- elog(ERROR, "DROP USER: user \"%s\" does not exist (no users removed)", user);
- else
- elog(ERROR, "DROP USER: user \"%s\" does not exist", user);
- }
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("user \"%s\" does not exist", user)));
usesysid = ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
if (usesysid == GetUserId())
- elog(ERROR, "current user cannot be dropped");
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("current user cannot be dropped")));
if (usesysid == GetSessionUserId())
- elog(ERROR, "session user cannot be dropped");
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("session user cannot be dropped")));
/*
* Check if user still owns a database. If so, error out.
char *dbname;
dbname = NameStr(((Form_pg_database) GETSTRUCT(tmp_tuple))->datname);
- elog(ERROR, "DROP USER: user \"%s\" owns database \"%s\", cannot be removed%s",
- user, dbname,
- (length(stmt->users) > 1) ? " (no users removed)" : "");
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_IN_USE),
+ errmsg("user \"%s\" cannot be dropped", user),
+ errdetail("The user owns database \"%s\".", dbname)));
}
heap_endscan(scan);
0, 0, 0);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("user \"%s\" does not exist", oldname)));
/*
*/
if (((Form_pg_shadow) GETSTRUCT(tup))->usesysid == GetSessionUserId())
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("session user may not be renamed")));
/* make sure the new name doesn't exist */
if (SearchSysCacheExists(SHADOWNAME,
CStringGetDatum(newname),
0, 0, 0))
- {
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("user \"%s\" already exists", newname)));
- }
/* must be superuser */
if (!superuser())
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied")));
/* rename */
htup = SearchSysCache(RELOID,
ObjectIdGetDatum(RelOid_pg_shadow),
0, 0, 0);
- if (!HeapTupleIsValid(htup))
- elog(ERROR, "CheckPgUserAclNotNull: \"%s\" not found",
- ShadowRelationName);
+ if (!HeapTupleIsValid(htup)) /* should not happen, we hope */
+ elog(ERROR, "cache lookup failed for relation %u", RelOid_pg_shadow);
if (heap_attisnull(htup, Anum_pg_class_relacl))
- elog(ERROR,
- "To use passwords, you have to revoke permissions on %s "
- "so normal users cannot read the passwords. "
- "Try 'REVOKE ALL ON \"%s\" FROM PUBLIC'.",
- ShadowRelationName, ShadowRelationName);
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("before using passwords you must revoke permissions on %s",
+ ShadowRelationName),
+ errdetail("This restriction is to prevent unprivileged users from reading the passwords."),
+ errhint("Try 'REVOKE ALL ON \"%s\" FROM PUBLIC'.",
+ ShadowRelationName)));
ReleaseSysCache(htup);
}
if (strcmp(defel->defname, "sysid") == 0)
{
if (dsysid)
- elog(ERROR, "CREATE GROUP: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
dsysid = defel;
}
else if (strcmp(defel->defname, "userElts") == 0)
{
if (duserElts)
- elog(ERROR, "CREATE GROUP: conflicting options");
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("conflicting or redundant options")));
duserElts = defel;
}
else
- elog(ERROR, "CREATE GROUP: option \"%s\" not recognized",
+ elog(ERROR, "option \"%s\" not recognized",
defel->defname);
}
{
sysid = intVal(dsysid->arg);
if (sysid <= 0)
- elog(ERROR, "group id must be positive");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("group id must be positive")));
havesysid = true;
}
* Make sure the user can do this.
*/
if (!superuser())
- elog(ERROR, "CREATE GROUP: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
if (strcmp(stmt->name, "public") == 0)
- elog(ERROR, "CREATE GROUP: group name \"%s\" is reserved",
- stmt->name);
+ ereport(ERROR,
+ (errcode(ERRCODE_RESERVED_NAME),
+ errmsg("group name \"%s\" is reserved",
+ stmt->name)));
/*
* Scan the pg_group relation to be certain the group or id doesn't
heap_endscan(scan);
if (group_exists)
- elog(ERROR, "CREATE GROUP: group name \"%s\" already exists",
- stmt->name);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("group \"%s\" already exists",
+ stmt->name)));
if (sysid_exists)
- elog(ERROR, "CREATE GROUP: group sysid %d is already assigned",
- sysid);
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("sysid %d is already assigned", sysid)));
+ /* If no sysid given, use max existing id + 1 */
if (!havesysid)
sysid = max_id + 1;
* Make sure the user can do this.
*/
if (!superuser())
- elog(ERROR, "%s: permission denied", tag);
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
/*
* Secure exclusive lock to protect our update of the flat group file.
PointerGetDatum(stmt->name),
0, 0, 0);
if (!HeapTupleIsValid(group_tuple))
- elog(ERROR, "%s: group \"%s\" does not exist", tag, stmt->name);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("group \"%s\" does not exist", stmt->name)));
/* Fetch old group membership. */
datum = heap_getattr(group_tuple, Anum_pg_group_grolist,
}
else
{
- elog(ERROR, "AlterGroup: unknown tag %s", tag);
+ elog(ERROR, "unexpected tag: \"%s\"", tag);
sysid = 0; /* keep compiler quiet */
}
if (!intMember(sysid, newlist))
newlist = lappendi(newlist, sysid);
else
-
- /*
- * we silently assume here that this error will only come
- * up in a ALTER GROUP statement
- */
- elog(WARNING, "%s: user \"%s\" is already in group \"%s\"",
- tag, strVal(lfirst(item)), stmt->name);
+ ereport(WARNING,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("user \"%s\" is already in group \"%s\"",
+ strVal(lfirst(item)), stmt->name)));
}
/* Do the update */
if (newlist == NIL)
{
if (!is_dropuser)
- elog(WARNING, "ALTER GROUP: group \"%s\" does not have any members", stmt->name);
+ ereport(WARNING,
+ (errcode(ERRCODE_WARNING),
+ errmsg("group \"%s\" does not have any members",
+ stmt->name)));
}
else
{
if (intMember(sysid, newlist))
newlist = lremovei(sysid, newlist);
else if (!is_dropuser)
- elog(WARNING, "ALTER GROUP: user \"%s\" is not in group \"%s\"", strVal(lfirst(item)), stmt->name);
+ ereport(WARNING,
+ (errcode(ERRCODE_WARNING),
+ errmsg("user \"%s\" is not in group \"%s\"",
+ strVal(lfirst(item)), stmt->name)));
}
/* Do the update */
* Make sure the user can do this.
*/
if (!superuser())
- elog(ERROR, "DROP GROUP: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
/*
* Secure exclusive lock to protect our update of the flat group file.
PointerGetDatum(stmt->name),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "DROP GROUP: group \"%s\" does not exist", stmt->name);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("group \"%s\" does not exist", stmt->name)));
simple_heap_delete(pg_group_rel, &tuple->t_self);
0, 0, 0);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("group \"%s\" does not exist", oldname)));
/* make sure the new name doesn't exist */
if (SearchSysCacheExists(GRONAME,
CStringGetDatum(newname),
0, 0, 0))
- {
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
- errmsg("a group \"%s\" already exists", newname)));
- }
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("group \"%s\" already exists", newname)));
/* must be superuser */
if (!superuser())
ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied")));
/* rename */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.279 2003/07/16 17:25:48 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.280 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (paramno <= 0 || /* shouldn't happen, but... */
paramno > context->numParams)
- elog(ERROR, "Parameter '$%d' is out of range", paramno);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_PARAMETER),
+ errmsg("there is no parameter $%d", paramno)));
if (param->paramtype != context->paramTypes[paramno-1])
- elog(ERROR, "Could not determine datatype of parameter $%d",
- paramno);
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_PARAMETER),
+ errmsg("could not determine datatype of parameter $%d",
+ paramno)));
}
return false;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.103 2003/07/03 19:07:48 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.104 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (paramno <= 0 || /* shouldn't happen, but... */
paramno > toppstate->p_numparams)
- elog(ERROR, "Parameter '$%d' is out of range", paramno);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_PARAMETER),
+ errmsg("there is no parameter $%d", paramno)));
if (toppstate->p_paramtypes[paramno-1] == UNKNOWNOID)
{
else
{
/* Ooops */
- elog(ERROR, "Inconsistent types deduced for parameter '$%d'"
- "\n\tCould be either %s or %s",
- paramno,
- format_type_be(toppstate->p_paramtypes[paramno-1]),
- format_type_be(targetTypeId));
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_PARAMETER),
+ errmsg("inconsistent types deduced for parameter $%d",
+ paramno),
+ errdetail("Could be either %s or %s.",
+ format_type_be(toppstate->p_paramtypes[paramno-1]),
+ format_type_be(targetTypeId))));
}
param->paramtype = targetTypeId;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.155 2003/07/03 16:34:16 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.156 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Check parameter number is in range */
if (paramno <= 0) /* probably can't happen? */
- elog(ERROR, "Parameter '$%d' is out of range",
- paramno);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_PARAMETER),
+ errmsg("there is no parameter $%d", paramno)));
if (paramno > toppstate->p_numparams)
{
if (!toppstate->p_variableparams)
- elog(ERROR, "Parameter '$%d' is out of range",
- paramno);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_PARAMETER),
+ errmsg("there is no parameter $%d",
+ paramno)));
/* Okay to enlarge param array */
if (toppstate->p_paramtypes)
toppstate->p_paramtypes =
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.153 2003/07/04 02:51:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.154 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* function, but the test doesn't hurt.
*/
if (nargs > FUNC_MAX_ARGS)
- elog(ERROR, "Cannot pass more than %d arguments to a function",
- FUNC_MAX_ARGS);
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
+ errmsg("cannot pass more than %d arguments to a function",
+ FUNC_MAX_ARGS)));
if (fargs)
{
first_arg = lfirst(fargs);
- if (first_arg == NULL) /* should not happen */
- elog(ERROR, "Function '%s' does not allow NULL input",
- NameListToString(funcname));
+ Assert(first_arg != NULL);
}
/*
case RTE_RELATION:
toid = get_rel_type_id(rte->relid);
if (!OidIsValid(toid))
- elog(ERROR, "Cannot find type OID for relation %u",
+ elog(ERROR, "cannot find type OID for relation %u",
rte->relid);
/* replace RangeVar in the arg list */
lfirst(i) = makeVar(vnum,
unknown_attribute(schemaname, relname,
strVal(lfirst(funcname)));
else
- elog(ERROR, "Cannot pass result of sub-select or join %s to a function",
- relname);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot pass result of sub-select or join %s to a function",
+ relname)));
toid = InvalidOid; /* keep compiler quiet */
break;
}
* an aggregate?
*/
if (agg_star)
- elog(ERROR, "%s(*) specified, but %s is not an aggregate function",
- NameListToString(funcname), NameListToString(funcname));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("%s(*) specified, but %s is not an aggregate function",
+ NameListToString(funcname),
+ NameListToString(funcname))));
if (agg_distinct)
- elog(ERROR, "DISTINCT specified, but %s is not an aggregate function",
- NameListToString(funcname));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("DISTINCT specified, but %s is not an aggregate function",
+ NameListToString(funcname))));
}
else if (fdresult != FUNCDETAIL_AGGREGATE)
{
colname);
relTypeId = exprType(first_arg);
if (!ISCOMPLEX(relTypeId))
- elog(ERROR, "Attribute notation .%s applied to type %s, which is not a complex type",
- colname, format_type_be(relTypeId));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("attribute notation .%s applied to type %s, which is not a complex type",
+ colname, format_type_be(relTypeId))));
else
- elog(ERROR, "Attribute \"%s\" not found in datatype %s",
- colname, format_type_be(relTypeId));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("attribute \"%s\" not found in datatype %s",
+ colname, format_type_be(relTypeId))));
}
/*
actual_arg_types)),
errhint("Unable to choose a best candidate function. "
"You may need to add explicit typecasts.")));
-
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
retval = (Node *) aggref;
if (retset)
- elog(ERROR, "Aggregates may not return sets");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("aggregates may not return sets")));
}
return retval;
ObjectIdGetDatum(best_candidate->oid),
0, 0, 0);
if (!HeapTupleIsValid(ftup)) /* should not happen */
- elog(ERROR, "cache lookup of function %u failed",
+ elog(ERROR, "cache lookup failed for function %u",
best_candidate->oid);
pform = (Form_pg_proc) GETSTRUCT(ftup);
*rettype = pform->prorettype;
attno = get_attnum(relid, attname);
if (attno == InvalidAttrNumber)
- elog(ERROR, "Relation \"%s\" has no column \"%s\"",
- get_rel_name(relid), attname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("relation \"%s\" has no column \"%s\"",
+ get_rel_name(relid), attname)));
fselect->arg = (Expr *) input;
fselect->fieldnum = attno;
}
/*
- * Simple helper routine for delivering "No such attribute" error message
+ * Simple helper routine for delivering "no such attribute" error message
*/
static void
unknown_attribute(const char *schemaname, const char *relname,
const char *attname)
{
if (schemaname)
- elog(ERROR, "No such attribute %s.%s.%s",
- schemaname, relname, attname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("no such attribute %s.%s.%s",
+ schemaname, relname, attname)));
else
- elog(ERROR, "No such attribute %s.%s",
- relname, attname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("no such attribute %s.%s",
+ relname, attname)));
}
/*
if (noError)
return InvalidOid;
if (basetype == ANYOID)
- elog(ERROR, "aggregate %s(*) does not exist",
- NameListToString(aggname));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("aggregate %s(*) does not exist",
+ NameListToString(aggname))));
else
- elog(ERROR, "aggregate %s(%s) does not exist",
- NameListToString(aggname), format_type_be(basetype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("aggregate %s(%s) does not exist",
+ NameListToString(aggname),
+ format_type_be(basetype))));
}
/* Make sure it's an aggregate */
ObjectIdGetDatum(oid),
0, 0, 0);
if (!HeapTupleIsValid(ftup)) /* should not happen */
- elog(ERROR, "function %u not found", oid);
+ elog(ERROR, "cache lookup failed for function %u", oid);
pform = (Form_pg_proc) GETSTRUCT(ftup);
if (!pform->proisagg)
if (noError)
return InvalidOid;
/* we do not use the (*) notation for functions... */
- elog(ERROR, "function %s(%s) is not an aggregate",
- NameListToString(aggname), format_type_be(basetype));
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("function %s(%s) is not an aggregate",
+ NameListToString(aggname), format_type_be(basetype))));
}
ReleaseSysCache(ftup);
}
if (!noError)
- elog(ERROR, "function %s does not exist",
- func_signature_string(funcname, nargs, argtypes));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("function %s does not exist",
+ func_signature_string(funcname, nargs, argtypes))));
return InvalidOid;
}
MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid));
argcount = length(argtypes);
if (argcount > FUNC_MAX_ARGS)
- elog(ERROR, "functions cannot have more than %d arguments",
- FUNC_MAX_ARGS);
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
+ errmsg("functions cannot have more than %d arguments",
+ FUNC_MAX_ARGS)));
for (i = 0; i < argcount; i++)
{
argoids[i] = LookupTypeName(t);
if (!OidIsValid(argoids[i]))
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(t));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type \"%s\" does not exist",
+ TypeNameToString(t))));
argtypes = lnext(argtypes);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.69 2003/07/04 02:51:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.70 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
leftoid = LookupTypeName(oprleft);
if (!OidIsValid(leftoid))
- elog(ERROR, "type %s does not exist",
- TypeNameToString(oprleft));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type %s does not exist",
+ TypeNameToString(oprleft))));
}
if (oprright == NULL)
rightoid = InvalidOid;
{
rightoid = LookupTypeName(oprright);
if (!OidIsValid(rightoid))
- elog(ERROR, "type %s does not exist",
- TypeNameToString(oprright));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type %s does not exist",
+ TypeNameToString(oprright))));
}
return LookupOperName(opername, leftoid, rightoid, noError);
}
}
if (!noError)
- elog(ERROR, "unable to identify an equality operator for type %s",
- format_type_be(argtype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("unable to identify an equality operator for type %s",
+ format_type_be(argtype))));
return NULL;
}
}
}
if (!noError)
- elog(ERROR, "unable to identify an ordering operator for type %s"
- "\n\tUse an explicit ordering operator or modify the query",
- format_type_be(argtype));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("unable to identify an ordering operator for type %s",
+ format_type_be(argtype)),
+ errhint("Use an explicit ordering operator or modify the query.")));
return NULL;
}
ReleaseSysCache(optup);
if (!noError)
- elog(ERROR, "operator requires run-time type coercion: %s",
- op_signature_string(op, 'b', arg1, arg2));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("operator requires run-time type coercion: %s",
+ op_signature_string(op, 'b', arg1, arg2))));
return (Operator) NULL;
}
{
rtypeId = get_element_type(atypeId);
if (!OidIsValid(rtypeId))
- elog(ERROR, "op ANY/ALL (array) requires array on right side");
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("op ANY/ALL (array) requires array on right side")));
}
/* Now resolve the operator */
* Check that operator result is boolean
*/
if (rettype != BOOLOID)
- elog(ERROR, "op ANY/ALL (array) requires operator to yield boolean");
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("op ANY/ALL (array) requires operator to yield boolean")));
if (get_func_retset(opform->oprcode))
- elog(ERROR, "op ANY/ALL (array) requires operator not to return a set");
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("op ANY/ALL (array) requires operator not to return a set")));
/*
* Now switch back to the array type on the right, arranging for
*/
res_atypeId = get_array_type(declared_arg_types[1]);
if (!OidIsValid(res_atypeId))
- elog(ERROR, "unable to find datatype for array of %s",
- format_type_be(declared_arg_types[1]));
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("unable to find datatype for array of %s",
+ format_type_be(declared_arg_types[1]))));
actual_arg_types[1] = atypeId;
declared_arg_types[1] = res_atypeId;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.108 2003/06/19 23:22:40 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.109 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
len = pg_mbcliplen(literalbuf, literallen,
NAMEDATALEN-1);
- elog(NOTICE, "identifier \"%s\" will be truncated to \"%.*s\"",
- literalbuf, len, literalbuf);
+ ereport(NOTICE,
+ (errcode(ERRCODE_NAME_TOO_LONG),
+ errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
+ literalbuf, len, literalbuf)));
literalbuf[len] = '\0';
literallen = len;
}
int len;
len = pg_mbcliplen(ident, i, NAMEDATALEN-1);
- elog(NOTICE, "identifier \"%s\" will be truncated to \"%.*s\"",
- ident, len, ident);
+ ereport(NOTICE,
+ (errcode(ERRCODE_NAME_TOO_LONG),
+ errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
+ ident, len, ident)));
ident[len] = '\0';
}
yylval.str = ident;
if (*loc == YY_END_OF_BUFFER_CHAR)
{
- /* translator: %s is typically "syntax error" */
ereport(ERROR,
- (errmsg("%s at end of input", message),
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ /* translator: %s is typically "syntax error" */
+ errmsg("%s at end of input", message),
errposition(cursorpos)));
}
else
{
- /* translator: first %s is typically "syntax error" */
ereport(ERROR,
- (errmsg("%s at or near \"%s\"", message, loc),
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ /* translator: first %s is typically "syntax error" */
+ errmsg("%s at or near \"%s\"", message, loc),
errposition(cursorpos)));
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.112 2003/06/30 16:47:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.113 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
edata->filename = filename;
edata->lineno = lineno;
edata->funcname = funcname;
- edata->sqlerrcode = ERRCODE_INTERNAL_ERROR; /* default errcode */
+ /* Select default errcode based on elevel */
+ if (elevel >= ERROR)
+ edata->sqlerrcode = ERRCODE_INTERNAL_ERROR;
+ else if (elevel == WARNING)
+ edata->sqlerrcode = ERRCODE_WARNING;
+ else
+ edata->sqlerrcode = ERRCODE_SUCCESSFUL_COMPLETION;
/* errno is saved here so that error parameter eval can't change it */
edata->saved_errno = errno;
/*
+ * errcode_for_file_access --- add SQLSTATE error code to the current error
+ *
+ * The SQLSTATE code is chosen based on the saved errno value. We assume
+ * that the failing operation was some type of disk file access.
+ *
+ * NOTE: the primary error message string should generally include %m
+ * when this is used.
+ */
+int
+errcode_for_file_access(void)
+{
+ ErrorData *edata = &errordata[errordata_stack_depth];
+
+ /* we don't bother incrementing recursion_depth */
+ CHECK_STACK_DEPTH();
+
+ switch (edata->saved_errno)
+ {
+ /* Permission-denied failures */
+ case EPERM: /* Not super-user */
+ case EACCES: /* Permission denied */
+#ifdef EROFS
+ case EROFS: /* Read only file system */
+#endif
+ edata->sqlerrcode = ERRCODE_INSUFFICIENT_PRIVILEGE;
+ break;
+
+ /* Object not found */
+ case ENOENT: /* No such file or directory */
+ edata->sqlerrcode = ERRCODE_UNDEFINED_OBJECT;
+ break;
+
+ /* Duplicate object */
+ case EEXIST: /* File exists */
+ edata->sqlerrcode = ERRCODE_DUPLICATE_OBJECT;
+ break;
+
+ /* Wrong object type or state */
+ case ENOTDIR: /* Not a directory */
+ case EISDIR: /* Is a directory */
+ case ENOTEMPTY: /* Directory not empty */
+ edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
+ break;
+
+ /* Insufficient resources */
+ case ENOSPC: /* No space left on device */
+ edata->sqlerrcode = ERRCODE_DISK_FULL;
+ break;
+
+ case ENFILE: /* File table overflow */
+ case EMFILE: /* Too many open files */
+ edata->sqlerrcode = ERRCODE_INSUFFICIENT_RESOURCES;
+ break;
+
+ /* Hardware failure */
+ case EIO: /* I/O error */
+ edata->sqlerrcode = ERRCODE_IO_ERROR;
+ break;
+
+ /* All else is classified as internal errors */
+ default:
+ edata->sqlerrcode = ERRCODE_INTERNAL_ERROR;
+ break;
+ }
+
+ return 0; /* return value does not matter */
+}
+
+
+/*
* This macro handles expansion of a format string and associated parameters;
* it's common code for errmsg(), errdetail(), etc. Must be called inside
* a routine that is declared like "const char *fmt, ..." and has an edata
if ((fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY,
0666)) < 0)
ereport(FATAL,
- (errmsg("failed to open %s: %m", OutputFileName)));
+ (errcode_for_file_access(),
+ errmsg("failed to open \"%s\": %m", OutputFileName)));
istty = isatty(fd);
close(fd);
*/
if (!freopen(OutputFileName, "a", stderr))
ereport(FATAL,
- (errmsg("failed to reopen %s as stderr: %m",
+ (errcode_for_file_access(),
+ errmsg("failed to reopen \"%s\" as stderr: %m",
OutputFileName)));
/*
if (istty && IsUnderPostmaster)
if (!freopen(OutputFileName, "a", stdout))
ereport(FATAL,
- (errmsg("failed to reopen %s as stdout: %m",
+ (errcode_for_file_access(),
+ errmsg("failed to reopen \"%s\" as stdout: %m",
OutputFileName)));
}
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.60 2003/05/27 17:49:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.61 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*
* If the function is not found, we raise an error if signalNotFound is true,
* else return (PGFunction) NULL. Note that errors in loading the library
- * will provoke elog regardless of signalNotFound.
+ * will provoke ereport() regardless of signalNotFound.
*
* If filehandle is not NULL, then *filehandle will be set to a handle
* identifying the library file. The filehandle can be used with
* Check for same files - different paths (ie, symlink or link)
*/
if (stat(fullname, &stat_buf) == -1)
- elog(ERROR, "stat failed on file '%s': %m", fullname);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not access file \"%s\": %m", fullname)));
for (file_scanner = file_list;
file_scanner != (DynamicFileList *) NULL &&
file_scanner = (DynamicFileList *)
malloc(sizeof(DynamicFileList) + strlen(fullname));
if (file_scanner == NULL)
- elog(ERROR, "Out of memory in load_external_function");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
+ errmsg("out of memory")));
MemSet((char *) file_scanner, 0, sizeof(DynamicFileList));
strcpy(file_scanner->filename, fullname);
{
load_error = (char *) pg_dlerror();
free((char *) file_scanner);
- elog(ERROR, "Load of file %s failed: %s", fullname, load_error);
+ /* errcode_for_file_access might not be appropriate here? */
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not load library \"%s\": %s",
+ fullname, load_error)));
}
/* OK to link it into list */
retval = pg_dlsym(file_scanner->handle, funcname);
if (retval == (PGFunction) NULL && signalNotFound)
- elog(ERROR, "Can't find function %s in file %s", funcname, fullname);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("could not find function \"%s\" in file \"%s\"",
+ funcname, fullname)));
pfree(fullname);
return retval;
* good error message if bogus file name given.
*/
if (stat(fullname, &stat_buf) == -1)
- elog(ERROR, "LOAD: could not open file '%s': %m", fullname);
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not access file \"%s\": %m", fullname)));
if (file_list != (DynamicFileList *) NULL)
{
if (stat(name, &st) == 0)
return S_ISDIR(st.st_mode) ? false : true;
else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
- elog(ERROR, "stat failed on %s: %s", name, strerror(errno));
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not access file \"%s\": %m", name)));
return false;
}
if (strncmp(name, "$libdir", macroname_len) == 0)
replacement = PKGLIBDIR;
else
- elog(ERROR, "invalid macro name in dynamic library path");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("invalid macro name in dynamic library path")));
if (name[macroname_len] == '\0')
return pstrdup(replacement);
len = strcspn(p, ":");
if (len == 0)
- elog(ERROR, "zero length dynamic_library_path component");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("zero-length component in DYNAMIC_LIBRARY_PATH")));
piece = palloc(len + 1);
strncpy(piece, p, len);
/* only absolute paths */
if (!is_absolute_path(mangled))
- elog(ERROR, "dynamic_library_path component is not absolute");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("DYNAMIC_LIBRARY_PATH component is not absolute")));
full = palloc(strlen(mangled) + 1 + baselen + 1);
sprintf(full, "%s/%s", mangled, basename);
pfree(mangled);
- elog(DEBUG3, "find_in_dynamic_libpath: trying %s", full);
+ elog(DEBUG3, "find_in_dynamic_libpath: trying \"%s\"", full);
if (file_exists(full))
return full;
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: elog.h,v 1.47 2003/07/14 23:36:15 tgl Exp $
+ * $Id: elog.h,v 1.48 2003/07/18 23:20:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#define ERRCODE_INTERNAL_ERROR MAKE_SQLSTATE('X','X', '0','0','0')
#define ERRCODE_INSUFFICIENT_PRIVILEGE MAKE_SQLSTATE('4','2', '5','0','1')
#define ERRCODE_SYNTAX_ERROR MAKE_SQLSTATE('4','2', '6','0','1')
+#define ERRCODE_INVALID_NAME MAKE_SQLSTATE('4','2', '6','0','2')
+#define ERRCODE_NAME_TOO_LONG MAKE_SQLSTATE('4','2', '6','2','2')
+#define ERRCODE_RESERVED_NAME MAKE_SQLSTATE('4','2', '9','3','9')
#define ERRCODE_UNTERMINATED_LITERAL MAKE_SQLSTATE('4','2', '6','0','3')
#define ERRCODE_INVALID_LITERAL MAKE_SQLSTATE('4','2', '6','0','6')
+#define ERRCODE_STATEMENT_TOO_COMPLEX MAKE_SQLSTATE('5','4', '0','0','1')
#define ERRCODE_TOO_MANY_ARGUMENTS MAKE_SQLSTATE('4','2', '6','0','5')
-#define ERRCODE_UNDEFINED_COLUMN MAKE_SQLSTATE('4','2', '7','0','3')
+#define ERRCODE_TOO_MANY_COLUMNS MAKE_SQLSTATE('5','4', '0','1','1')
/*
* Note: use the above SQL-standard error codes for undefined catalog, schema,
- * prepared statement, or cursor names. Curiously, they don't define error
- * codes for any other kinds of objects. We choose to define an errcode for
- * undefined tables, as well as one for functions (also used for operators);
- * all other names (rules, triggers, etc) are lumped as UNDEFINED_OBJECT.
- * The same breakdown is used for "ambiguous" and "duplicate" complaints.
+ * prepared statement, and cursor names. Curiously, they don't define error
+ * codes for any other kinds of objects. We choose to define separate error
+ * codes for undefined table and column names, as well as one for functions
+ * (also used for operators). All other names (rules, triggers, etc) are
+ * lumped as UNDEFINED_OBJECT.
+ * The same breakdown is used for "ambiguous" and "duplicate" complaints,
+ * as well as complaints associated with incorrect declarations.
*/
-#define ERRCODE_UNDEFINED_TABLE MAKE_SQLSTATE('4','2', '7','0','4')
+#define ERRCODE_UNDEFINED_COLUMN MAKE_SQLSTATE('4','2', '7','0','3')
+#define ERRCODE_UNDEFINED_CURSOR ERRCODE_INVALID_CURSOR_NAME
+#define ERRCODE_UNDEFINED_DATABASE ERRCODE_INVALID_CATALOG_NAME
#define ERRCODE_UNDEFINED_FUNCTION MAKE_SQLSTATE('4','2', '8','8','3')
+#define ERRCODE_UNDEFINED_PSTATEMENT ERRCODE_INVALID_SQL_STATEMENT_NAME
+#define ERRCODE_UNDEFINED_SCHEMA ERRCODE_INVALID_SCHEMA_NAME
+#define ERRCODE_UNDEFINED_TABLE MAKE_SQLSTATE('4','2', '7','0','4')
#define ERRCODE_UNDEFINED_OBJECT MAKE_SQLSTATE('4','2', '7','0','5')
+#define ERRCODE_UNDEFINED_PARAMETER MAKE_SQLSTATE('4','2', '7','1','5')
#define ERRCODE_AMBIGUOUS_COLUMN MAKE_SQLSTATE('4','2', '7','0','2')
#define ERRCODE_AMBIGUOUS_FUNCTION MAKE_SQLSTATE('4','2', '7','2','5')
+#define ERRCODE_AMBIGUOUS_PARAMETER MAKE_SQLSTATE('4','2', '7','1','6')
#define ERRCODE_DUPLICATE_COLUMN MAKE_SQLSTATE('4','2', '7','1','1')
-#define ERRCODE_DUPLICATE_TABLE MAKE_SQLSTATE('4','2', '7','2','2')
+#define ERRCODE_DUPLICATE_CURSOR ERRCODE_DUPLICATE_OBJECT
+#define ERRCODE_DUPLICATE_DATABASE ERRCODE_DUPLICATE_OBJECT
#define ERRCODE_DUPLICATE_FUNCTION MAKE_SQLSTATE('4','2', '7','2','3')
+#define ERRCODE_DUPLICATE_PSTATEMENT ERRCODE_DUPLICATE_OBJECT
+#define ERRCODE_DUPLICATE_SCHEMA ERRCODE_DUPLICATE_OBJECT
+#define ERRCODE_DUPLICATE_TABLE MAKE_SQLSTATE('4','2', '7','2','2')
#define ERRCODE_DUPLICATE_OBJECT MAKE_SQLSTATE('4','2', '7','1','0')
+#define ERRCODE_INVALID_COLUMN_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','1')
+#define ERRCODE_INVALID_CURSOR_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','2')
+#define ERRCODE_INVALID_DATABASE_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','3')
+#define ERRCODE_INVALID_FUNCTION_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','4')
+#define ERRCODE_INVALID_PSTATEMENT_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','5')
+#define ERRCODE_INVALID_SCHEMA_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','6')
+#define ERRCODE_INVALID_TABLE_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','7')
+#define ERRCODE_INVALID_OBJECT_DEFINITION MAKE_SQLSTATE('4','2', 'A','0','8')
+#define ERRCODE_WRONG_OBJECT_TYPE MAKE_SQLSTATE('4','2', '8','0','9')
+#define ERRCODE_OBJECT_IN_USE MAKE_SQLSTATE('5','5', '0','0','6')
#define ERRCODE_GROUPING_ERROR MAKE_SQLSTATE('4','2', '8','0','3')
#define ERRCODE_TYPE_MISMATCH MAKE_SQLSTATE('4','2', '8','0','4')
#define ERRCODE_CANNOT_COERCE MAKE_SQLSTATE('4','2', '8','4','6')
#define ERRCODE_INVALID_FOREIGN_KEY MAKE_SQLSTATE('4','2', '8','3','0')
+#define ERRCODE_TOO_MANY_CONNECTIONS MAKE_SQLSTATE('5','7', '0','3','2')
+#define ERRCODE_DISK_FULL MAKE_SQLSTATE('5','4', '1','0','0')
+#define ERRCODE_INSUFFICIENT_RESOURCES MAKE_SQLSTATE('5','4', '2','0','0')
+#define ERRCODE_IO_ERROR MAKE_SQLSTATE('5','8', '0','3','0')
/* Which __func__ symbol do we have, if any? */
/*----------
* New-style error reporting API: to be used in this way:
* ereport(ERROR,
- * (errcode(ERRCODE_INVALID_CURSOR_NAME),
+ * (errcode(ERRCODE_UNDEFINED_CURSOR),
* errmsg("portal \"%s\" not found", stmt->portalname),
* ... other errxxx() fields as needed ...));
*
* The error level is required, and so is a primary error message (errmsg
* or errmsg_internal). All else is optional. errcode() defaults to
- * ERRCODE_INTERNAL_ERROR.
+ * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
+ * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
+ * NOTICE or below.
*----------
*/
#define ereport(elevel, rest) \
extern int errcode(int sqlerrcode);
+extern int errcode_for_file_access(void);
+
extern int errmsg(const char *fmt, ...)
/* This extension allows gcc to check the format string for consistency with
the supplied arguments. */
select a from atacc1;
ERROR: Attribute "a" not found
select atacc1.a from atacc1;
-ERROR: No such attribute atacc1.a
+ERROR: no such attribute atacc1.a
select b,c,d from atacc1;
b | c | d
---+---+---
select "........pg.dropped.1........" from atacc1;
ERROR: Attribute "........pg.dropped.1........" not found
select atacc1."........pg.dropped.1........" from atacc1;
-ERROR: No such attribute atacc1.........pg.dropped.1........
+ERROR: no such attribute atacc1.........pg.dropped.1........
select "........pg.dropped.1........",b,c,d from atacc1;
ERROR: Attribute "........pg.dropped.1........" not found
select * from atacc1 where "........pg.dropped.1........" = 1;
RETURNS int42
AS 'int4in'
LANGUAGE 'internal' WITH (isStrict);
-NOTICE: ProcedureCreate: type int42 is not yet defined
+NOTICE: type int42 is not yet defined
+DETAIL: Creating a shell type definition.
CREATE FUNCTION int42_out(int42)
RETURNS cstring
AS 'int4out'
LANGUAGE 'internal' WITH (isStrict);
-NOTICE: Argument type "int42" is only a shell
+NOTICE: argument type int42 is only a shell
CREATE FUNCTION text_w_default_in(cstring)
RETURNS text_w_default
AS 'textin'
LANGUAGE 'internal' WITH (isStrict);
-NOTICE: ProcedureCreate: type text_w_default is not yet defined
+NOTICE: type text_w_default is not yet defined
+DETAIL: Creating a shell type definition.
CREATE FUNCTION text_w_default_out(text_w_default)
RETURNS cstring
AS 'textout'
LANGUAGE 'internal' WITH (isStrict);
-NOTICE: Argument type "text_w_default" is only a shell
+NOTICE: argument type text_w_default is only a shell
CREATE TYPE int42 (
internallength = 4,
input = int42_in,
CREATE USER regressuser3;
CREATE USER regressuser4;
CREATE USER regressuser4; -- duplicate
-ERROR: CREATE USER: user name "regressuser4" already exists
+ERROR: user "regressuser4" already exists
CREATE GROUP regressgroup1;
CREATE GROUP regressgroup2 WITH USER regressuser1, regressuser2;
ALTER GROUP regressgroup1 ADD USER regressuser4;
ALTER GROUP regressgroup2 ADD USER regressuser2; -- duplicate
-WARNING: ALTER GROUP: user "regressuser2" is already in group "regressgroup2"
+WARNING: user "regressuser2" is already in group "regressgroup2"
ALTER GROUP regressgroup2 DROP USER regressuser2;
ALTER GROUP regressgroup2 ADD USER regressuser4;
-- test owner privileges
RETURNS widget
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
-NOTICE: ProcedureCreate: type widget is not yet defined
+NOTICE: type widget is not yet defined
+DETAIL: Creating a shell type definition.
CREATE FUNCTION widget_out(widget)
RETURNS cstring
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
-NOTICE: Argument type "widget" is only a shell
+NOTICE: argument type widget is only a shell
CREATE FUNCTION int44in(cstring)
RETURNS city_budget
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
-NOTICE: ProcedureCreate: type city_budget is not yet defined
+NOTICE: type city_budget is not yet defined
+DETAIL: Creating a shell type definition.
CREATE FUNCTION int44out(city_budget)
RETURNS cstring
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
-NOTICE: Argument type "city_budget" is only a shell
+NOTICE: argument type city_budget is only a shell
CREATE FUNCTION check_primary_key ()
RETURNS trigger
AS '@abs_builddir@/../../../contrib/spi/refint@DLSUFFIX@'
-- Things that shouldn't work:
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT ''not an integer'';';
-ERROR: return type mismatch in function: declared to return integer, returns "unknown"
+ERROR: return type mismatch in function declared to return integer
+DETAIL: Actual return type is "unknown".
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'not even SQL';
ERROR: syntax error at or near "not" at character 1
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT 1, 2, 3;';
-ERROR: function declared to return integer returns multiple columns in final SELECT
+ERROR: return type mismatch in function declared to return integer
+DETAIL: Final SELECT must return exactly one column.
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT $2;';
-ERROR: Parameter '$2' is out of range
+ERROR: there is no parameter $2
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'a', 'b';
-ERROR: CREATE FUNCTION: only one AS item needed for sql language
+ERROR: only one AS item needed for language "sql"
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE c
AS 'nosuchfile';
-ERROR: stat failed on file 'nosuchfile': No such file or directory
+ERROR: could not access file "nosuchfile": No such file or directory
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE c
AS '@abs_builddir@/regress@DLSUFFIX@', 'nosuchsymbol';
-ERROR: Can't find function nosuchsymbol in file @abs_builddir@/regress@DLSUFFIX@
+ERROR: could not find function "nosuchsymbol" in file "@abs_builddir@/regress@DLSUFFIX@"
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal
AS 'nosuch';
ERROR: there is no built-in function named "nosuch"