Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Merlin Moncure
On Tue, Jun 17, 2014 at 9:02 AM, Tom Lane wrote: > But come to think of it, WITH is already an interesting precedent: if you > look into rewriteHandler.c you'll notice a boatload of corner cases where > the rewriter just throws up its hands for various combinations of rules > and statements contai

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Tom Lane
Martijn van Oosterhout writes: > Would it not be possible to use WITH here, like: > WITH bar AS ( ... subselect ... ) > INSERT INTO foolog VALUES (bar.a, bar.b, ...) Don't think it works if the sub-select is correlated. Consider something like UPDATE summary_table s SET (sumx, sumy) = (SELEC

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Andres Freund
On 2014-06-17 09:46:13 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2014-06-17 11:22:17 +0200, Vik Fearing wrote: > >> On 06/17/2014 09:43 AM, Hannu Krosing wrote: > >>> Was'nt there a plan (consensus?) about deprecating rules altogether ? > > >> I believe that was just for user access t

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Tom Lane
Andres Freund writes: > On 2014-06-17 11:22:17 +0200, Vik Fearing wrote: >> On 06/17/2014 09:43 AM, Hannu Krosing wrote: >>> Was'nt there a plan (consensus?) about deprecating rules altogether ? >> I believe that was just for user access to them, ie CREATE RULE. I >> don't think there was ever q

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Andres Freund
On 2014-06-17 11:22:17 +0200, Vik Fearing wrote: > On 06/17/2014 09:43 AM, Hannu Krosing wrote: > > On 06/14/2014 09:35 PM, Tom Lane wrote: > >> > As I mentioned awhile ago, I'm thinking about implementing the > >> > SQL-standard construct > >> > > >> > UPDATE foo SET ..., (a,b,...) = (SELECT x,y,

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Hannu Krosing
On 06/17/2014 11:22 AM, Vik Fearing wrote: > On 06/17/2014 09:43 AM, Hannu Krosing wrote: >> On 06/14/2014 09:35 PM, Tom Lane wrote: As I mentioned awhile ago, I'm thinking about implementing the SQL-standard construct UPDATE foo SET ..., (a,b,...) = (SELECT x,y,...), ... >>>

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Vik Fearing
On 06/17/2014 09:43 AM, Hannu Krosing wrote: > On 06/14/2014 09:35 PM, Tom Lane wrote: >> > As I mentioned awhile ago, I'm thinking about implementing the >> > SQL-standard construct >> > >> >UPDATE foo SET ..., (a,b,...) = (SELECT x,y,...), ... >> > >> > I've run into a rather nasty problem, w

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Hannu Krosing
On 06/14/2014 09:35 PM, Tom Lane wrote: > As I mentioned awhile ago, I'm thinking about implementing the > SQL-standard construct > > UPDATE foo SET ..., (a,b,...) = (SELECT x,y,...), ... > > I've run into a rather nasty problem, which is how does this interact > with expansion of NEW referen

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-17 Thread Martijn van Oosterhout
On Sat, Jun 14, 2014 at 03:35:33PM -0400, Tom Lane wrote: > The best that I think is reasonable to do in such cases is to pull out > a separate copy of the sub-select for each actual NEW reference in a > rule query. So the example above would give rise to an expanded > rule query along the lines o

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Andres Freund
On 2014-06-14 19:27:03 -0500, Jim Nasby wrote: > On 6/14/14, 3:51 PM, Andres Freund wrote: > >>Hm. But you might as well use a trigger, no? Is anyone likely to > >>>actually be doing such a thing? > >I don't think anybody is likely to do such a thing on an actual table, > >but INSTEAD OF for view

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Jim Nasby
On 6/14/14, 3:51 PM, Andres Freund wrote: Hm. But you might as well use a trigger, no? Is anyone likely to >actually be doing such a thing? I don't think anybody is likely to do such a thing on an actual table, but INSTEAD OF for views is pretty new. For a long time rules were the the only way

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Andres Freund
On 2014-06-14 16:44:10 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2014-06-14 15:48:52 -0400, Tom Lane wrote: > >> Well, it wouldn't be "unsafe" (barring volatile functions in the UPDATE, > >> which are unsafe already). It might be slow, but that's probably better > >> than failing. >

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Tom Lane
Andres Freund writes: > On 2014-06-14 15:48:52 -0400, Tom Lane wrote: >> Well, it wouldn't be "unsafe" (barring volatile functions in the UPDATE, >> which are unsafe already). It might be slow, but that's probably better >> than failing. > I forgot the details, but IIRC it's possible to write a

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Andres Freund
On 2014-06-14 15:48:52 -0400, Tom Lane wrote: > Andres Freund writes: > > Hi, > > On 2014-06-14 15:35:33 -0400, Tom Lane wrote: > >> Given that ON UPDATE rules are close to being a deprecated feature, > >> it doesn't seem appropriate to work harder than this; and frankly > >> I don't see how we co

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Tom Lane
Andres Freund writes: > Hi, > On 2014-06-14 15:35:33 -0400, Tom Lane wrote: >> Given that ON UPDATE rules are close to being a deprecated feature, >> it doesn't seem appropriate to work harder than this; and frankly >> I don't see how we could avoid multiple sub-select evaluations anyway, >> if th

Re: [HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Andres Freund
Hi, On 2014-06-14 15:35:33 -0400, Tom Lane wrote: > Given that ON UPDATE rules are close to being a deprecated feature, > it doesn't seem appropriate to work harder than this; and frankly > I don't see how we could avoid multiple sub-select evaluations anyway, > if the NEW references are in WHERE

[HACKERS] UPDATE SET (a,b,c) = (SELECT ...) versus rules

2014-06-14 Thread Tom Lane
As I mentioned awhile ago, I'm thinking about implementing the SQL-standard construct UPDATE foo SET ..., (a,b,...) = (SELECT x,y,...), ... I've run into a rather nasty problem, which is how does this interact with expansion of NEW references in ON UPDATE rules? For example, suppose foo