Re: Identity columns should own only one sequence

2019-08-06 Thread Peter Eisentraut
On 2019-08-05 13:30, Laurenz Albe wrote: > Peter Eisentraut wrote: >> On 2019-05-08 16:49, Laurenz Albe wrote: >>> I believe we should have both: >>> >>> - Identity columns should only use sequences with an INTERNAL dependency, >>> as in Peter's patch. >> >> I have committed this. > > Since this

Re: Identity columns should own only one sequence

2019-08-05 Thread Laurenz Albe
Peter Eisentraut wrote: > On 2019-05-08 16:49, Laurenz Albe wrote: > > I believe we should have both: > > > > - Identity columns should only use sequences with an INTERNAL dependency, > > as in Peter's patch. > > I have committed this. Since this is a bug fix, shouldn't it be backpatched? You

Re: Identity columns should own only one sequence

2019-08-05 Thread Laurenz Albe
Peter Eisentraut wrote: > On 2019-05-08 16:49, Laurenz Albe wrote: > > I believe we should have both: > > > > - Identity columns should only use sequences with an INTERNAL dependency, > > as in Peter's patch. > > I have committed this. Thanks! > > - When a column default is dropped, remove al

Re: Identity columns should own only one sequence

2019-07-22 Thread Peter Eisentraut
On 2019-05-08 16:49, Laurenz Albe wrote: > I believe we should have both: > > - Identity columns should only use sequences with an INTERNAL dependency, > as in Peter's patch. I have committed this. > - When a column default is dropped, remove all dependencies between the > column and sequenc

Re: Identity columns should own only one sequence

2019-05-08 Thread Laurenz Albe
On Tue, 2019-05-07 at 13:06 +0900, Michael Paquier wrote: > On Fri, May 03, 2019 at 08:14:35AM +0200, Laurenz Albe wrote: > > On Thu, 2019-05-02 at 22:43 +0200, Peter Eisentraut wrote: > >> I think the proper way to address this would be to create some kind of > >> dependency between the sequence a

Re: Identity columns should own only one sequence

2019-05-06 Thread Michael Paquier
On Fri, May 03, 2019 at 08:14:35AM +0200, Laurenz Albe wrote: > On Thu, 2019-05-02 at 22:43 +0200, Peter Eisentraut wrote: >> I think the proper way to address this would be to create some kind of >> dependency between the sequence and the default. > > That is certainly true. But that's hard to r

Re: Identity columns should own only one sequence

2019-05-02 Thread Laurenz Albe
On Thu, 2019-05-02 at 22:43 +0200, Peter Eisentraut wrote: > On 2019-04-29 18:28, Laurenz Albe wrote: > > I still think thatthat there is merit to Michael's idea of removing > > sequence "ownership" (which is just a dependency) when the DEFAULT > > on the column is dropped, but this approach is pos

Re: Identity columns should own only one sequence

2019-05-02 Thread Peter Eisentraut
On 2019-04-29 18:28, Laurenz Albe wrote: > I still think thatthat there is merit to Michael's idea of removing > sequence "ownership" (which is just a dependency) when the DEFAULT > on the column is dropped, but this approach is possibly cleaner. I think the proper way to address this would be to

Re: Identity columns should own only one sequence

2019-04-29 Thread Laurenz Albe
On Sat, 2019-04-27 at 14:16 +0200, Peter Eisentraut wrote: > On 2019-04-26 15:37, Laurenz Albe wrote: > > What do you think of the patch I just posted on this thread to > > remove ownership automatically when the default is dropped, as Michael > > suggested? I think that would make things much mor

Re: Identity columns should own only one sequence

2019-04-27 Thread Peter Eisentraut
On 2019-04-26 15:37, Laurenz Albe wrote: > What do you think of the patch I just posted on this thread to > remove ownership automatically when the default is dropped, as Michael > suggested? I think that would make things much more intuitive from > the user's perspective. I think that adds more

Re: Identity columns should own only one sequence

2019-04-26 Thread Michael Paquier
On Fri, Apr 26, 2019 at 11:55:34AM -0400, Alvaro Herrera wrote: > On 2019-Apr-26, Laurenz Albe wrote: > I think a better overall fix is that that when creating the generated > column (or altering a column to make it generated) we should look for > existing an existing sequence and take ownership of

Re: Identity columns should own only one sequence

2019-04-26 Thread Alvaro Herrera
On 2019-Apr-26, Laurenz Albe wrote: > What do you think of the patch I just posted on this thread to > remove ownership automatically when the default is dropped, as Michael > suggested? I think that would make things much more intuitive from > the user's perspective. I think a better overall fi

Re: Identity columns should own only one sequence

2019-04-26 Thread Laurenz Albe
On Fri, 2019-04-26 at 15:23 +0200, Peter Eisentraut wrote: > > So if one tries to convert a "serial" column to an identity column, > > the following can happen: > > > > test=> CREATE TABLE ser(id serial); > > CREATE TABLE > > test=> ALTER TABLE ser ALTER id ADD GENERATED ALWAYS AS IDENTITY; > > ER

Re: Identity columns should own only one sequence

2019-04-26 Thread Peter Eisentraut
On 2019-04-14 17:51, Laurenz Albe wrote: > Identity columns don't work if they own more than one sequence. Well, they shouldn't, because then how do they know which sequence they should use? > So if one tries to convert a "serial" column to an identity column, > the following can happen: > > tes

Re: Identity columns should own only one sequence

2019-04-26 Thread Laurenz Albe
On Thu, 2019-04-25 at 09:55 +0900, Michael Paquier wrote: > On Sun, Apr 14, 2019 at 05:51:47PM +0200, Laurenz Albe wrote: > > test=> INSERT INTO ser (id) VALUES (DEFAULT); > > ERROR: more than one owned sequence found > > Yes this should never be user-triggerable, so it seems that we need to > fi

Re: Identity columns should own only one sequence

2019-04-24 Thread Michael Paquier
On Sun, Apr 14, 2019 at 05:51:47PM +0200, Laurenz Albe wrote: > test=> INSERT INTO ser (id) VALUES (DEFAULT); > ERROR: more than one owned sequence found Yes this should never be user-triggerable, so it seems that we need to fix and back-patch something if possible. > I propose that we check if

Re: Identity columns should own only one sequence

2019-04-24 Thread Laurenz Albe
On Sun, 2019-04-14 at 20:15 +0200, I wrote: > I wrote: > > Identity columns don't work if they own more than one sequence. > > Alternatively, maybe getOwnedSequence should only consider sequences > with an "internal" dependency on the column. That would avoid the problem > without forbidding anyt

Re: Identity columns should own only one sequence

2019-04-14 Thread Laurenz Albe
I wrote: > Identity columns don't work if they own more than one sequence. > [...] > test=> INSERT INTO ser (id) VALUES (DEFAULT); > ERROR: more than one owned sequence found > > > I propose that we check if there already is a dependent sequence > before adding an identity column. > > The atta

Identity columns should own only one sequence

2019-04-14 Thread Laurenz Albe
Identity columns don't work if they own more than one sequence. So if one tries to convert a "serial" column to an identity column, the following can happen: test=> CREATE TABLE ser(id serial); CREATE TABLE test=> ALTER TABLE ser ALTER id ADD GENERATED ALWAYS AS IDENTITY; ERROR: column "id" of r