Skip to main content
By default, Omni will assign fields labeled like id or table_id as primary keys when generating a model. For example, the users_id on a users table. Primary keys can also be automatically set using dbt constraints.
Primary keys are used to prevent fan outs when calculating metrics with more than one table, in conjunction with the join relationship. They can be defined using this parameter or in the workbook by hovering over a field and clicking > Modeling > Primary key. For situations where a database column is not available for primary_key declaration - for example, compound keys like CONCAT(id, '-', user_id) - Omni recommends creating a new field and setting that field as the primary key. Alternatively, for compound primary keys, you can set custom_compound_primary_key_sql at the view level to define an array of fields that make up the view’s primary key.

Syntax

<dimension_name>:
  primary_key: true

Properties

dimension_name
object
The name of the dimension. Dimension names must:
  • Be unique within the view
  • Start with a letter
  • Contain only alphanumeric characters and underscores

Examples

Simple primary key
id:
  primary_key: true
Compound primary key
compound_primary_key_field:
  sql: concat(${field_1},'-',${field_2})
  primary_key: true
  hidden: true