Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-03 Thread Martijn van Oosterhout
On Mon, Jun 02, 2014 at 01:29:25PM -0400, Robert Haas wrote: I agree, but I think it's important to note that Alex's complaint is not unique - the way things work now is a real source of frustration for users. In a previous job, I wrote a schema-upgrade script that dropped all of the views in

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-03 Thread Robert Haas
On Mon, Jun 2, 2014 at 10:00 PM, Tom Lane t...@sss.pgh.pa.us wrote: I can see two answers. Answer #1 is that the column type of bar.a changes from int to bigint and the view definition is still SELECT a FROM foo. In that case, showing the user the SQL does not help them see and approve

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-03 Thread David G Johnston
On Tuesday, June 3, 2014, Robert Haas [via PostgreSQL] ml-node+s1045698n5805857...@n5.nabble.com wrote: On Mon, Jun 2, 2014 at 10:00 PM, Tom Lane [hidden email] http://user/SendEmail.jtp?type=nodenode=5805857i=0 wrote: I can see two answers. Answer #1 is that the column type of bar.a

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-03 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mon, Jun 2, 2014 at 10:00 PM, Tom Lane t...@sss.pgh.pa.us wrote: Or something else; I don't claim to be a good UI designer. But in the end, this is 90% a UI problem, and that means that raw SQL is seriously poorly suited to solve it directly. I

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-03 Thread Robert Haas
On Tue, Jun 3, 2014 at 10:14 AM, Tom Lane t...@sss.pgh.pa.us wrote: If we had such a mechanism, then perhaps someone could build a UI providing the sort of user feedback you're suggesting to help them use it more safely. But isn't the core server support the first thing? I'm guessing you

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-03 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Tue, Jun 3, 2014 at 10:14 AM, Tom Lane t...@sss.pgh.pa.us wrote: I'm guessing you did not read http://www.postgresql.org/message-id/18723.1401734...@sss.pgh.pa.us Argh, sorry, I saw that go by and it went past my eyes but obviously I didn't really

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Robert Haas
On Wed, May 28, 2014 at 8:22 AM, ash a...@commandprompt.com wrote: None of that involves answering hypothetical questions; but what you want to do does, and that I think is the problem in a nutshell. In a nutshell I'd like PostgreSQL to just re-parse the *current* view definition. Should

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread ash
Robert Haas robertmh...@gmail.com writes: On Wed, May 28, 2014 at 8:22 AM, ash a...@commandprompt.com wrote: None of that involves answering hypothetical questions; but what you want to do does, and that I think is the problem in a nutshell. In a nutshell I'd like PostgreSQL to just

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: What exactly do you mean by re-parse the current view definition? The only form of the view definition we actually have is already parsed into an internal form (see pg_rewrite) which, for the reasons I've attempted to explain, is not easy to adapt to

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Robert Haas
On Mon, Jun 2, 2014 at 8:52 AM, ash a...@commandprompt.com wrote: On Wed, May 28, 2014 at 8:22 AM, ash a...@commandprompt.com wrote: None of that involves answering hypothetical questions; but what you want to do does, and that I think is the problem in a nutshell. In a nutshell I'd like

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mon, Jun 2, 2014 at 8:52 AM, ash a...@commandprompt.com wrote: Should this fail, the user will have to work around it, but most of the time it could just work. You're either missing or choosing to ignore the point that I'm making, which is that we

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread ash
Tom Lane t...@sss.pgh.pa.us writes: Robert Haas robertmh...@gmail.com writes: On Mon, Jun 2, 2014 at 8:52 AM, ash a...@commandprompt.com wrote: Should this fail, the user will have to work around it, but most of the time it could just work. You're either missing or choosing to ignore the

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Robert Haas
On Mon, Jun 2, 2014 at 10:21 AM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Mon, Jun 2, 2014 at 8:52 AM, ash a...@commandprompt.com wrote: Should this fail, the user will have to work around it, but most of the time it could just work. You're either

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mon, Jun 2, 2014 at 10:21 AM, Tom Lane t...@sss.pgh.pa.us wrote: The real problem in my mind is one of user expectations. If the database silently does something behind your back, people expect that that action will be *right* and they don't have

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Stephen Frost
* Robert Haas (robertmh...@gmail.com) wrote: On Mon, Jun 2, 2014 at 10:21 AM, Tom Lane t...@sss.pgh.pa.us wrote: The real problem in my mind is one of user expectations. If the database silently does something behind your back, people expect that that action will be *right* and they don't

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Stephen Frost
* Tom Lane (t...@sss.pgh.pa.us) wrote: Robert Haas robertmh...@gmail.com writes: I agree, but I think it's important to note that Alex's complaint is not unique - the way things work now is a real source of frustration for users. Oh, I quite agree with that. My concern here has to do

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Josh Berkus
On 06/02/2014 10:40 AM, Stephen Frost wrote: Tom's point goes back to what I was trying to drive at originally- people should have to ask for this. Perhaps we can provide a way for them to ask which is explicit enough that they understand this might not do exactly what you think it does, akin

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Andres Freund
On 2014-06-02 10:48:02 -0700, Josh Berkus wrote: On 06/02/2014 10:40 AM, Stephen Frost wrote: Tom's point goes back to what I was trying to drive at originally- people should have to ask for this. Perhaps we can provide a way for them to ask which is explicit enough that they understand

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Andres Freund
On 2014-06-02 13:40:32 -0400, Stephen Frost wrote: Of course, there is a question about if it's worth it to keep around the exact text of each CREATE VIEW and build all this infrastructure for something which will only work properly in a specific subset of cases and in many others could break

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Alvaro Herrera
Tom Lane wrote: Oh, I quite agree with that. My concern here has to do with automatically and silently making changes that we can't be very sure will meet the user's expectations. Perhaps what we need is some kind of UI/API design whereby the user can inspect/modify/approve the semantic

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Robert Haas
On Mon, Jun 2, 2014 at 1:40 PM, Stephen Frost sfr...@snowman.net wrote: * Robert Haas (robertmh...@gmail.com) wrote: On Mon, Jun 2, 2014 at 10:21 AM, Tom Lane t...@sss.pgh.pa.us wrote: The real problem in my mind is one of user expectations. If the database silently does something behind

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes: Tom Lane wrote: Oh, I quite agree with that. My concern here has to do with automatically and silently making changes that we can't be very sure will meet the user's expectations. Perhaps what we need is some kind of UI/API design whereby the

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: FWIW, I don't think reparsing the original view-text is even remotely plausible. The fact that views stay glued to the same objects even of those objects are renamed is a pretty handy property of the current system, and any sort of

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Robert Haas
On Mon, Jun 2, 2014 at 2:47 PM, Tom Lane t...@sss.pgh.pa.us wrote: Deparse-and-reparse might be better, but I'll bet that has too many problems to be viable, too (even if I haven't yet thought of what they are). For better or for worse, I think the best we're likely to be able to do is

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-06-02 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mon, Jun 2, 2014 at 2:47 PM, Tom Lane t...@sss.pgh.pa.us wrote: I think deparse-and-reparse is exactly what we have to do, mainly because, if you subscribe to the idea that the user should see and approve semantic changes, what else are we going to

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread Stephen Frost
* Robert Haas (robertmh...@gmail.com) wrote: On Mon, May 26, 2014 at 10:39 AM, Stephen Frost sfr...@snowman.net wrote: It'd need to be explicitly requested, eg a 'CASCADE' option. Why? Would any sane person NOT want this behavior? [...] Now maybe there are options other than trying to

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread ash
Robert Haas robertmh...@gmail.com writes: Well, pg_dump is trying to do something different than what you're trying to do here. pg_dump wants to make sure that the view, when fed back into psql, creates the same view that exists now, regardless of whether that's what the user created

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread ash
Stephen Frost sfr...@snowman.net writes: I hadn't even considered the idea that we would go through and try to change everything which referenced that view to now be the new type- but in that case, I'd want to know that there were other changes which were happening beyond the single view

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread Stephen Frost
* ash (a...@commandprompt.com) wrote: Stephen Frost sfr...@snowman.net writes: I hadn't even considered the idea that we would go through and try to change everything which referenced that view to now be the new type- but in that case, I'd want to know that there were other changes which

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread ash
Stephen Frost sfr...@snowman.net writes: * ash (a...@commandprompt.com) wrote: Stephen Frost sfr...@snowman.net writes: Also consider MatViews which would need to be rewritten for the new type That might be costly but not impossible. A user would need to do that anyway, though

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread Stephen Frost
* ash (a...@commandprompt.com) wrote: What I am suggesting is that we try to detect such breakage at the time the user runs ALTER TABLE (issuing NOTICE or ERROR at user discretion.) If changing column type of a table breaks some functions down the way, the user will hit it anyway, but better

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread Tom Lane
ash a...@commandprompt.com writes: Stephen Frost sfr...@snowman.net writes: We're not going to re-parse every function in the system, like, ever. Well, only every *affected* function, which might be pretty minimal in the usual case. We don't store dependency information for function bodies,

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread ash
Tom Lane t...@sss.pgh.pa.us writes: We don't store dependency information for function bodies, so there's no way to do this except by reparsing everything in sight. A larger issue with the idea is that a function might fail reparsing for reasons having nothing to do with the proposed ALTER

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread Alvaro Herrera
ash wrote: Tom Lane t...@sss.pgh.pa.us writes: We don't store dependency information for function bodies, so there's no way to do this except by reparsing everything in sight. OK, forget functions, I now realize it's not feasible to consider. Can we get back to re-defining views at

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-28 Thread Stephen Frost
* ash (a...@commandprompt.com) wrote: OK, forget functions, I now realize it's not feasible to consider. I never meant to imply that it was but rather to point out that we might have users who actually want to get an error when they're changing a type definition which goes beyond the scope of

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-27 Thread ash
David Fetter da...@fetter.org writes: Also worth considering: functions which take any part of the view as a parameter. Sorry, I don't get it: do you suggest we should re-create dependent functions too? I'd throw an error in cases where such functions had an obvious and deterministic

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-27 Thread Robert Haas
On Mon, May 26, 2014 at 10:39 AM, Stephen Frost sfr...@snowman.net wrote: * ash (a...@commandprompt.com) wrote: This came up recently on general list (and I've just hit the same issue today):

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-27 Thread David G Johnston
Alexander Shulgin wrote Hi Hackers, This came up recently on general list (and I've just hit the same issue today): http://www.postgresql.org/message-id/ CAB7nPqTLmMn1LTb5WE0v0dO57iP0U73yKwzbZytAXDF1CAWLZg@.gmail Why couldn't postgres re-create the dependent views automatically? I

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-27 Thread ash
Robert Haas robertmh...@gmail.com writes: It'd need to be explicitly requested, eg a 'CASCADE' option. Why? Would any sane person NOT want this behavior? I think the question here is whether there's any way to make this work at all, not whether we'd want it if we could get it. Consider:

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-27 Thread ash
David G Johnston david.g.johns...@gmail.com writes: Would it be possible to handle the specific case of varchar(n) to varchar/text by just ignoring the error? Simply for the reference, my case is INT to BIGINT. -- Alex -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-27 Thread Robert Haas
On Tue, May 27, 2014 at 11:20 PM, ash a...@commandprompt.com wrote: Now, consider the situation in which we want to achieve the same result without having to drop and recreate v. When the column type of t.a is changed, we can use the dependencies to figure out that v might be impacted. We

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-26 Thread Stephen Frost
ash, * ash (a...@commandprompt.com) wrote: This came up recently on general list (and I've just hit the same issue today): http://www.postgresql.org/message-id/cab7npqtlmmn1ltb5we0v0do57ip0u73ykwzbzytaxdf1caw...@mail.gmail.com Why couldn't postgres re-create the dependent views

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-26 Thread David Fetter
On Mon, May 26, 2014 at 06:25:09PM +0400, ash wrote: Hi Hackers, This came up recently on general list (and I've just hit the same issue today): http://www.postgresql.org/message-id/cab7npqtlmmn1ltb5we0v0do57ip0u73ykwzbzytaxdf1caw...@mail.gmail.com Why couldn't postgres re-create the

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-26 Thread ash
David Fetter da...@fetter.org writes: On Mon, May 26, 2014 at 06:25:09PM +0400, ash wrote: Hi Hackers, This came up recently on general list (and I've just hit the same issue today):

Re: [HACKERS] Re-create dependent views on ALTER TABLE ALTER COLUMN ... TYPE?

2014-05-26 Thread David Fetter
On Tue, May 27, 2014 at 12:37:32AM +0400, ash wrote: David Fetter da...@fetter.org writes: On Mon, May 26, 2014 at 06:25:09PM +0400, ash wrote: Hi Hackers, This came up recently on general list (and I've just hit the same issue today):