The content of this article can be found in Looker’s technical documentation here.
This won’t work because CONCAT only takes 2 arguments. Or maybe I am doing something wrong.
The following worked for me:
- dimension: compound_primary_key
primary_key: true
hidden: true
sql: ${TABLE}.primary_key_1 || '-' || ${TABLE}.primary_key_2
Note: I’m using looker with AWS Redshift
Thanks for the note @stas1 - depending on your SQL dialect, you may need to use a concatenation operator other than CONCAT
. Looks like ||
does the trick for Redshift!
I haven’t tested yet to see how (or in what circumstances) it might improve performance, but depending on your dialect you can wrap the concatenation in a hashing function (like MD5()) and get a virtually-guaranteed-to-be-unique-in-most-applications 32-character id. I had to make a compound key using something like 8 different columns and I think persisting that ID was more efficient.