Restrict iteration using the special key
Template create table $table$ ( … );alter table $table$ add primary key ($for columns(select primary_key)$ $column$ $unless _last$, $end$$end$);
Notes:
Back in the template, we again use a for directive to select each column in the columns list in turn, but we add a qualifying select phrase to the directive which states that we are only interested in the elements which contain a primary_key key. The name of each column so identified is generated, followed by a comma unless it is the last element.
Note that qualifying the elements with a select phrase in the expression $for columns (select primary_key)$…$end$ is not quite the same as saying $for columns$$if primary_key$…$end$$end$. In the latter case the last primary key element may not be the last column in the list, and will not have _last key set.