View a markdown version of this page

애플리케이션 및 도구에 Amazon Redshift 드라이버 메타데이터 API 사용 - Amazon Redshift

Amazon Redshift는 패치 198부터 새 Python UDF 생성을 더 이상 지원하지 않습니다. 기존 Python UDF는 2026년 6월 30일까지 계속 작동합니다. 자세한 내용은 블로그 게시물을 참조하세요.

애플리케이션 및 도구에 Amazon Redshift 드라이버 메타데이터 API 사용

비즈니스 인텔리전스 도구 또는 쿼리 편집기와 같이 Amazon Redshift에 연결되는 애플리케이션 및 도구의 경우, Amazon Redshift JDBC 2.x, ODBC 2.x 또는 Python 드라이버에서 제공하는 드라이버 메타데이터 API를 사용하여 데이터베이스, 스키마, 테이블, 열 및 데이터 유형 등 데이터 웨어하우스 객체에 대한 메타데이터를 검색하는 것이 좋습니다. 대안으로 Amazon Redshift SHOW 명령을 사용할 수 있습니다.

드라이버 메타데이터 API를 사용하면 다음과 같은 이점이 있습니다.

  • 사양 준수. JDBC 및 ODBC 드라이버는 표준 메타데이터 인터페이스(JDBC의 DatabaseMetaData, ODBC의 SQLTablesSQLColumns)를 구현합니다. Python의 DB-API(PEP 249)는 메타데이터 API 사양을 정의하지 않으므로 Amazon Redshift Python 드라이버는 JDBC DatabaseMetaData 사양을 따르며, get_tables(), get_columns()get_schemas() 같은 동등한 메서드를 제공합니다. 이러한 API는 잘 정의된 사양을 따르므로, 통합 코드를 이식할 수 있습니다. Amazon Redshift는 내부 시스템 테이블을 발전시키므로, 애플리케이션을 변경할 필요가 없습니다.

  • 성능 최적화. 드라이버 메타데이터 API는 메타데이터를 효율적으로 반환하도록 최적화되어 있습니다. AWS는 드라이버 메타데이터 API 성능에 계속 투자하고 있습니다.

  • 향후 호환성. Amazon Redshift는 JDBC, ODBC 및 Python 커넥터 사양을 준수합니다. 이러한 표준 API를 기반으로 코딩하면 기본 시스템 카탈로그 구조가 변경되더라도 애플리케이션이 보호됩니다.

예: JDBC DatabaseMetaData.getTables()를 사용하여 테이블 메타데이터 검색

DatabaseMetaData dbmd = connection.getMetaData(); // getTables(catalog, schemaPattern, tableNamePattern, types) // catalog: "test" — filters to the database named "test" // schemaPattern: "test_pattern" — filters schemas matching this pattern (supports SQL wildcards % and _) // tableNamePattern: null — no filter, returns all table names // types: {"TABLE", "EXTERNAL TABLE"} — only return regular tables and external tables ResultSet rs = dbmd.getTables("test", "test_pattern", null, new String[] {"TABLE", "EXTERNAL TABLE"});

예: Python cursor.get_columns()를 사용하여 열 메타데이터 검색

cursor: redshift_connector.Cursor = conn.cursor() # get_columns(catalog, schema_pattern, table_name_pattern, column_name_pattern) # catalog: 'test' — filters to the database named "test" # schema_pattern: 'test_pattern' — filters schemas matching this pattern (supports SQL wildcards % and _) # table_name_pattern: 'testabc' — filters to the table named "testabc" # column_name_pattern: '%' — wildcard, returns all columns in the matching table result: tuple = cursor.get_columns('test', 'test_pattern', 'testabc', '%')

예: ODBC SQLPrimaryKeys()를 사용하여 프라이머리 키 메타데이터 검색

// SQLPrimaryKeys(hstmt, catalog, catalog_len, schema, schema_len, table, table_len) // catalog: "test" — filters to the database named "test" // schema: "test_schema" — filters to the schema named "test_schema" // table: "test_table" — retrieves primary key columns for this table // Note: Unlike getTables/getColumns, SQLPrimaryKeys does NOT support wildcard patterns. retcode = SQLPrimaryKeys(hstmt, (SQLCHAR *)"test", SQL_NTS, (SQLCHAR *)"test_schema", SQL_NTS, (SQLCHAR *)"test_table", SQL_NTS); while (SQL_SUCCEEDED(retcode = SQLFetch(hstmt))) { for (i = 1; i <= columns; i++) { retcode = SQLGetData(hstmt, i, SQL_C_CHAR, buf, sizeof(buf), &indicator); } }

예: ODBC SQLTables()를 사용하여 데이터베이스 및 스키마 나열

ODBC API는 카탈로그 또는 스키마를 나열하기 위한 별도의 함수를 제공하지 않습니다. 대신 SQLTables()의 특수 호출 규칙을 사용하여 이 정보를 검색합니다.

모든 데이터베이스 나열(카탈로그)

CatalogNameSQL_ALL_CATALOGS로 설정된 SQLTables()를 직접 호출합니다. SchemaNameTableName을 빈 문자열로 설정합니다. 결과 세트는 TABLE_CAT 열에서만 유효한 값을 반환합니다. 다른 모든 열에는 NULL이 포함됩니다.

// List all catalogs (databases) available on the data source. retcode = SQLTables(hstmt, (SQLCHAR *)SQL_ALL_CATALOGS, SQL_NTS, // CatalogName = "%" (SQL_ALL_CATALOGS) (SQLCHAR *)"", 0, // SchemaName = "" (empty string) (SQLCHAR *)"", 0, // TableName = "" (empty string) NULL, 0); // TableType = NULL (not filtered)

모든 스키마를 나열하는 방법

SchemaNameSQL_ALL_SCHEMAS로 설정된 SQLTables()를 직접 호출합니다. CatalogNameTableName을 빈 문자열로 설정합니다.

// List all schemas available on the data source. retcode = SQLTables(hstmt, (SQLCHAR *)"", 0, // CatalogName = "" (empty string) (SQLCHAR *)SQL_ALL_SCHEMAS, SQL_NTS, // SchemaName = "%" (SQL_ALL_SCHEMAS) (SQLCHAR *)"", 0, // TableName = "" (empty string) NULL, 0); // TableType = NULL (not filtered)
참고

ODBC 사양은 스키마 열거에 대해 TABLE_SCHEM만 유효한 것으로 정의합니다. Amazon Redshift는 데이터베이스 간 메타데이터 검색을 지원하며 각 스키마의 범위가 특정 데이터베이스로 지정되므로 TABLE_CAT도 채워집니다.