Thread: silence and failure of SQL commands

silence and failure of SQL commands

From
"John Payne"
Date:

Sorry for getting defensive, and yes I think Leif’s suggestion is much better than mine.  A statistics program I use (R) has a simple and elegant solution: it drops the cursor one line and puts in a “+” sign.  For example, here I enter the command “read” at the command prompt (>), and then forget to close the parenthesis:

 

> read(

+

 

That doesn’t solve the other potential problem, of forgetting to add the backslash to internal commands, or of putting a semicolon on them, but if I remember the error output was clearer in the latter case.

 

John

 

 

John Payne
POST Staff Scientist and US Coordinator
www.postcoml.org

Tel. (206) 463-3404

 

Re: silence and failure of SQL commands

From
Robert Poor
Date:
John:

On Thu, Apr 28, 2011 at 13:08, John Payne <jcpayne@uw.edu> wrote:
> A statistics program I use (R) has a simple and elegant
> solution: it drops the cursor one line and puts in a “+” sign.

Just for jollies, try typing this in:

\set PROMPT2 '+%# '

... and then try a command, intentionally omitting the semicolon:

postgres=# SELECT * FROM users
+#

... and see if you like the results.  If there's enough acclaim for
it, perhaps Tom will consider making it the default.

Re: silence and failure of SQL commands

From
Leif Biberg Kristensen
Date:
On Thursday 28 April 2011 22:22:24 Robert Poor wrote:

> postgres=# SELECT * FROM users
> +#

Just a piece of advice, since this is a novice list: postgres is a privileged
user (per default *the* privileged user), and you should never log in and
execute queries as such unless there is a very specific reason to do so. You
should create a user with ordinary privileges and normally use that account.
Otherwise, you run a great risk of shooting yourself in the foot, as a lot of
people have realized a little too late.

The prompt for a regular user will appear as => while the =# shows that you're
logged in as a super-user.

regards, Leif

Re: silence and failure of SQL commands

From
Robert Poor
Date:
Lief:

On Thu, Apr 28, 2011 at 13:42, Leif Biberg Kristensen
<leif@solumslekt.org> wrote:
> On Thursday 28 April 2011 22:22:24 Robert Poor wrote:
>> postgres=# SELECT * FROM users
>> +#
> The prompt for a regular user will appear as => while the =# shows that you're
> logged in as a super-user.

You are totally correct -- thou shalt not assume super-user privs
without cause.  I was using the "#" notation to be consistant with
Tom's previous post.

But this doesn't change my suggestion about changing

   \set PROMPT2 '+%# '

The "%#" token at the end expands to "#" for the super user and ">"
for us mere mortals.  So I could have typed my example as:

postgres=> SELECT * FROM users
+>

... which I think would satisfy the needs of new-ish users such as
myself and John.

- Rob

Re: silence and failure of SQL commands

From
Leif Biberg Kristensen
Date:
On Thursday 28 April 2011 22:54:36 Robert Poor wrote:

> You are totally correct -- thou shalt not assume super-user privs
> without cause.  I was using the "#" notation to be consistant with
> Tom's previous post.
>
> But this doesn't change my suggestion about changing
>
>    \set PROMPT2 '+%# '

Of course not. I've got no objection to that part.

There are plenty of ways to shoot yourself in the foot in psql as a regular
user, like a DELETE FROM without a WHERE clause. Been there, done that. Took
me a couple of restores to kick that habit.

regards, Leif

Re: silence and failure of SQL commands

From
Robert Poor
Date:
On Thu, Apr 28, 2011 at 14:06, Leif Biberg Kristensen
<leif@solumslekt.org> wrote:
> There are plenty of ways to shoot yourself in the foot in psql as a regular
> user, like a DELETE FROM without a WHERE clause. Been there, done that. Took
> me a couple of restores to kick that habit.

Ooogh -- that smarts.  Here's another excellent example of What Not To Do:

  http://xkcd.com/327/

- Robert

Re: silence and failure of SQL commands

From
"John Payne"
Date:

One subtle aspect of this is that I did the same thing wrong several times in a row:

 

1.        I enter an SQL command without a semicolon.  No response.  (I fail to notice the cursor change from => to ->)

2.       I enter another SQL command without a semicolon.  No response, and this time, the cursor is already ‘->’, so NOTHING changes.

3.       I enter another SQL command without a semicolon…no response, nothing changes.

4.       Etc.

 

I don’t know how useful it is to be able to split commands over many lines, but maybe after you’ve hit Enter without a semicolon several times it could give you more of a prompt.

 

John

 

Re: silence and failure of SQL commands

From
"John Payne"
Date:

Just a final note (at least from me) that I got around to trying Robert’s solution of setting the prompt using

 

  \set PROMPT2 '+%# '

 

and I like it very much.  I recommend trying it, and I’ll make it permanent if I can figure out how to modify the config file.

 

John