Running cockroachdb commands in file from CLI

hello -

i see here how to run commands from the command line using an external file BEFORE I have logged into cockroachdb, but what about if i was already logged in?

i should think that something like:

mark@:26257/bank> SET DATABASE = bank;
mark@:26257/bank> \. marksCockroachCommand.sql

in this format: (backslash-dot) filename.sql

would also work.

suggestions?

Hi @edwardsmarkf,

Does this work for you:

mark@:26257/bank> SET DATABASE = bank;
mark@:26257/bank> \| cat marksCockroachCommand.sql

– Becca

hi - sorry i missed that, somehow. yes, indeed it works.

since this is so commonly used, i am surprised we have to use an enternal “cat” command.

Hi @edwardsmarkf,

Great! Glad it worked. I agree that the UI could probably be a bit friendlier here. I created an issue to improve it: https://github.com/cockroachdb/cockroach/issues/25178. I’m not sure how the team will prioritize fixing this, but feel free to follow the issue if you’d like to stay informed.

– Becca

the more i think about, the more i realize you can do all sorts of wonderful stuff with this, such as something like

\| cat becca.sql | sed -e ‘s/oldTable/newTable/g;’ ;

Good point! The syntax may not be completely intuitive, but it’s certainly powerful :slight_smile: