Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks SQL
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
-
A mandatory
STRINGliteral 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_FUNCTIONis raised. connectorOptionKeyA 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_queryfunction. If a key is not supportedPARAMETER_NOT_SUPPORTED_FOR_REMOTE_QUERY_FUNCTIONis raised.connectorOptionValueA 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
Related functions
- http_request - Similar because it also uses Unity Catalog connection credentials to send HTTP requests to certain API
- CREATE CONNECTION
- ALTER CONNECTION
- DROP CONNECTION