Execute cockroach sql with variable substitution

Is it possible to run a script through cockroach sql and perform variable substition on the statements, for example in psql you can run something like:

echo "CREATE DATABASE IF NOT EXISTS :dbname" | psql -v dbname=test

I don’t see any similar options for cockroach sql but wanted to check

This is not yet supported unfortunately. Feel free to create an issue on github to request the feature.

Tip: you can use the psql command with CockroachDB and let it perform variable substitution for you!

Thanks for the tip - i’ll give it a go.

Created ticket too: https://github.com/cockroachdb/cockroach/issues/33725

1 Like