viernes, 11 de febrero de 2022

Read-only psql

This is how I wrote a short snippet to open read-only postgres connection using psql.  Notice the amount of non-trivial stuff in those lines (technically, only one line of code).

 

I tried to show many concepts in those short snippets I post around here. 

  • For example, notice how some lines need backslashes to continue the line, but some others not. 
  • Also notice how to use <() to create a temporary file, so we don't have to have a duplicate file (probably outdated). 
  • The command being a "cat originalfile && echo "customline") makes it a fresh file each time, that inherits from your originalfile. 
  • Finally, good old "$@" to proxy the parameters to another command.

in zsh, you can add "compdef ropsql=psql" so it also proxies the autocompletion

1 comentario:

Tel U dijo...

Thanks for sharing valuable Information, I really very impressive on your blog. I hope you continue,