@@ -291,37 +291,20 @@ ProtectExtensionCatalogServersHandler(ProcessUtilityParams *processUtilityParams
291291}
292292
293293
294- /*
295- * GetRestCatalogConnectionFromGUCs returns a RestCatalogConnectionInfo
296- * populated from the current GUC variables. Used for backward-compatible
297- * catalog='rest' tables.
298- */
299- RestCatalogConnectionInfo *
300- GetRestCatalogConnectionFromGUCs (void )
301- {
302- RestCatalogConnectionInfo * conn = palloc0 (sizeof (RestCatalogConnectionInfo ));
303-
304- conn -> serverName = REST_CATALOG_NAME ;
305- conn -> host = RestCatalogHost ;
306- conn -> oauthHostPath = RestCatalogOauthHostPath ;
307- conn -> clientId = RestCatalogClientId ;
308- conn -> clientSecret = RestCatalogClientSecret ;
309- conn -> scope = RestCatalogScope ;
310- conn -> authType = RestCatalogAuthType ;
311- conn -> enableVendedCredentials = RestCatalogEnableVendedCredentials ;
312-
313- return conn ;
314- }
315-
316-
317294/*
318295 * GetRestCatalogConnectionFromServer returns a RestCatalogConnectionInfo
319- * populated from the options of a ForeignServer (non-secret config) and
320- * its USER MAPPING (credentials) for the current user.
296+ * populated from the options of the named ForeignServer. GUC values are
297+ * used as defaults; any option explicitly set on the server overrides the
298+ * corresponding GUC. This applies to both the extension-owned 'rest'
299+ * server and user-created iceberg_catalog servers.
321300 */
322301RestCatalogConnectionInfo *
323302GetRestCatalogConnectionFromServer (const char * serverName )
324303{
304+ /* Normalize case-insensitive match to the canonical pre-created name */
305+ if (pg_strcasecmp (serverName , REST_CATALOG_NAME ) == 0 )
306+ serverName = REST_CATALOG_NAME ;
307+
325308 ForeignServer * server = GetForeignServerByName (serverName , false);
326309 ForeignDataWrapper * fdw = GetForeignDataWrapper (server -> fdwid );
327310
@@ -335,14 +318,14 @@ GetRestCatalogConnectionFromServer(const char *serverName)
335318
336319 conn -> serverName = pstrdup (serverName );
337320
338- /* Set defaults matching the GUC defaults */
339- conn -> host = NULL ;
340- conn -> oauthHostPath = "" ;
341- conn -> clientId = NULL ;
342- conn -> clientSecret = NULL ;
343- conn -> scope = "PRINCIPAL_ROLE:ALL" ;
344- conn -> authType = REST_CATALOG_AUTH_TYPE_DEFAULT ;
345- conn -> enableVendedCredentials = true ;
321+ /* GUC values serve as defaults; server options override below */
322+ conn -> host = RestCatalogHost ;
323+ conn -> oauthHostPath = RestCatalogOauthHostPath ;
324+ conn -> clientId = RestCatalogClientId ;
325+ conn -> clientSecret = RestCatalogClientSecret ;
326+ conn -> scope = RestCatalogScope ;
327+ conn -> authType = RestCatalogAuthType ;
328+ conn -> enableVendedCredentials = RestCatalogEnableVendedCredentials ;
346329
347330 ListCell * lc ;
348331
@@ -372,7 +355,7 @@ GetRestCatalogConnectionFromServer(const char *serverName)
372355 conn -> enableVendedCredentials = defGetBoolean (def );
373356 }
374357
375- if (conn -> host == NULL )
358+ if (conn -> host == NULL || conn -> host [ 0 ] == '\0' )
376359 ereport (ERROR ,
377360 (errcode (ERRCODE_FDW_OPTION_NAME_NOT_FOUND ),
378361 errmsg ("\"rest_endpoint\" option is required for iceberg_catalog server \"%s\"" ,
@@ -384,9 +367,9 @@ GetRestCatalogConnectionFromServer(const char *serverName)
384367
385368/*
386369 * GetRestCatalogConnectionForRelation returns the REST catalog connection
387- * info for the given relation. If the table uses catalog='rest', the
388- * connection is built from GUCs. Otherwise, the catalog option is treated
389- * as a server name and the connection is built from its options .
370+ * info for the given relation. The catalog option value is used as the
371+ * server name. For the extension-owned 'rest' server and user-created
372+ * servers alike, server options are read first with GUC fallback .
390373 */
391374RestCatalogConnectionInfo *
392375GetRestCatalogConnectionForRelation (Oid relationId )
@@ -399,9 +382,6 @@ GetRestCatalogConnectionForRelation(Oid relationId)
399382 (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
400383 errmsg ("catalog option is not set for relation %u" , relationId )));
401384
402- if (IsRestCatalogOwnedByExtension (catalog ))
403- return GetRestCatalogConnectionFromGUCs ();
404-
405385 return GetRestCatalogConnectionFromServer (catalog );
406386}
407387
0 commit comments