pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
survey: psql syntax errors abort my transactions
12+ messages / 7 participants
[nested] [flat]

* survey: psql syntax errors abort my transactions
@ 2020-07-02 15:54 Jeremy Schneider <schnjere@amazon.com>
  2020-07-02 16:28 ` Re: survey: psql syntax errors abort my transactions David G. Johnston <david.g.johnston@gmail.com>
  2020-07-02 16:31 ` Re: survey: psql syntax errors abort my transactions Adrian Klaver <adrian.klaver@aklaver.com>
  2020-07-03 06:54 ` Re: survey: psql syntax errors abort my transactions Laurenz Albe <laurenz.albe@cybertec.at>
  2020-07-06 01:04 ` Re: survey: psql syntax errors abort my transactions raf <raf@raf.org>
  0 siblings, 4 replies; 12+ messages in thread

From: Jeremy Schneider @ 2020-07-02 15:54 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Maybe it's just me, but I'm wondering if it's worth changing the default
behavior of psql so it doesn't abort transactions in interactive mode
when I mistakenly mis-spell "select" or something silly like that.  This
is of course easily remedied in my psqlrc file by adding "\set
ON_ERROR_ROLLBACK interactive". I don't know whether there are
equivalent settings for pgAdmin and Toad and whatever other tools people
are using for their interactive SQL sessions. But I do know that for all
the new people coming to PostgreSQL right now (including lots at my
company), none of them are going to know about this setting and
personally I think the default is user-unfriendly.

https://www.postgresql.org/docs/current/app-psql.html#id-1.9.4.18.8.5.2.9.17.1.2

A couple years back, some hackers discussed changing the default, and it
was decided against (IIUC) because of concerns about broken scripts
suddenly causing damage rather than aborting out. (About which... I
think if a script is sending broken SQL, then it might not be checking
error return values either and will likely keep running even after
PostgreSQL ignores a few SQL statements after the error in the current
session...)

https://www.postgresql.org/message-id/flat/CABTbUpiAOKZ405uArt8cJFtC72RhzthmvWETQK_6Qw0Ad-HquQ%40mai...

This thread on hackers actually seemed kindof short to me. Not nearly
enough bike-shedding to call it a closed case. It also seems to me that
the community has made significant changes across new major versions in
the past, and this idea here might not be entirely off the table quite yet.

So...

Survey for the user community here on the pgsql-general list: it would
be great if lots of people could chime in by answering two questions
about your very own production environment:

question 1) are you worried about scripts in your production environment
where damage could be caused by a different default in a future new
major version of postgresql?  (not aborting transactions in interactive
mode when syntax errors occur)

question 2) do you think the increased user-friendliness of changing
this default behavior would be worthwhile for specific users in your
organization who use postgresql?  (including both yourself and others
you know of)

As someone working at a large company with an aweful lot of PostgreSQL,
thinking of the internal production systems I'm aware of, I'd personally
vote pretty strongly in favor of changing the default.

-Jeremy


-- 
Jeremy Schneider
Database Engineer
Amazon Web Services

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
@ 2020-07-02 16:28 ` David G. Johnston <david.g.johnston@gmail.com>
  2020-07-02 16:44   ` Re: survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  3 siblings, 1 reply; 12+ messages in thread

From: David G. Johnston @ 2020-07-02 16:28 UTC (permalink / raw)
  To: Jeremy Schneider <schnjere@amazon.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Thu, Jul 2, 2020 at 8:54 AM Jeremy Schneider <schnjere@amazon.com> wrote:

>
> https://www.postgresql.org/message-id/flat/CABTbUpiAOKZ405uArt8cJFtC72RhzthmvWETQK_6Qw0Ad-HquQ%40mai...
>
> This thread on hackers actually seemed kindof short to me. Not nearly
> enough bike-shedding to call it a closed case.
>

Seemed about right:

"We should do this"
Yes
No - with a reason
No - with a reason
No - improve user education
No - emphatically
Yes - but ends ups deferring to the majority

No one else chooses to voice an opinion

