sql_createenables custom Data Definition Language (DDL) commands for buildingpersistent derived tables (PDTs).sql_createwill issue a statement as is, without Looker's usual error checking. The only requirement is that the statement results in the creation and execution of a PDT. This lets you, for example, create PDTs that support the GoogleBigQuery MLmachine learning models.
For PDTs defined usingsql_create, you cannot use any of the following parameters:
Create a PDT for BigQuery ML queries that predict likelihood of future purchases:
view: future_purchase_model {
derived_table: {
datagroup_trigger: bqml_datagroup
sql_create:
CREATE OR REPLACE MODEL ${SQL_TABLE_NAME}
OPTIONS(model_type='logistic_reg'
, labels=['will_purchase_in_future']
, min_rel_progress = 0.005
, max_iterations = 40
) AS
SELECT
* EXCEPT(fullVisitorId, visitId)
FROM ${training_input.SQL_TABLE_NAME};;
}
}
Things to consider
${SQL_TABLE_NAME}substitution operator
You can use the${SQL_TABLE_NAME}substitution operator to substitute in the computed name of the PDT being created. This ensures the SQL statement will correctly include the PDT name given in the LookMLviewparameter.
sql_createmust create a table with the name indicated by the${SQL_TABLE_NAME}substitution operator, or it will be rebuilt from scratch on every trigger check interval specified in a connection'sPDT and Datagroup Maintenance Schedulesetting (the default is five minutes). This can cause unexpected query traffic on your database or data warehouse.
Usecreate_processto create a PDT in multiple steps
If your database dialect requires custom DDL commands, and you want to issue multiple commands to create a PDT, you can usecreate_processto issue multiple custom DDL commands in a specific order.
Tables defined withsql_createcan't be used for incremental PDTs
To be used as anincremental PDT, a SQL-based PDT must have a query defined using thesqlparameter. SQL-based PDTs that are defined with thesql_createparameter or thecreate_processparameter cannot be incrementally built.
This is because Looker uses anINSERT or a MERGE command to create the incrementsfor an incremental PDT. The derived table cannot be defined using custom Data Definition Language (DDL) statements, since Looker wouldn't be able to determine which DDL statements would be required to create an accurate increment.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-22 UTC."],[],[],null,["# sql_create\n\n\u003cbr /\u003e\n\nUsage\n-----\n\n```\nderived_table: customer_order_facts {\n sql_create: {\n SQL statement ;;\n }\n}\n```\n\nDefinition\n----------\n\n`sql_create` enables custom Data Definition Language (DDL) commands for building [persistent derived tables (PDTs)](/looker/docs/derived-tables#persistent_derived_tables_(pdts)). `sql_create` will issue a statement as is, without Looker's usual error checking. The only requirement is that the statement results in the creation and execution of a PDT. This lets you, for example, create PDTs that support the Google [BigQuery ML](https://cloud.google.com/bigquery/docs/bigqueryml) machine learning models.\n\u003e For PDTs defined using `sql_create`, you cannot use any of the following parameters:\n\u003e - [`indexes`](/looker/docs/reference/param-view-indexes)\n\u003e - [`cluster_keys`](/looker/docs/reference/param-view-cluster-keys)\n\u003e - [`distribution`](/looker/docs/reference/param-view-distribution)\n\u003e - [`distribution_style`](/looker/docs/reference/param-view-distribution-style)\n\u003e - [`partition_keys`](/looker/docs/reference/param-view-partition-keys)\n\u003e - [`sortkeys`](/looker/docs/reference/param-view-sortkeys)\n\u003e\nExamples\n--------\n\nCreate a PDT for BigQuery ML queries that predict likelihood of future purchases: \n\n view: future_purchase_model {\n derived_table: {\n datagroup_trigger: bqml_datagroup\n sql_create:\n CREATE OR REPLACE MODEL ${SQL_TABLE_NAME}\n OPTIONS(model_type='logistic_reg'\n , labels=['will_purchase_in_future']\n , min_rel_progress = 0.005\n , max_iterations = 40\n ) AS\n SELECT\n * EXCEPT(fullVisitorId, visitId)\n FROM ${training_input.SQL_TABLE_NAME};;\n }\n }\n\nThings to consider\n------------------\n\n### `${SQL_TABLE_NAME}` substitution operator\n\nYou can use the `${SQL_TABLE_NAME}` substitution operator to substitute in the computed name of the PDT being created. This ensures the SQL statement will correctly include the PDT name given in the LookML `view` parameter.\n\u003e `sql_create` must create a table with the name indicated by the `${SQL_TABLE_NAME}` substitution operator, or it will be rebuilt from scratch on every trigger check interval specified in a connection's [**PDT and Datagroup Maintenance Schedule**](/looker/docs/connecting-to-your-db#pdt_and_datagroup_maintenance_schedule) setting (the default is five minutes). This can cause unexpected query traffic on your database or data warehouse.\n\n### Use `create_process` to create a PDT in multiple steps\n\nIf your database dialect requires custom DDL commands, and you want to issue multiple commands to create a PDT, you can use [`create_process`](/looker/docs/reference/param-view-create-process) to issue multiple custom DDL commands in a specific order.\n\n### Tables defined with `sql_create` can't be used for incremental PDTs\n\nTo be used as an [incremental PDT](/looker/docs/incremental-pdts), a SQL-based PDT must have a query defined using the [`sql`](/looker/docs/reference/param-view-sql-for-derived-table) parameter. SQL-based PDTs that are defined with the `sql_create` parameter or the [`create_process`](/looker/docs/reference/param-view-create-process) parameter cannot be incrementally built.\n\nThis is because Looker uses an [INSERT or a MERGE command to create the increments](/looker/docs/incremental-pdts#example_1) for an incremental PDT. The derived table cannot be defined using custom Data Definition Language (DDL) statements, since Looker wouldn't be able to determine which DDL statements would be required to create an accurate increment."]]