mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Convert the reg* input functions to report (most) errors softly.
This is not really complete, but it catches most cases of practical interest. The main omissions are: * regtype, regprocedure, and regoperator parse type names by calling the main grammar, so any grammar-detected syntax error will still be a hard error. Also, if one includes a type modifier in such a type specification, errors detected by the typmodin function will be hard errors. * Lookup errors are handled just by passing missing_ok = true to the relevant catalog lookup function. Because we've used quite a restrictive definition of "missing_ok", this means that edge cases such as "the named schema exists, but you lack USAGE permission on it" are still hard errors. It would make sense to me to replace most/all missing_ok parameters with an escontext parameter and then allow these additional lookup failure cases to be trapped too. But that's a job for some other day. Discussion: https://postgr.es/m/3342239.1671988406@sss.pgh.pa.us
This commit is contained in:
31
src/backend/utils/cache/ts_cache.c
vendored
31
src/backend/utils/cache/ts_cache.c
vendored
@ -38,6 +38,7 @@
|
||||
#include "catalog/pg_ts_template.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/miscnodes.h"
|
||||
#include "tsearch/ts_cache.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/catcache.h"
|
||||
@ -556,6 +557,8 @@ lookup_ts_config_cache(Oid cfgId)
|
||||
Oid
|
||||
getTSCurrentConfig(bool emitError)
|
||||
{
|
||||
List *namelist;
|
||||
|
||||
/* if we have a cached value, return it */
|
||||
if (OidIsValid(TSCurrentConfigCache))
|
||||
return TSCurrentConfigCache;
|
||||
@ -576,9 +579,22 @@ getTSCurrentConfig(bool emitError)
|
||||
}
|
||||
|
||||
/* Look up the config */
|
||||
TSCurrentConfigCache =
|
||||
get_ts_config_oid(stringToQualifiedNameList(TSCurrentConfig),
|
||||
!emitError);
|
||||
if (emitError)
|
||||
{
|
||||
namelist = stringToQualifiedNameList(TSCurrentConfig, NULL);
|
||||
TSCurrentConfigCache = get_ts_config_oid(namelist, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorSaveContext escontext = {T_ErrorSaveContext};
|
||||
|
||||
namelist = stringToQualifiedNameList(TSCurrentConfig,
|
||||
(Node *) &escontext);
|
||||
if (namelist != NIL)
|
||||
TSCurrentConfigCache = get_ts_config_oid(namelist, true);
|
||||
else
|
||||
TSCurrentConfigCache = InvalidOid; /* bad name list syntax */
|
||||
}
|
||||
|
||||
return TSCurrentConfigCache;
|
||||
}
|
||||
@ -594,12 +610,19 @@ check_default_text_search_config(char **newval, void **extra, GucSource source)
|
||||
*/
|
||||
if (IsTransactionState() && MyDatabaseId != InvalidOid)
|
||||
{
|
||||
ErrorSaveContext escontext = {T_ErrorSaveContext};
|
||||
List *namelist;
|
||||
Oid cfgId;
|
||||
HeapTuple tuple;
|
||||
Form_pg_ts_config cfg;
|
||||
char *buf;
|
||||
|
||||
cfgId = get_ts_config_oid(stringToQualifiedNameList(*newval), true);
|
||||
namelist = stringToQualifiedNameList(*newval,
|
||||
(Node *) &escontext);
|
||||
if (namelist != NIL)
|
||||
cfgId = get_ts_config_oid(namelist, true);
|
||||
else
|
||||
cfgId = InvalidOid; /* bad name list syntax */
|
||||
|
||||
/*
|
||||
* When source == PGC_S_TEST, don't throw a hard error for a
|
||||
|
Reference in New Issue
Block a user