The status quo prevailed since no-one chose to contribute further arguments
for change and the original patch was retracted.  What kind of
"bike-shedding" (which seems to be used incorrectly here) would you expect?

All I can speak for is personal usage but I don't find the current default
to be an issue.  I'm also generally opposed to changing this kind of
default even when I disagree with its current value.  If anything psql is a
bit too permissive by default IMO.  Default should be as safe as possible
even at the cost of user inconvenience - so that unknowledgeable people get
the most protection.  If options exist to trade safety for convenience that
is good - each user can make that trade-off for themselves and in the
process be aware of what exactly their decision entails.

David J.

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-02 16:28 ` Re: survey: psql syntax errors abort my transactions David G. Johnston <david.g.johnston@gmail.com>
@ 2020-07-02 16:44   ` Jeremy Schneider <schnjere@amazon.com>
  2020-07-02 16:52     ` Re: survey: psql syntax errors abort my transactions Adrian Klaver <adrian.klaver@aklaver.com>
  2020-07-02 16:56     ` Re: survey: psql syntax errors abort my transactions Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 2 replies; 12+ messages in thread

From: Jeremy Schneider @ 2020-07-02 16:44 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On 7/2/20 09:28, David G. Johnston wrote:
> The status quo prevailed since no-one chose to contribute further
> arguments for change and the original patch was retracted.  What kind
> of "bike-shedding" (which seems to be used incorrectly here) would you
> expect?

The bike-shedding comment reflects my sense of humor, which is evidently
so dry that it can be entirely un-detectable.  :)  But overall I do
think there's room for input from more people.  Might not change the
outcome, I'm just curious if there are more people who'd have thoughts
to offer.

I'm not sure hint text would be the right course, as the hint wouldn't
make sense in the context of other clients and I don't know if we have a
mechanism now for the server to change it's error response based on
which client is being used.

One other thought occurred to me after sending this email - does
ON_ERROR_ROLLBACK=interactive differentiate between syntax errors and
other errors? Thinking about how users approach SQL, this feels
significant. I'd happily want to let users at my company retry after
syntax errors, but I'd want them to inspect any other error more closely.

-Jeremy

-- 
Jeremy Schneider
Database Engineer
Amazon Web Services

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-02 16:28 ` Re: survey: psql syntax errors abort my transactions David G. Johnston <david.g.johnston@gmail.com>
  2020-07-02 16:44   ` Re: survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
@ 2020-07-02 16:52     ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 12+ messages in thread

From: Adrian Klaver @ 2020-07-02 16:52 UTC (permalink / raw)
  To: Jeremy Schneider <schnjere@amazon.com>; David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On 7/2/20 9:44 AM, Jeremy Schneider wrote:
> On 7/2/20 09:28, David G. Johnston wrote:
>> The status quo prevailed since no-one chose to contribute further 
>> arguments for change and the original patch was retracted.  What kind 
>> of "bike-shedding" (which seems to be used incorrectly here) would you 
>> expect?
> 
> The bike-shedding comment reflects my sense of humor, which is evidently 
> so dry that it can be entirely un-detectable.  :)  But overall I do 
> think there's room for input from more people.  Might not change the 
> outcome, I'm just curious if there are more people who'd have thoughts 
> to offer.
> 
> I'm not sure hint text would be the right course, as the hint wouldn't 
> make sense in the context of other clients and I don't know if we have a 
> mechanism now for the server to change it's error response based on 
> which client is being used.

But psql can. psql knows what the setting is and act accordingly e.g.:

test(5432)=# \x
Expanded display is on.

My suggestion is that the hint would only be shown in psql. Using  HINT: 
maybe not be the best choice as it shows up in server messages, but 
something along that line.

> 
> One other thought occurred to me after sending this email - does 
> ON_ERROR_ROLLBACK=interactive differentiate between syntax errors and 
> other errors? Thinking about how users approach SQL, this feels 
> significant. I'd happily want to let users at my company retry after 
> syntax errors, but I'd want them to inspect any other error more closely.
> 
> -Jeremy
> 
> -- 
> Jeremy Schneider
> Database Engineer
> Amazon Web Services
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-02 16:28 ` Re: survey: psql syntax errors abort my transactions David G. Johnston <david.g.johnston@gmail.com>
  2020-07-02 16:44   ` Re: survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
