What do I do when I don't have a natural primary key?

  • 2 January 2018
  • 2 replies

I have a list of IDs and values associated with each of those IDs. I’m going to join this table to another table on the list of IDs in a one_to_many relationship. There ID column repeats the IDs over and over again.

Does it matter for looker whether I have a primary key? I can add an arbitrary number associated with each row.


2 replies

Hey Sebastian!

You’ll typically want a primary key for any of your Views (tables) since having one is critical to performing symmetric aggregates. If you had an explore based on a Table A and decided to join a Table B (that does not have a primary key) onto Table A, Looker would not allow you to use any of Table B’s measures in that explore.

In regards to your question about an arbitrary number being your primary key, that is totally fine! You could also instead create a compound primary key that is a combination of two or more other dimensions in your View. Here’s an article on how to create a compound primary key:

Hope this was helpful! Let us know if you have any other questions.



I have tried to create a compound primary key as above and also for the PDT’s where the combination is not unique, I have generated a new column as - row_number() over (order by DATE_TRUNC(‘month’,date) desc) as row as a dimension and used it in the compound primary key .