Hello list,
I have a use case where an extension dependency can be satisfied by one
of five other extensions. Currently I'm unable to express that in the
extension control file, since the elements from 'requires' are currently
searched on exact name match. The attached patch changes this behaviour
for list elements that end with a *, into prefix matching, so that e.g.
table* matches tablefunc.
This allows me to specify in a controlfile
requires 'vocab*'
which is satisfied by having either one of the following extensions loaded:
vocab2005
vocab2006
vocab2008
vocab2009
vocab2010
thoughts?
regards,
Yeb Havinga
--
Yeb Havinga
http://www.mgrid.net/
Mastering Medical Data
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
new file mode 100644
index 278bbcf..5bf7f8e
*** a/src/backend/commands/extension.c
--- b/src/backend/commands/extension.c
*************** static void ApplyExtensionUpdates(Oid ex
*** 114,145 ****
Oid
get_extension_oid(const char *extname, bool missing_ok)
{
! Oid result;
! Relation rel;
SysScanDesc scandesc;
HeapTuple tuple;
ScanKeyData entry[1];
rel = heap_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0],
Anum_pg_extension_extname,
! BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(extname));
! scandesc = systable_beginscan(rel, ExtensionNameIndexId, true,
! SnapshotNow, 1, entry);
! tuple = systable_getnext(scandesc);
! /* We assume that there can be at most one matching tuple */
! if (HeapTupleIsValid(tuple))
! result = HeapTupleGetOid(tuple);
! else
! result = InvalidOid;
! systable_endscan(scandesc);
heap_close(rel, AccessShareLock);
if (!OidIsValid(result) && !missing_ok)
--- 114,152 ----
Oid
get_extension_oid(const char *extname, bool missing_ok)
{
! Oid result = InvalidOid;
! Relation rel, idx;
SysScanDesc scandesc;
HeapTuple tuple;
ScanKeyData entry[1];
+ int len = strlen(extname) - 1;
+ bool wildcard = (extname[len] == '*');
rel = heap_open(ExtensionRelationId, AccessShareLock);
+ idx = index_open(ExtensionNameIndexId, AccessShareLock);
ScanKeyInit(&entry[0],
Anum_pg_extension_extname,
! BTGreaterEqualStrategyNumber,
! F_NAMEGE,
CStringGetDatum(extname));
! scandesc = systable_beginscan_ordered(rel, idx,
! SnapshotNow, 1, entry);
! if (HeapTupleIsValid(tuple = systable_getnext_ordered(scandesc, ForwardScanDirection)))
! {
! Form_pg_extension form = (Form_pg_extension) GETSTRUCT(tuple);
! if (wildcard
! ? (strncmp(extname, NameStr(form->extname), len) == 0)
! : (strcmp(extname, NameStr(form->extname)) == 0))
! result = HeapTupleGetOid(tuple);
! }
! systable_endscan_ordered(scandesc);
+ index_close(idx, AccessShareLock);
heap_close(rel, AccessShareLock);
if (!OidIsValid(result) && !missing_ok)
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers