PG 14.11
This works perfectly:
CDSLBXW=# set sch public
CDSLBXW=# set tbl job_history
CDSLBXW=# set fld job_id
CDSLBXW=# CREATE INDEX CONCURRENTLY IF NOT EXISTS blarge ON :sch.:tbl (:fld) WITH (fillfactor=100);
CREATE INDEX
However, I do not want an index named “blarge”. The goal is to build a meaningful index name from the table and field names, but underscores cause it to fail:
CDSLBXW=# CREATE INDEX CONCURRENTLY IF NOT EXISTS tmpidx_:tbl_:fld ON :sch.:tbl (:fld) WITH (fillfactor=100);
ERROR: syntax error at or near ":"
LINE 1: CREATE INDEX CONCURRENTLY IF NOT EXISTS tmpidx_:tbl_job_id O...
^
In bash, you’d use curly braces to delimit the variable names, but those aren’t available in psql.
What to do?
0