remote_query table-valued function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 18.3 and above

Returns the tabular result of the query executed on the remote database engine.

remote_query fetches data from remote systems using credentials from a connection. The function accepts a set of connector options.

This function requires named parameter invocation.

Syntax

remote_query(connectionName [, connectorOptionKey => connectorOptionValue ] [...])

Arguments

  • connectionName

    A mandatory STRING literal that references Unity Catalog connection name. If the connection name does not exist Databricks raises CONNECTION_NOT_FOUND.

    The following connections are supported:

    • BigQuery
    • JDBC
    • MySQL
    • Oracle
    • PostgreSQL
    • Redshift
    • Snowflake
    • SQL Server
    • Teradata

    If the connection is not supported CONNECTION_TYPE_NOT_SUPPORTED_FOR_REMOTE_QUERY_FUNCTION is raised.

  • connectorOptionKey

    A connector option key which is a case-sensitive identifier. The required and optional connector options depend on the connection type. See Query external databases using the remote_query function. If a key is not supported PARAMETER_NOT_SUPPORTED_FOR_REMOTE_QUERY_FUNCTION is raised.

  • connectorOptionValue

    A constant expression representing the connector option value.

Returns

Returns a table. The output schema is dependent on the query or the tables being scanned on a remote system.

Common error conditions

Notes

This function cannot be used in streaming queries (UNSUPPORTED_STREAMING_TABLE_VALUED_FUNCTION).

Examples

-- Simple example with MySQL connection
> SELECT a, b FROM remote_query('mysql_connection', query => 'SELECT * FROM mysql_database.mysql_table WHERE sin(b) = 0.5');
  a        b
  angle_1  30

-- Connection name does not exist
> SELECT * FROM remote_query('non_existent_uc_connection', query => '');
  Error: CONNECTION_NOT_FOUND

-- Connection type is not supported
> SELECT * FROM remote_query('google_drive_connection', query => '');
  Error: CONNECTION_TYPE_NOT_SUPPORTED_FOR_REMOTE_QUERY_FUNCTION