Overview
External SQL execution is automatically enabled when the “folio” or “reshare” module is specified in your data source configuration. The feature allows you to:- Run SQL files on a scheduled basis
- Create and maintain derived tables
- Track execution status in system tables
Details such as the location of SQL files and scheduling are currently hardcoded but will be configurable in future releases.
Enabling external SQL
To enable external SQL, configure the appropriate Git reference using thealter system command:
- FOLIO
'') disables external SQL execution for that repository.
SQL file format
When writing external SQL files, follow these formatting rules:Statement separation
Separate each SQL statement with an empty line:Schema names
Directives
Directives are special comment lines that control Metadb’s behavior. Each directive must:- Begin with
--metadb: - Appear on its own line
- Be followed by an empty line before the SQL statements
—metadb:table
The--metadb:table directive declares that the SQL file updates a specific table. This enables Metadb to track the update status in the metadb.table_update system table.
Syntax:
The name of the table being updated. Do not include a schema name.
Complete example
Here’s a complete example showing proper formatting and directive usage:File structure breakdown
File structure breakdown
- Directive line:
--metadb:table user_groupdeclares the target table - Empty line: Required separator
- Drop statement: Removes existing table if present
- Empty line: Statement separator
- Create statement: Defines the new table and its data
- Empty line: Statement separator
- Index creation: Additional optimizations
Monitoring execution
Track the status of external SQL execution using themetadb.table_update system table:
- When each table was last updated
- How long the update took to complete
- Which schema and table were affected
Best practices
Use directives
Always include
--metadb:table at the start of each file for proper trackingSeparate statements
Use empty lines between SQL statements for correct parsing
Avoid schemas
Don’t specify schema names in table creation statements
Monitor execution
Check
metadb.table_update to verify successful executionTroubleshooting
External SQL not running
External SQL not running
Verify that the configuration parameter is set:Ensure the value is not an empty string (
'') and points to a valid Git reference.Table not appearing in metadb.table_update
Table not appearing in metadb.table_update
Confirm that your SQL file includes the
--metadb:table directive at the beginning, followed by an empty line.SQL statements not executing
SQL statements not executing
Check that:
- Each statement is separated by an empty line
- Schema names are not included in table creation
- The directive line is followed by an empty line
Related documentation
Configuration parameters
Learn about external_sql_folio and external_sql_reshare parameters
System tables
Query execution status in metadb.table_update
