From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Jeffrey W(dot) Baker" <jwbaker(at)acm(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net> |
Subject: | Re: psql exit status varies for scripts on STDIN |
Date: | 2004-09-14 05:15:02 |
Message-ID: | 2566.1095138902@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Jeffrey W. Baker" <jwbaker(at)acm(dot)org> writes:
> $ echo "your mom" | psql
> ERROR: syntax error at or near "your" at character 1
> $ echo $?
> 0
> The script failed, but the exit status is 0 (success) anyway.
> $ psql -c "your mom"
> ERROR: syntax error at or near "your" at character 1
> $ echo $?
> 1
> If the same command is given with -c, the exit status indicates failure.
AFAICS the first behavior comports with what it says in the psql man
page, and the second does not.
: Exit Status
: psql returns 0 to the shell if it finished normally, 1 if a fatal error
: of its own (out of memory, file not found) occurs, 2 if the connection
: to the server went bad and the session was not interactive, and 3 if an
: error occurred in a script and the variable ON_ERROR_STOP was set.
I think this behavior is correct for the script case. You can quibble
about whether reading from stdin is just like the script case or not,
but really the answer is to set ON_ERROR_STOP if you want a report.
If -c is considered to be a shorthand for a script, then this ought to
yield either 0 or 3 depending on whether ON_ERROR_STOP is set by
~/.psqlrc. However I'm not sure if ~/.psqlrc is read for a -c
invocation. I'd be willing to agree that -c should act as though
ON_ERROR_STOP is set always ... but in that case the exit code should
be 3, not 1.
Peter, I think you were the last to touch this stuff; any comments?
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2004-09-14 06:36:56 | Re: Deadlock removal |
Previous Message | Tom Lane | 2004-09-14 05:03:34 | Re: how to use geometric shapes? |