@@ -761,30 +761,6 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
761761 errmsg ("writable %s catalog iceberg tables do not "
762762 "allow explicit catalog options" , hasObjectStoreCatalogOption ? "object store" : "REST" )));
763763 }
764-
765- if (hasRestCatalogOption )
766- {
767- /*
768- * For writable rest catalog iceberg tables, we register the
769- * namespace in the rest catalog. We do that early in the
770- * command processing so that any errors in the registration
771- * are caught before we create the actual table.
772- *
773- * Note that registering a namespace is not a transactional
774- * operation from pg_lake's perspective. If the subsequent
775- * table creation fails, the namespace registration will
776- * remain. We accept that tradeoff for simplicity as
777- * re-registering an existing namespace is a no-op. For a
778- * writable rest catalog iceberg table, the namespace is
779- * always the table's schema name. Similarly, the catalog name
780- * is always the database name. We normally encode that in
781- * GetRestCatalogName() etc., but here we need to do it early
782- * before the table is created.
783- */
784- RegisterNamespaceToRestCatalog (get_database_name (MyDatabaseId ),
785- get_namespace_name (namespaceId ),
786- hasExternalCatalogReadOnlyOption );
787- }
788764 }
789765 else if (createStmt -> base .tableElts == NIL && hasExternalCatalogReadOnlyOption )
790766 {
@@ -930,6 +906,31 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
930906 /* we currently only allow Iceberg tables in the managed storage region */
931907 ErrorIfNotInManagedStorageRegion (location );
932908
909+
910+ if (hasRestCatalogOption )
911+ {
912+ /* here we only deal with writable rest catalog iceberg tables */
913+ Assert (!HasReadOnlyOption (createStmt -> options ));
914+
915+ /*
916+ * For writable rest catalog iceberg tables, we register the namespace
917+ * in the rest catalog. We do that later in the command processing so
918+ * that any previous errors (e.g., table creation failures) prevents
919+ * us from registering the namespace.
920+ *
921+ * Note that registering a namespace is not a transactional operation
922+ * from pg_lake's perspective. If the subsequent table creation fails,
923+ * the namespace registration will remain. We accept that tradeoff for
924+ * simplicity as re-registering an existing namespace is a no-op. For
925+ * a writable rest catalog iceberg table, the namespace is always the
926+ * table's schema name. Similarly, the catalog name is always the
927+ * database name. We normally encode that in GetRestCatalogName()
928+ * etc., but here we need to do it early before the table is created.
929+ */
930+ RegisterNamespaceToRestCatalog (get_database_name (MyDatabaseId ),
931+ get_namespace_name (namespaceId ));
932+ }
933+
933934 bool hasRowIds = GetBoolOption (createStmt -> options , "row_ids" , false);
934935
935936 /* when a table has row_ids, we need to create a sequence */
0 commit comments