matlab-use-database

Read, write, update, and manage relational databases from MATLAB using Database Toolbox.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-use-database
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-use-database
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/reporting-and-database-access/matlab-use-database
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-use-database

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Working with relational databases from MATLAB involves many subtle API rules—positional arguments, pushdown filtering, transaction handling, and ORM conventions—that are easy to get wrong, leading to slow queries, broken transactions, or accidental data loss. This Skill gives an AI agent the correct patterns for the full database lifecycle so generated MATLAB code follows Database Toolbox best practices.

Core Features & Use Cases

  • Reading with pushdown filtering: Import tables with sqlread or run SQL queries with fetch, using RowFilter and databaseImportOptions so filtering happens on the database server instead of in MATLAB.
  • Writing, updating, and transactions: Insert with sqlwrite, update rows with sqlupdate, and wrap multi-step operations in transactions using AutoCommit, commit, and rollback with proper error handling.
  • ORM and advanced workflows: Map MATLAB classes to tables with Mappable and ormwrite/ormread/ormupdate, run stored procedures and prepared statements, and scale to multithreaded I/O with parfeval (R2026a+).
  • Use Case: Connect to a PostgreSQL production database, read only active orders placed after a date using server-side filtering, update prices in place, and commit both changes atomically—all with securely stored credentials via setSecret/getSecret.

Quick Start

Ask the agent to connect to your database and read rows from a table filtered by a column condition using MATLAB Database Toolbox.

Frequently Asked Questions about matlab-use-database

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I read filtered data from a database table in MATLAB?

Use sqlread with a RowFilter so the filter runs on the database server: create rf = rowfilter("Price"), then call sqlread(conn, "products", RowFilter=rf.Price > 100). Never import all rows and filter in MATLAB afterward.

How do I update rows in a database table from MATLAB?

Use sqlupdate with a table of new values and a RowFilter as the required positional fourth argument: sqlupdate(conn, "inventory", data, rf.ProductID == 42). For multiple rows with different values, pass a cell array of filters.

Does MATLAB Database Toolbox support ORM for mapping classes to tables?

Yes, since R2023b you can inherit from database.orm.mixin.Mappable, mark a PrimaryKey property, and use ormwrite, ormread, and ormupdate. The constructor must handle nargin == 0, and ORM works with JDBC, ODBC, PostgreSQL, MySQL, SQLite, and DuckDB connections.

How do I use transactions with commit and rollback in MATLAB?

Set conn.AutoCommit = 'off', perform operations inside a try block, call commit(conn) on success, and rollback(conn) in the catch block, then restore AutoCommit to 'on'. Never use raw SQL BEGIN or COMMIT through execute.

Can I run database operations in parallel from MATLAB?

Yes, with R2026a and Parallel Computing Toolbox you can use parfeval on a parpool("Threads") pool, but each thread must create its own connection since connections are not thread-safe. Wrap large data in parallel.pool.Constant to avoid copies.

When should I not use this database skill in MATLAB?

Route DuckDB workflows to the dedicated DuckDB skill and Databricks connection setup to the Databricks skill. MongoDB, Cassandra, and Neo4j are not relational, so Database Toolbox ORM and CRUD patterns do not apply to them.