@ 2020-07-02 16:56     ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 12+ messages in thread

From: Adrian Klaver @ 2020-07-02 16:56 UTC (permalink / raw)
  To: Jeremy Schneider <schnjere@amazon.com>; David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On 7/2/20 9:44 AM, Jeremy Schneider wrote:
> On 7/2/20 09:28, David G. Johnston wrote:
>> The status quo prevailed since no-one chose to contribute further 
>> arguments for change and the original patch was retracted.  What kind 
>> of "bike-shedding" (which seems to be used incorrectly here) would you 
>> expect?
> 
> The bike-shedding comment reflects my sense of humor, which is evidently 
> so dry that it can be entirely un-detectable.  :)  But overall I do 
> think there's room for input from more people.  Might not change the 
> outcome, I'm just curious if there are more people who'd have thoughts 
> to offer.
> 
> I'm not sure hint text would be the right course, as the hint wouldn't 
> make sense in the context of other clients and I don't know if we have a 
> mechanism now for the server to change it's error response based on 
> which client is being used.
> 
> One other thought occurred to me after sending this email - does 
> ON_ERROR_ROLLBACK=interactive differentiate between syntax errors and 
> other errors? Thinking about how users approach SQL, this feels 
> significant. I'd happily want to let users at my company retry after 
> syntax errors, but I'd want them to inspect any other error more closely.

An error is an error:

\set ON_ERROR_ROLLBACK interactive

test(5432)=# begin ;
BEGIN
test(5432)=# slect 1;
ERROR:  syntax error at or near "slect"
LINE 1: slect 1;
         ^
test(5432)=# select 1;
  ?column?
----------
         1
(1 row)

test(5432)=# select 1/0;
ERROR:  division by zero
test(5432)=# select 1;
  ?column?
----------
         1
(1 row)

