CData ODBC Driver for Amazon Marketplace 2019 - Online Help
Questions / Feedback?

Discovering Schemas

CData ODBC Driver for Amazon Marketplace 2019 - Build 19.0.7354

The following sections show how to obtain schema information.

List Tables and Views

Although the sql package does not provide a native interface to query tables and views, you can use the sys_tables and sys_views provided by the driver.

tables, _ := db.Query("SELECT CatalogName, SchemaName, TableName FROM sys_tables")
defer tables.Close()

for tables.Next() {
        var (
                catalog string
                schema string
                table string
        )

        rows.Scan(&catalog, &schema, &table)
        fmt.Printf("Catalog: %s, Schema: %s, Table: %s", catalog, schema, table)
}

views, _ := db.Query("SELECT CatalogName, SchemaName, TableName FROM sys_views")
defer views.Close()

for views.Next() {
        var (
                catalog string
                schema string
                view string
        )

        rows.Scan(&catalog, &schema, &view)
        fmt.Printf("Catalog: %s, Schema: %s, Table: %s", catalog, schema, table)
}

List Table Columns

You can use the sys_tablecolumns and sys_viewcolumns to get information about columns.

columns, _ := db.Query("SELECT ColumnName, DataType, Length, NumericPrecision, IsNullable FROM sys_tablecolumns WHERE TableName = 'SampleTable_1'")
defer columns.Close()

for columns.Next() {
        var (
                column string
                datatype int
                length int
                precision int
                nullable bool
        )

        rows.Scan(&column, &datatype, &length, &precision, &nullable)
        fmt.Printf("Name: %s, Type: %d, Length: %d, Precision: %d, Nullable: %t\n", column, datatype, length, precision, nullable)
}

 
 
Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 19.0.7354.0