Thread: Display output file name in psql prompt?
Hello fellow hackers, Today when I get back home and connected to my psql prompt I've left running under $terminal_multiplexor I've run some SQL, but no output did appear on my screen. I have immediately realized that it must be sending it to a file instead of STDOUT as I have instructed it earlier today using \o command, but have totally forgot about the fact. So I wonder if there's a way to make psql display the current output file/command in the prompt? After reading the current docs, I don't see any option. Would a patch be accepted for submission (make it into default prompt, unless stdout?) Something like this: \set PROMPT1 '%/:%o%R%# ' postgres:/path/to/output/file.txt=> -- Regards, Alex PS: upon reading the docs more carefully, I guess I should have used \g instead of \o, but still this might be not a bad feature to have.
Alex <ash@commandprompt.com> writes: > Today when I get back home and connected to my psql prompt I've left > running under $terminal_multiplexor I've run some SQL, but no output did > appear on my screen. I have immediately realized that it must be > sending it to a file instead of STDOUT as I have instructed it earlier > today using \o command, but have totally forgot about the fact. > So I wonder if there's a way to make psql display the current output > file/command in the prompt? After reading the current docs, I don't see > any option. Would a patch be accepted for submission (make it into > default prompt, unless stdout?) If you're proposing changing the contents of the default prompt, I think that has very little chance of passing. A new option for something to add into a custom prompt might get accepted. I'm not sure that that approach would do much for the scenario you describe, since it's unlikely that anyone would add it to their prompt (at least not before they'd gotten burnt...). However, I don't recall hearing of anyone getting confused like this before, and you say you figured it out pretty quickly, so it doesn't seem like a big problem. regards, tom lane
Tom, > If you're proposing changing the contents of the default prompt, I think > that has very little chance of passing. A new option for something to > add into a custom prompt might get accepted. I'm not sure that that > approach would do much for the scenario you describe, since it's > unlikely that anyone would add it to their prompt (at least not before > they'd gotten burnt...). However, I don't recall hearing of anyone > getting confused like this before, and you say you figured it out pretty > quickly, so it doesn't seem like a big problem. Well, I think having a \ command to show the current \o setting would be fine. Actually, it might be better to show *all* psql settings with a general command, including things like \timing and \pset. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com
Josh Berkus <josh@agliodbs.com> writes: > Tom, > >> If you're proposing changing the contents of the default prompt, I think >> that has very little chance of passing. A new option for something to >> add into a custom prompt might get accepted. I'm not sure that that >> approach would do much for the scenario you describe, since it's >> unlikely that anyone would add it to their prompt (at least not before >> they'd gotten burnt...). However, I don't recall hearing of anyone >> getting confused like this before, and you say you figured it out pretty >> quickly, so it doesn't seem like a big problem. > > Well, I think having a \ command to show the current \o setting would be > fine. Actually, it might be better to show *all* psql settings with a > general command, including things like \timing and \pset. Actually in my case, I've also used \t and \a psql commands to produce undecorated machine-readable output and now I think it would be nice to also show the status of these in the prompt. What if we add '%\' substitute to expand to the list of all settings with non-default values? Like this: postgres=# \set PROMPT1 '%/%\%R%# ' postgres=# -- Nothing is set, so '%\' expands to an empty string. postgres=# \t Showing only tuples. postgres\t=# \a Output format is unaligned. postgres\a\t=# \o /path/to/output/file.out postgres\a\o=/path/to/output/file.out\t=# Not sure how \pset could fit there, it might be a bit excessive. Another idea is we could add \O and \G commands that will act like the plain \o and \g, but will set \a and \t automatically. I mean it must be quite often that you don't need all the decoration when you save query results to a file, so instead of doing \a, \t, \g (then setting \a and \t back) you can just do \G and move on. -- Alex