> 
> -Jeremy
> 
> -- 
> Jeremy Schneider
> Database Engineer
> Amazon Web Services
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
@ 2020-07-02 16:31 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-07-03 06:46   ` Re: survey: psql syntax errors abort my transactions Laurenz Albe <laurenz.albe@cybertec.at>
  3 siblings, 1 reply; 12+ messages in thread

From: Adrian Klaver @ 2020-07-02 16:31 UTC (permalink / raw)
  To: Jeremy Schneider <schnjere@amazon.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On 7/2/20 8:54 AM, Jeremy Schneider wrote:
> Maybe it's just me, but I'm wondering if it's worth changing the default 
> behavior of psql so it doesn't abort transactions in interactive mode 
> when I mistakenly mis-spell "select" or something silly like that.  This 
> is of course easily remedied in my psqlrc file by adding "\set 
> ON_ERROR_ROLLBACK interactive". I don't know whether there are 
> equivalent settings for pgAdmin and Toad and whatever other tools people 
> are using for their interactive SQL sessions. But I do know that for all 
> the new people coming to PostgreSQL right now (including lots at my 
> company), none of them are going to know about this setting and 
> personally I think the default is user-unfriendly.
> 
> https://www.postgresql.org/docs/current/app-psql.html#id-1.9.4.18.8.5.2.9.17.1.2
> 
> A couple years back, some hackers discussed changing the default, and it 
> was decided against (IIUC) because of concerns about broken scripts 
> suddenly causing damage rather than aborting out. (About which... I 
> think if a script is sending broken SQL, then it might not be checking 
> error return values either and will likely keep running even after 
> PostgreSQL ignores a few SQL statements after the error in the current 
> session...)
> 
> https://www.postgresql.org/message-id/flat/CABTbUpiAOKZ405uArt8cJFtC72RhzthmvWETQK_6Qw0Ad-HquQ%40mai...
> 
> This thread on hackers actually seemed kindof short to me. Not nearly 
> enough bike-shedding to call it a closed case. It also seems to me that 
> the community has made significant changes across new major versions in 
> the past, and this idea here might not be entirely off the table quite yet.
> 
> So...
> 
> Survey for the user community here on the pgsql-general list: it would 
> be great if lots of people could chime in by answering two questions 
> about your very own production environment:
> 
> question 1) are you worried about scripts in your production environment 
> where damage could be caused by a different default in a future new 
> major version of postgresql?  (not aborting transactions in interactive 
> mode when syntax errors occur)
> 
> question 2) do you think the increased user-friendliness of changing 
> this default behavior would be worthwhile for specific users in your 
> organization who use postgresql?  (including both yourself and others 
> you know of)

I would say just add a message to the ERROR that points out 
ON_ERROR_ROLLBACK = 'on' is available. For instance:

test(5432)=# begin ;
BEGIN
test(5432)=# select 1/0;
ERROR:  division by zero
test(5432)=# select 1;
ERROR:  current transaction is aborted, commands ignored until end of 
transaction block

New part of message
HINT: \set ON_ERROR_ROLLBACK on to rollback on error.

> 
> As someone working at a large company with an aweful lot of PostgreSQL, 
> thinking of the internal production systems I'm aware of, I'd personally 
> vote pretty strongly in favor of changing the default.
> 
> -Jeremy
> 
> 
> -- 
> Jeremy Schneider
> Database Engineer
> Amazon Web Services
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-02 16:31 ` Re: survey: psql syntax errors abort my transactions Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-07-03 06:46   ` Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 0 replies; 12+ messages in thread

From: Laurenz Albe @ 2020-07-03 06:46 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; Jeremy Schneider <schnjere@amazon.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Thu, 2020-07-02 at 09:31 -0700, Adrian Klaver wrote:
> I would say just add a message to the ERROR that points out 
> ON_ERROR_ROLLBACK = 'on' is available. For instance:
> 
> test(5432)=# begin ;
> BEGIN
> test(5432)=# select 1/0;
> ERROR:  division by zero
> test(5432)=# select 1;
> ERROR:  current transaction is aborted, commands ignored until end of 
> transaction block
> 
> New part of message
> HINT: \set ON_ERROR_ROLLBACK on to rollback on error.

-1

That would increase the already annoying spam of "current transaction is aborted"
messages when your transaction fails.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
@ 2020-07-03 06:54 ` Laurenz Albe <laurenz.albe@cybertec.at>
  2020-07-03 17:46   ` Re: survey: psql syntax errors abort my transactions Ron <ronljohnsonjr@gmail.com>
  3 siblings, 1 reply; 12+ messages in thread

From: Laurenz Albe @ 2020-07-03 06:54 UTC (permalink / raw)
  To: Jeremy Schneider <schnjere@amazon.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Thu, 2020-07-02 at 08:54 -0700, Jeremy Schneider wrote:
> Maybe it's just me, but I'm wondering if it's worth changing the default behavior
> of psql so it doesn't abort transactions in interactive mode when I mistakenly
> mis-spell "select" or something silly like that.
> This is of course easily remedied in my psqlrc file by adding "\set ON_ERROR_ROLLBACK interactive".
> [...]
> But I do know that for all the new people coming to PostgreSQL right now
> (including lots at my company), none of them are going to know about this setting
> and personally I think the default is user-unfriendly.
> [...]
>
> So...
> 
> Survey for the user community here on the pgsql-general list: it would be great if lots
> of people could chime in by answering two questions about your very own production environment:
> 
> question 1) are you worried about scripts in your production environment where damage
> could be caused by a different default in a future new major version of postgresql?
> not aborting transactions in interactive mode when syntax errors occur)

I would dislike if interactive mode behaves differently from a non-interactive mode.

This is my favorite example why I like the way PostgreSQL does things:

/* poor man's VACUUM (FULL) */
BEGIN;
CREATTE TABLE t2 AS SELECT * FROM t1;
DROP TABLE t1;
ALTER TABLE t2 RENAME TO t1;
COMMIT;

> question 2) do you think the increased user-friendliness of changing this default
> behavior would be worthwhile for specific users in your organization who use postgresql?
> (including both yourself and others you know of)

I personally would benefit because I wouldn't have to repeat the whole transaction
while teaching a class when I made a typo inside a transaction.

Still I prefer the way things are currently.  Teaching classes is not the main
use case of psql.

Yours,
Laurenz Albe






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-03 06:54 ` Re: survey: psql syntax errors abort my transactions Laurenz Albe <laurenz.albe@cybertec.at>
@ 2020-07-03 17:46   ` Ron <ronljohnsonjr@gmail.com>
  2020-07-03 18:41     ` Re: survey: psql syntax errors abort my transactions Julien Rouhaud <rjuju123@gmail.com>
  2020-07-06 08:15     ` Re: survey: psql syntax errors abort my transactions Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 2 replies; 12+ messages in thread

From: Ron @ 2020-07-03 17:46 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 7/3/20 1:54 AM, Laurenz Albe wrote:
> On Thu, 2020-07-02 at 08:54 -0700, Jeremy Schneider wrote:
>> Maybe it's just me, but I'm wondering if it's worth changing the default behavior
>> of psql so it doesn't abort transactions in interactive mode when I mistakenly
>> mis-spell "select" or something silly like that.
>> This is of course easily remedied in my psqlrc file by adding "\set ON_ERROR_ROLLBACK interactive".
>> [...]
>> But I do know that for all the new people coming to PostgreSQL right now
>> (including lots at my company), none of them are going to know about this setting
>> and personally I think the default is user-unfriendly.
>> [...]
>>
>> So...
>>
>> Survey for the user community here on the pgsql-general list: it would be great if lots
>> of people could chime in by answering two questions about your very own production environment:
>>
>> question 1) are you worried about scripts in your production environment where damage
>> could be caused by a different default in a future new major version of postgresql?
>> not aborting transactions in interactive mode when syntax errors occur)
> I would dislike if interactive mode behaves differently from a non-interactive mode.
>
> This is my favorite example why I like the way PostgreSQL does things:
>
> /* poor man's VACUUM (FULL) */
> BEGIN;
> CREATTE TABLE t2 AS SELECT * FROM t1;
> DROP TABLE t1;
> ALTER TABLE t2 RENAME TO t1;
> COMMIT;

How so, since it does not carry over indexes, foreign keys, triggers, 
partition references, etc?

-- 
Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-03 06:54 ` Re: survey: psql syntax errors abort my transactions Laurenz Albe <laurenz.albe@cybertec.at>
  2020-07-03 17:46   ` Re: survey: psql syntax errors abort my transactions Ron <ronljohnsonjr@gmail.com>
@ 2020-07-03 18:41     ` Julien Rouhaud <rjuju123@gmail.com>
  1 sibling, 0 replies; 12+ messages in thread

