News for hackers. Stuff that matters.
Re:Psql command line tutorial and cheat sheet by NAR8789 on Monday November 16, 2020 @01:03PM (#25114907)
To complement this, I recommend installing `pgcli`[https://www.pgcli.com/]. It's a near-drop-in-replacement for psql, and gives autocompletion, syntax highlighting, and semicolon forgiveness.

Even as someone already comfortable with psql, pgcli is extremely handy.

Re:Psql command line tutorial and cheat sheet by Cieplak on Monday November 16, 2020 @03:38PM (#25116702)
I went back and forth between psql and pgcli for several years, until I realized that pgcli tab-completes JOIN conditions.
Re:Psql command line tutorial and cheat sheet by jessedhillon on Tuesday November 17, 2020 @02:02AM (#25120960)
Postgres supports JOIN USING. If your keys are named the same in both tables, say `user_id` then you can simply say

  SELECT *
  FROM parent
  JOIN child USING (user_id)
I personally think naming your primary keys with their full name instead of calling all of them `id` or `key` is better practice also.
Re:Psql command line tutorial and cheat sheet by felixyz on Monday November 16, 2020 @04:49PM (#25117399)
And to complement that, I recommend Postgres Pager (https://github.com/okbob/pspg)
Re:Psql command line tutorial and cheat sheet by qwertox on Monday November 16, 2020 @04:47PM (#25117375)
A drop-down autocomplete in a console? First time I've seen such a thing. Thanks for pointing out this tool.
Re:Psql command line tutorial and cheat sheet by djeiasbsbo on Monday November 16, 2020 @06:56PM (#25118686)
That's part of prompt toolkit, a python library for building cli applications. Its creator actually reimplemented a number of applications in python with similar additions. Check out pyvim, pymux, ptpython, pypager and ptterm.
Re:Psql command line tutorial and cheat sheet by resheku on Monday November 16, 2020 @04:49PM (#25117402)
pgcli is nice

and it works great with pspg pager [https://github.com/okbob/pspg]

''\pager /usr/local/bin/pspg''

Re:Psql command line tutorial and cheat sheet by djeiasbsbo on Monday November 16, 2020 @06:59PM (#25118720)
I wish there was an oracle database equivalent. The oracle SQL REPLs are both terrible but the cx_oracle python client library is decent so maybe a pgcli fork would be possible.
Re:Psql command line tutorial and cheat sheet by masklinn on Tuesday November 17, 2020 @01:47AM (#25120890)
pspg supports MySQL and SQLite after sone configuration to their shell, might be possible for oracle as well?
Re:Psql command line tutorial and cheat sheet by EQYV on Monday November 16, 2020 @04:01PM (#25116946)
Thanks! Just switched to this for a project I'm working on.
Re:Psql command line tutorial and cheat sheet by solarized on Monday November 16, 2020 @08:36PM (#25119393)
one big cons of pgcli appear when we deal with long query. even it support multiline and vi mode. we still can't integrate a formatter for convenient sake.
Re:Psql command line tutorial and cheat sheet by russelwilson on Monday November 16, 2020 @01:57PM (#25115540)
I second this motion.