OpenBI Docs Buy

Odbc.Query

The rows of a SQL statement that an ODBC data source runs, in its own SQL.

Group: Databases and lakes. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Odbc.Query(connectionString as any, query as text, optional options as nullable record) as table
ParameterTypeDescription
connectionStringanyA data source name, a connection string, or a record of its attributes, as Odbc.DataSource takes it.
querytextThe SQL, as the database's own dialect writes it.
optionsnullable record
optional
Accepted as Power Query writes it; none is read.

Returns

table. The statement's result, its columns as the statement names them.

Remarks

  • The database runs the statement; the steps after it run in DuckDB on the rows it returns.
  • No user or password in the connection string: the sign-in holds them. Credentials are never part of the M: the studio asks for a sign-in the first time this computer reads the source and keeps it on this computer only, for you.

Examples

Sales by shop, grouped by the database

Odbc.Query("dsn=Warehouse", "SELECT Shop, SUM(Amount) AS Sales FROM Orders GROUP BY Shop")

Result: not shown here: it needs an ODBC data source on this computer.

Odbc.DataSource, Sql.Database, DuckDB.Query.

Last updated · OpenBI Studio 0.3.79