Main Content

sqlqueryinfo

Retrieve SQL query metadata

Since R2025a

    Description

    queryInfo = sqlqueryinfo(dataSourceInfo,sqlquery) returns SQL query metadata by using information about the data source contained in dataSourceInfo, which can either be a connection object or a data source name.

    example

    Examples

    collapse all

    This example assumes you already stored your user credentials with your data source in the Database Explorer app.

    Use sqltableinfo by specifying the name of the data source and the SQL query that you want to retrieve information about.

    dataSourceInfo = "PostgreSQL Native";
    sqlquery = "SELECT  *  from inventoryTable I inner join productTable P ON I.productNumber = P.productNumber";
    queryInfo = sqlqueryinfo(dataSourceInfo,sqlquery)
    queryInfo = 
    
      struct with fields:
    
             SQLQuery: "SELECT  *  from inventoryTable I inner join productTable P ON I.productNumber = P.productNumber"
              NumCols: 9
              NumRows: 13
        VariableNames: ["productnumber"    "quantity"    "price"    "inventorydate"    "productnumber"    "stocknumber"    "suppliernumber"    "unitcost"    "productdescription"]
        VariableTypes: ["double"    "double"    "double"    "datetime"    "double"    "double"    "double"    "double"    "string"]
    

    Input Arguments

    collapse all

    Data source information, specified as a connection object, string scalar, or character vector. Specifying data source information depends on the connection method:

    • Specify dataSourceInfo as connection object by using the database function and retrieving your credentials using getSecret. This method assumes you have not stored your user credentials with the data source when using the Database Explorer app. Supported connection objects include:

      • database.odbc.connection

      • database.jdbc.connection

      • database.mysql.connection

      • database.postgre.connection

      • sqlite

    • Specify dataSourceInfo as a character vector or string scalar if you have already created your data source and saved your user credentials with the Database Explorer app. Supported data sources include:

      • ODBC

      • JDBC

      • MySQL

      • PostgreSQL

    SQL query, specified as a string scalar or character vector.

    Output Arguments

    collapse all

    Query information, returned as a structure containing the following fields:

    • SQLQuery

    • NumCols

    • NumRows

    • VariableNames

    • VariableTypes

    Version History

    Introduced in R2025a