pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Run commands on startup

Open lee-kagiso opened this issue 10 years ago • 11 comments

I would like to run some commands on start up, like \x.

Is this possible?

lee-kagiso avatar May 28 '15 17:05 lee-kagiso

Right now there is no way to have a startup command.

Is \x the only thing you have in mind or do you have other ideas for this request?

The reason I ask is because I can made the expanded output to be a config option in ~/.pgclirc and you'll be able to achieve this feature. If you have more things in mind, I'll have to think of a different solution.

amjith avatar May 29 '15 06:05 amjith

I would also like to be able to change the value for nulls:

`\pset null '(null)'``.

In my current psqlrc I also echo out a cheatsheet of \ commands, but I can live without those...

https://github.com/leebrooks0/dotfiles/blob/master/psqlrc

lee-kagiso avatar May 29 '15 06:05 lee-kagiso

The null thing is not going to work. \pset is not supported by pgcli. Right now all null values are displayed as <null> by default.

The idea is that pgcli should ship with sane defaults that requires no configuration. But there does exist a config file which tweaks certain settings such as colorscheme and keybindings.

I can sympathize with the cheat sheet commands. I'll see what I can do.

amjith avatar May 29 '15 06:05 amjith

is perfect, anything other than blank is good.

lee-kagiso avatar May 29 '15 06:05 lee-kagiso

Also I didn't know about \x auto that seems like an awesome feature of psql that I might steal. :)

amjith avatar May 29 '15 06:05 amjith

One other thing worth mentioning, can you also add to the config file the ability to use multiline by default?

lee-kagiso avatar May 29 '15 07:05 lee-kagiso

Aha! This is already part of the config file. Open up ~/.pgclirc and you'll see an option to enable or disable multi-line mode.

amjith avatar May 29 '15 13:05 amjith

Is it possible to use the .pgclirc config file to set my default search path, like I can in .psqlrc? What would be the syntax?

normkatz avatar Jul 24 '15 16:07 normkatz

I would join to the question how to set up defaul search_path. Is it possible now?

spinus avatar Mar 27 '17 23:03 spinus

I too would like the ability to execute arbitrary commands on startup. My use case is a little different; I want to be able to CREATE TEMP VIEW on startup for some tables that I frequently join together. I don't think "named queries" are what I'm looking for because AFAICT you can't use named queries as part of another query, e.g. I wouldn't be able to join a named query against some other table. (Correct me if I'm wrong.)

psql just interprets everything in .psqlrc literally; I'm not super familiar with the details of the config file format, but would it be possible to add a section like "literal startup commands" that just sends every line straight to _evaluate_command?

Gollum999 avatar Mar 28 '18 14:03 Gollum999

My use case for it would be automatically making the session as readonly when connecting to a production database. E.g. SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;

assembler avatar Nov 05 '20 12:11 assembler