From: Julien Rouhaud @ 2020-07-03 18:41 UTC (permalink / raw)
  To: Ron <ronljohnsonjr@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Fri, Jul 3, 2020 at 7:46 PM Ron <ronljohnsonjr@gmail.com> wrote:
>
> On 7/3/20 1:54 AM, Laurenz Albe wrote:
> > This is my favorite example why I like the way PostgreSQL does things:
> >
> > /* poor man's VACUUM (FULL) */
> > BEGIN;
> > CREATTE TABLE t2 AS SELECT * FROM t1;
> > DROP TABLE t1;
> > ALTER TABLE t2 RENAME TO t1;
> > COMMIT;
>
> How so, since it does not carry over indexes, foreign keys, triggers,
> partition references, etc?

The point of this example is that if you have a typo in the CREATE
TABLE like here, you *don't want* to continue executing the commands,
which would drop the original table while you don't have a copy of the
data anymore.  That's what he meant by liking the way postgres does
things, not how to do this poor man's vacuum full.





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
  2020-07-03 06:54 ` Re: survey: psql syntax errors abort my transactions Laurenz Albe <laurenz.albe@cybertec.at>
  2020-07-03 17:46   ` Re: survey: psql syntax errors abort my transactions Ron <ronljohnsonjr@gmail.com>
