Skip to content

Commit 6468828

Browse files
sfc-gh-mslotclaude
andcommitted
Fix error messages and detect catalog_name changes in trigger
Fixed two issues with the external_catalog_modification trigger: 1. Changed error messages to match test expectations: - "modifying the internal catalog is currently only supported via pg_lake_iceberg tables" - This matches the expected error format in test_iceberg_catalog.py 2. Added validation to detect catalog_name changes during UPDATE: - Prevents changing a table from external catalog to internal catalog - Prevents changing a table from internal catalog to external catalog - These operations should only be done via CREATE/DROP TABLE Fixes CI test failures in: - test_create_in_internal_catalog - test_create_in_external_catalog All external write tests still pass (9/9). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e9341e5 commit 6468828

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

pg_lake_iceberg/src/iceberg/external_metadata_modification.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,25 @@ external_catalog_modification(PG_FUNCTION_ARGS)
114114
prevMetadataLocationIsNull ? NULL : TextDatumGetCString(prevMetadataLocationDatum);
115115

116116
char *databaseName = get_database_name(MyDatabaseId);
117+
bool isInternalCatalog = (strcmp(catalogName, databaseName) == 0);
117118

118-
if (strcmp(catalogName, databaseName) == 0)
119+
/* For UPDATE, check if catalog_name is being changed */
120+
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
121+
{
122+
Datum oldCatalogNameDatum = heap_getattr(trigdata->tg_trigtuple, 1,
123+
trigdata->tg_relation->rd_att, &isnull);
124+
char *oldCatalogName = TextDatumGetCString(oldCatalogNameDatum);
125+
bool wasInternalCatalog = (strcmp(oldCatalogName, databaseName) == 0);
126+
127+
if (isInternalCatalog != wasInternalCatalog)
128+
{
129+
ereport(ERROR,
130+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
131+
errmsg("modifying the internal catalog is currently only supported via pg_lake_iceberg tables")));
132+
}
133+
}
134+
135+
if (isInternalCatalog)
119136
{
120137
/*
121138
* For the current database catalog, only UPDATE is supported.
@@ -132,15 +149,13 @@ external_catalog_modification(PG_FUNCTION_ARGS)
132149
{
133150
ereport(ERROR,
134151
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
135-
errmsg("INSERT to the %s catalog is only supported via CREATE TABLE ... USING iceberg",
136-
databaseName)));
152+
errmsg("modifying the internal catalog is currently only supported via pg_lake_iceberg tables")));
137153
}
138154
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
139155
{
140156
ereport(ERROR,
141157
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
142-
errmsg("DELETE from the %s catalog is only supported via DROP TABLE",
143-
databaseName)));
158+
errmsg("modifying the internal catalog is currently only supported via pg_lake_iceberg tables")));
144159
}
145160
else
146161
{

0 commit comments

Comments
 (0)