@@ -264,17 +264,18 @@ cubes:
264264
265265### ` primary_key`
266266
267- Specify which dimension is a primary key for a cube. The default value is
267+ Specify if a dimension is a primary key for a cube. The default value is
268268` false` .
269269
270270A primary key is used to make [joins][ref-schema-ref-joins] work properly.
271271
272- <WarningBox >
272+ <InfoBox >
273273
274- Setting `primary_key` to `true` will change the default value of `public`
275- parameter to `false`. If you still want `public` to be `true`, set it manually.
274+ Setting `primary_key` to `true` will change the default value of the [`public`
275+ parameter](#public) to `false`. If you still want `public` to be `true`, set it
276+ explicitly.
276277
277- </WarningBox >
278+ </InfoBox >
278279
279280<CodeTabs>
280281
@@ -306,6 +307,85 @@ cubes:
306307
307308</CodeTabs>
308309
310+ It is possible to have more than one primary key dimension in a cube if you'd
311+ like them all to be parts of a composite key:
312+
313+ <CodeTabs>
314+
315+ ` ` ` javascript
316+ cube(`products`, {
317+ sql : `
318+ SELECT 1 AS column_a, 1 AS column_b UNION ALL
319+ SELECT 2 AS column_a, 1 AS column_b UNION ALL
320+ SELECT 1 AS column_a, 2 AS column_b UNION ALL
321+ SELECT 2 AS column_a, 2 AS column_b
322+ ` ,
323+
324+ dimensions : {
325+ composite_key_a : {
326+ sql : ` column_a` ,
327+ type : ` number` ,
328+ primary_key : true
329+ },
330+
331+ composite_key_b : {
332+ sql : ` column_b` ,
333+ type : ` number` ,
334+ primary_key : true
335+ }
336+ },
337+
338+ measures : {
339+ count : {
340+ type : ` count`
341+ }
342+ }
343+ })
344+ ```
345+
346+ ``` yaml
347+ cubes :
348+ - name : products
349+ sql : >
350+ SELECT 1 AS column_a, 1 AS column_b UNION ALL
351+ SELECT 2 AS column_a, 1 AS column_b UNION ALL
352+ SELECT 1 AS column_a, 2 AS column_b UNION ALL
353+ SELECT 2 AS column_a, 2 AS column_b
354+
355+ dimensions :
356+ - name : composite_key_a
357+ sql : column_a
358+ type : number
359+ primary_key : true
360+
361+ - name : composite_key_b
362+ sql : column_b
363+ type : number
364+ primary_key : true
365+
366+ measures :
367+ - name : count
368+ type : count
369+ ` ` `
370+
371+ </CodeTabs>
372+
373+ Querying the ` count` measure of the cube shown above will generate the following
374+ SQL to the upstream data source :
375+
376+ ` ` ` sql
377+ SELECT
378+ count(
379+ CAST("product".column_a as TEXT) || CAST("product".column_b as TEXT)
380+ ) "product__count"
381+ FROM (
382+ SELECT 1 AS column_a, 1 AS column_b UNION ALL
383+ SELECT 2 AS column_a, 1 AS column_b UNION ALL
384+ SELECT 1 AS column_a, 2 AS column_b UNION ALL
385+ SELECT 2 AS column_a, 2 AS column_b
386+ ) AS "product"
387+ ` ` `
388+
309389# ## `propagate_filters_to_sub_query`
310390
311391When this statement is set to `true`, the filters applied to the query will be
0 commit comments