Contenu principal

execute

Execute SQL statement using DuckDB native interface database connection

Since R2026a

    Description

    execute(conn,sqlquery) executes an SQL query that contains a non-SELECT SQL statement by using a DuckDB native interface database connection.

    example

    Examples

    collapse all

    Create a transient, in-memory DuckDB™ database connection by using the duckdb function.

    conn = duckdb();

    Load the patients information into the MATLAB® workspace.

    patients = readtable("patients.xls");

    Create a database table to store the patients information by using the sqlwrite function.

    tablename = "patients";
    sqlwrite(conn,tablename,patients)

    Import the data from the patients database table by using the sqlread function.

    sqlread(conn,tablename);

    Delete the database table by using the execute function with the following query.

    sqlquery = strcat("DROP TABLE ",tablename);
    execute(conn,sqlquery)

    Use the sqlfind function to verify that the table no longer exists.

    data = sqlfind(conn,tablename)
    data =
    
      0×5 empty table
    
        Catalog    Schema    Table    Columns    Type
        _______    ______    _____    _______    ____
    

    Close the connection.

    close(conn);

    Input Arguments

    collapse all

    DuckDB native interface database connection, specified as a connection object.

    SQL statement, specified as a string scalar or character vector. The SQL statement can be any valid non-SELECT SQL statement.

    The SQL statement can be a stored procedure that does not return any result sets. For stored procedures that return one or more result sets, use the fetch function.

    For information about the SQL query language, see the SQL Tutorial.

    Example: "DROP TABLE patients"

    Version History

    Introduced in R2026a

    See Also

    | |