<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/alter_tsconfig.sgml,v 1.1 2007/08/21 21:08:47 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/alter_tsconfig.sgml,v 1.2 2007/08/22 05:13:50 tgl Exp $
PostgreSQL documentation
-->
<refsynopsisdiv>
<synopsis>
-ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> (
- PARSER = <replaceable class="parameter">parser_name</replaceable>
-)
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable>
ADD MAPPING FOR <replaceable class="parameter">token_type</replaceable> [, ... ] WITH <replaceable class="parameter">dictionary_name</replaceable> [, ... ]
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable>
<para>
<command>ALTER TEXT SEARCH CONFIGURATION</command> changes the definition of
- a text search configuration. You can change which parser it uses, modify
- its mapping from token types to dictionaries,
+ a text search configuration. You can modify
+ its mappings from token types to dictionaries,
or change the configuration's name or owner.
</para>
</listitem>
</varlistentry>
- <varlistentry>
- <term><replaceable class="parameter">parser_name</replaceable></term>
- <listitem>
- <para>
- The name of a new text search parser to use for this configuration.
- </para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><replaceable class="parameter">token_type</replaceable></term>
<listitem>
</para>
</refsect1>
-
- <refsect1>
- <title>Notes</title>
- <para>
- While changing the text search parser used by a configuration is allowed,
- this will only work nicely if old and new parsers use the same set of
- token types. It is advisable to drop the mappings for any incompatible
- token types before changing parsers.
- </para>
-
- </refsect1>
-
<refsect1>
<title>Examples</title>
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.3 2007/08/22 01:39:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.4 2007/08/22 05:13:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/syscache.h"
-static HeapTuple UpdateTSConfiguration(AlterTSConfigurationStmt *stmt,
- HeapTuple tup);
static void MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
- HeapTuple tup);
+ HeapTuple tup, Relation relMap);
static void DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
- HeapTuple tup);
+ HeapTuple tup, Relation relMap);
/* --------------------- TS Parser commands ------------------------ */
Oid namespaceoid;
char *cfgname;
NameData cname;
- List *sourceName = NIL;
Oid sourceOid = InvalidOid;
Oid prsOid = InvalidOid;
Oid cfgOid;
if (pg_strcasecmp(defel->defname, "parser") == 0)
prsOid = TSParserGetPrsid(defGetQualifiedName(defel), false);
else if (pg_strcasecmp(defel->defname, "copy") == 0)
- sourceName = defGetQualifiedName(defel);
+ sourceOid = TSConfigGetCfgid(defGetQualifiedName(defel), false);
else
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
defel->defname)));
}
+ if (OidIsValid(sourceOid) && OidIsValid(prsOid))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("cannot specify both PARSER and COPY options")));
+
/*
* Look up source config if given.
*/
- if (sourceName)
+ if (OidIsValid(sourceOid))
{
Form_pg_ts_config cfg;
- sourceOid = TSConfigGetCfgid(sourceName, false);
-
tup = SearchSysCache(TSCONFIGOID,
ObjectIdGetDatum(sourceOid),
0, 0, 0);
cfg = (Form_pg_ts_config) GETSTRUCT(tup);
- /* Use source's parser if no other was specified */
- if (!OidIsValid(prsOid))
- prsOid = cfg->cfgparser;
+ /* use source's parser */
+ prsOid = cfg->cfgparser;
ReleaseSysCache(tup);
}
AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
{
HeapTuple tup;
- HeapTuple newtup;
- Relation mapRel;
+ Relation relMap;
/* Find the configuration */
tup = GetTSConfigTuple(stmt->cfgname);
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
NameListToString(stmt->cfgname));
- /* Update fields of config tuple? */
- if (stmt->options)
- newtup = UpdateTSConfiguration(stmt, tup);
- else
- newtup = tup;
+ relMap = heap_open(TSConfigMapRelationId, RowExclusiveLock);
- /* Add or drop mappings? */
+ /* Add or drop mappings */
if (stmt->dicts)
- MakeConfigurationMapping(stmt, newtup);
+ MakeConfigurationMapping(stmt, tup, relMap);
else if (stmt->tokentype)
- DropConfigurationMapping(stmt, newtup);
-
- /*
- * Even if we aren't changing mappings, there could already be some,
- * so makeConfigurationDependencies always has to look.
- */
- mapRel = heap_open(TSConfigMapRelationId, AccessShareLock);
+ DropConfigurationMapping(stmt, tup, relMap);
/* Update dependencies */
- makeConfigurationDependencies(newtup, true, mapRel);
+ makeConfigurationDependencies(tup, true, relMap);
- heap_close(mapRel, AccessShareLock);
+ heap_close(relMap, RowExclusiveLock);
ReleaseSysCache(tup);
}
-/*
- * ALTER TEXT SEARCH CONFIGURATION - update fields of pg_ts_config tuple
- */
-static HeapTuple
-UpdateTSConfiguration(AlterTSConfigurationStmt *stmt, HeapTuple tup)
-{
- Relation cfgRel;
- ListCell *pl;
- Datum repl_val[Natts_pg_ts_config];
- char repl_null[Natts_pg_ts_config];
- char repl_repl[Natts_pg_ts_config];
- HeapTuple newtup;
-
- memset(repl_val, 0, sizeof(repl_val));
- memset(repl_null, ' ', sizeof(repl_null));
- memset(repl_repl, ' ', sizeof(repl_repl));
-
- cfgRel = heap_open(TSConfigRelationId, RowExclusiveLock);
-
- foreach(pl, stmt->options)
- {
- DefElem *defel = (DefElem *) lfirst(pl);
-
- if (pg_strcasecmp(defel->defname, "parser") == 0)
- {
- Oid newPrs;
-
- newPrs = TSParserGetPrsid(defGetQualifiedName(defel), false);
- repl_val[Anum_pg_ts_config_cfgparser - 1] = ObjectIdGetDatum(newPrs);
- repl_repl[Anum_pg_ts_config_cfgparser - 1] = 'r';
- }
- else
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("text search configuration parameter \"%s\" not recognized",
- defel->defname)));
- }
-
- newtup = heap_modifytuple(tup, RelationGetDescr(cfgRel),
- repl_val, repl_null, repl_repl);
-
- simple_heap_update(cfgRel, &newtup->t_self, newtup);
-
- CatalogUpdateIndexes(cfgRel, newtup);
-
- heap_close(cfgRel, RowExclusiveLock);
-
- return newtup;
-}
-
-/*------------------- TS Configuration mapping stuff ----------------*/
-
/*
* Translate a list of token type names to an array of token type numbers
*/
* ALTER TEXT SEARCH CONFIGURATION ADD/ALTER MAPPING
*/
static void
-MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
+MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
+ HeapTuple tup, Relation relMap)
{
Oid cfgId = HeapTupleGetOid(tup);
- Relation relMap;
ScanKeyData skey[2];
SysScanDesc scan;
HeapTuple maptup;
tokens = getTokenTypes(prsId, stmt->tokentype);
ntoken = list_length(stmt->tokentype);
- relMap = heap_open(TSConfigMapRelationId, RowExclusiveLock);
-
if (stmt->override)
{
/*
}
}
}
-
- heap_close(relMap, RowExclusiveLock);
}
/*
* ALTER TEXT SEARCH CONFIGURATION DROP MAPPING
*/
static void
-DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
+DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
+ HeapTuple tup, Relation relMap)
{
Oid cfgId = HeapTupleGetOid(tup);
- Relation relMap;
ScanKeyData skey[2];
SysScanDesc scan;
HeapTuple maptup;
tokens = getTokenTypes(prsId, stmt->tokentype);
ntoken = list_length(stmt->tokentype);
- relMap = heap_open(TSConfigMapRelationId, RowExclusiveLock);
-
i = 0;
foreach(c, stmt->tokentype)
{
i++;
}
-
- heap_close(relMap, RowExclusiveLock);
}