Skip to content
All writing ‹ Part 06 of 09 · Reaching a Remote DB From Your Laptop
Engineering · 2 min read

One-Shot Query vs Interactive REPL: DB CLIs Fork on One Flag

After connecting, DB CLIs fork on one thing: pass a query flag for a one-shot run, omit it to drop into a REPL. Plus the psql/mysql/mongosh flags and clean-output options.

After connecting (same five coordinates), the only fork is whether you pass a query flag:

after connecting query flag one-shot: run, print, back to shell no flag REPL: type statement by statement the only fork after connecting is whether you pass a query flag
Pass a query flag and it runs once. Omit it and you drop into a REPL.
One-shot (stay in shell)Interactive (REPL)
psql-c "…" / -f filepsql <uri> → dbname=#, quit \q
mysql-e "…" / < filemysql <flags> → mysql>, quit exit
mongosh--eval "…" / --filemongosh <uri> → >, quit Ctrl-D

The language inside the REPL differs: psql / mysql are SQL (mysql needs a trailing ;, psql’s \ meta-commands take no ;). Mongosh is a JavaScript REPL wired to db. For scripting, add clean-output flags: psql -tA, mysql -BN, mongosh --quiet.

From this session: psql … -c "\dt" ran a backslash meta-command one-shot (no ;) and returned to the shell. \dt only lists the search-path schema (public), while \dt *.* lists all schemas.

The only fork after connecting is the query flag: with one it is one-shot, without one it is a REPL.


References

Related: back to the remote DB overview. This runs on the five coordinates, and the MySQL side is four ways to feed inline SQL.

↑↓ navigate ↵ open esc close