@ 2020-07-06 08:15     ` Laurenz Albe <laurenz.albe@cybertec.at>
  1 sibling, 0 replies; 12+ messages in thread

From: Laurenz Albe @ 2020-07-06 08:15 UTC (permalink / raw)
  To: Ron <ronljohnsonjr@gmail.com>; pgsql-general@lists.postgresql.org

On Fri, 2020-07-03 at 12:46 -0500, Ron wrote:
> > This is my favorite example why I like the way PostgreSQL does things:
> > 
> > /* poor man's VACUUM (FULL) */
> > BEGIN;
> > CREATTE TABLE t2 AS SELECT * FROM t1;
> > DROP TABLE t1;
> > ALTER TABLE t2 RENAME TO t1;
> > COMMIT;
> 
> How so, since it does not carry over indexes, foreign keys, triggers, 
> partition references, etc?

It is an example of what a transaction could look like that
would suffer from statement-level rollback.

I am not claimimg that that code as such is very useful.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: survey: psql syntax errors abort my transactions
  2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
@ 2020-07-06 01:04 ` raf <raf@raf.org>
  3 siblings, 0 replies; 12+ messages in thread

From: raf @ 2020-07-06 01:04 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Jeremy Schneider wrote:

> Survey for the user community here on the pgsql-general list: it would
> be great if lots of people could chime in by answering two questions
> about your very own production environment:
> 
> question 1) are you worried about scripts in your production environment
> where damage could be caused by a different default in a future new
> major version of postgresql?  (not aborting transactions in interactive
> mode when syntax errors occur)

No. Any production scripts would be a single transaction.
I think anything else is a disaster waiting to happen
(and waiting for me to clean up afterwards).

> question 2) do you think the increased user-friendliness of changing
> this default behavior would be worthwhile for specific users in your
> organization who use postgresql?  (including both yourself and others
> you know of)

No. In fact, I think aborting on error is more
user-friendly than not doing so. I often send ad hoc
sql to psql via vim key bindings. I think that counts
as interactive from psql's point of view. The only
problem I have with that is when I mistyped "begin
transaction;" (or forgot the semi colon) and so an
error half way through doesn't result in a full
rollback. But I don't see what can be done about that
(other than automating the insertion of "begin
transaction;" and "commit transaction;" in my ad hoc
sql vim buffers).

What might be actually user-friendly is the ability,
after such an error, of being able to edit the contents
of the failed statement/transaction in the interactive
session in an editor to fix the typo. But that's for
real interactive use where stdin is a pty. That way,
you wouldn't have to retype or copy and paste the good
bits. That might already be possible. Yes, it's "\e".
And it works after an error, bringing up the
erroroneous sql in an editor, and it executes it when
you save and exit the editor. I think that's probably
what you want and it's already there. But it only edits
the last statement, not the whole transaction. It might
not be exactly what you need.

> As someone working at a large company with an aweful lot of PostgreSQL,
> thinking of the internal production systems I'm aware of, I'd personally
> vote pretty strongly in favor of changing the default.
> 
> -Jeremy
> 
> Jeremy Schneider
> Database Engineer
> Amazon Web Services

cheers,
raf






^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2020-07-06 08:15 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 15:54 survey: psql syntax errors abort my transactions Jeremy Schneider <schnjere@amazon.com>
2020-07-02 16:28 ` David G. Johnston <david.g.johnston@gmail.com>
2020-07-02 16:44   ` Jeremy Schneider <schnjere@amazon.com>
2020-07-02 16:52     ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-07-02 16:56     ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-07-02 16:31 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-07-03 06:46   ` Laurenz Albe <laurenz.albe@cybertec.at>
2020-07-03 06:54 ` Laurenz Albe <laurenz.albe@cybertec.at>
2020-07-03 17:46   ` Ron <ronljohnsonjr@gmail.com>
2020-07-03 18:41     ` Julien Rouhaud <rjuju123@gmail.com>
2020-07-06 08:15     ` Laurenz Albe <laurenz.albe@cybertec.at>
2020-07-06 01:04 ` raf <raf@raf.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox