pgFetch#
- pgFetch(connect, second_input, varargin)#
Fetch data and metadata from PostgreSQL using a connection or prepared statement.
- Parameters:
connect (
database.relational.connection) – Open database connectionsecond_input (
char | string | database.preparedstatement.SQLPreparedStatement) – SQL query string or prepared statementvarargin (
any) – Optional arguments
- Returns:
Fetched data
- Return type:
table | cell | struct | numeric
- Returns:
Metadata describing returned data
- Return type:
struct
Options (name-value):
MaxRows: Maximum number of rows to return (default 0 = unlimited)VariableNamingRule: “preserve” or “modify” (table output only)DataReturnFormat: one of “table” (default) | “cellarray” | “structure” | “numeric”RowFilter:matlab.io.RowFilterto push down to SQLrowlimit_or_opts: Either a row-limit scalar or a SQLImportOptions object
Notes:
When a prepared statement is provided, certain options are mutually exclusive (e.g.,
RowFilterand import options). See MATLAB Database Toolbox behavior.DATA = FETCH(CONN,SQLSTRING) imports database data into MATLAB given the connection handle, CONN, and the SQL string, SQLSTRING.
DATA = FETCH(CONN,SQLSTRING,OPTS) imports database data into MATLAB using the specified import options opts.
DATA = FETCH(CONN,SQLSTRING,NAME,VALUE) imports database data into MATLAB with additional options specified by one or more name-value arguments. For e.g., you can specify DataReturnFormat or MaxRows name-value argument.
DATA = FETCH(CONN,PSTMT) imports database data into MATLAB given the connection handle, CONN, and the SQLPreparedStatement, PSTMT.
DATA = FETCH(CONN,PSTMT,NAME,VALUE) imports database data into MATLAB with additional options specified by one or more name-value arguments. For e.g., you can specify DataReturnFormat or MaxRows name-value argument.
[data,metadata] = FETCH(_____) imports database data into MATLAB and metadata information for imported data
conn - database.jdbc.connection object. source - SQL query or SQLPreparedStatement.
opts - import options for sql query defined using databaseImportOptions DataReturnFormat - type of data returned. table (default) | cellarray | structure | numeric MaxRows - Maximum number of rows to return VariableNamingRule - determine use of arbitrary variable names
For example,
data = fetch(conn,’select * from tablename’) will return the data as a table by default.
[data,metadata] = fetch(conn,’select * from tablename’,’DataReturnFormat’,’cellarray’) will return the data as a cell array.
data = fetch(conn,’select * from tablename’,opts) will return the data using import options specified using opts.
See also
connection/sqlread,databaseImportOptions