从 2025 年 11 月 1 日起,Amazon Redshift 将不再支持创建新的 Python UDF。如果您想要使用 Python UDF,请在该日期之前创建 UDF。现有的 Python UDF 将继续正常运行。有关更多信息,请参阅博客文章
将 ListDatabases 和 Amazon SDK 搭配使用
以下代码示例演示如何使用 ListDatabases。
- .NET
-
- 适用于 .NET 的 Amazon SDK (v4)
-
注意
查看 GitHub,了解更多信息。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /// <summary> /// List databases in a Redshift cluster. /// </summary> /// <param name="clusterIdentifier">The cluster identifier.</param> /// <param name="dbUser">The database user.</param> /// <param name="dbUser">The database name for authentication.</param> /// <returns>A list of database names.</returns> public async Task<List<string>> ListDatabasesAsync(string clusterIdentifier, string dbUser, string databaseName) { try { var request = new ListDatabasesRequest { ClusterIdentifier = clusterIdentifier, DbUser = dbUser, Database = databaseName }; var response = await _redshiftDataClient.ListDatabasesAsync(request); var databases = new List<string>(); foreach (var database in response.Databases) { Console.WriteLine($"The database name is : {database}"); databases.Add(database); } return databases; } catch (Amazon.RedshiftDataAPIService.Model.ValidationException ex) { Console.WriteLine($"Validation error: {ex.Message}"); throw; } catch (Exception ex) { Console.WriteLine($"Couldn't list databases. Here's why: {ex.Message}"); throw; } }-
有关 API 详细信息,请参阅《适用于 .NET 的 Amazon SDK API Reference》中的 ListDatabases。
-
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
查看 GitHub,了解更多信息。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /** * Lists all databases asynchronously for the specified cluster, database user, and database. * @param clusterId the identifier of the cluster to list databases for * @param dbUser the database user to use for the list databases request * @param database the database to list databases for * @return a {@link CompletableFuture} that completes when the database listing is complete, or throws a {@link RuntimeException} if there was an error */ public CompletableFuture<Void> listAllDatabasesAsync(String clusterId, String dbUser, String database) { ListDatabasesRequest databasesRequest = ListDatabasesRequest.builder() .clusterIdentifier(clusterId) .dbUser(dbUser) .database(database) .build(); // Asynchronous paginator for listing databases. ListDatabasesPublisher databasesPaginator = getAsyncDataClient().listDatabasesPaginator(databasesRequest); CompletableFuture<Void> future = databasesPaginator.subscribe(response -> { response.databases().forEach(db -> { logger.info("The database name is {} ", db); }); }); // Return the future for asynchronous handling. return future.exceptionally(exception -> { throw new RuntimeException("Failed to list databases: " + exception.getMessage(), exception); }); }-
有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 ListDatabases。
-
有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用 本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。
GetStatementResult
ModifyCluster