home User Guide Getting Started Help Center Documentation Community Training Certification
menu
close
settings
Looker keyboard_arrow_down
language keyboard_arrow_down
English
Français
Deutsch
日本語
search
print
Looker documentation will be moving to cloud.google.com in mid-2022!
All the information you rely on will be migrated and all docs.looker.com URLs will be redirected to the appropriate page.
primary_key

Usage

view: view_name {
  dimension: field_name {
    primary_key: yes
  }
}
Hierarchy
primary_key
Possible Field Types
Dimension

Accepts
A Boolean (yes or no)

Definition

The primary_key parameter specifies that a dimension is the primary key for its view. The default value is false. For example:

dimension: id { primary_key: yes sql: ${TABLE}.id ;; }

The primary_key parameter has the following qualities and requirements:

Creating a compound primary key

If you have a primary key that is comprised of multiple columns, you can create a dimension that concatenates those columns, then declare that as your primary key. For example:

dimension: primary_key { primary_key: yes sql: CONCAT(${TABLE}.promotion_id, ${TABLE}.sku) ;; }

CONCAT works in some databases, such as MySQL, but other databases might have a different equivalent. Redshift, for example, uses || as its concatenation operator.

Top