Re: [HACKERS] plpgsql.consistent_into

2014-07-29 Thread Marko Tiikkaja
On 1/14/14, 6:15 PM, Tom Lane wrote: We don't actually implement this in PG yet, except for trivial cases, but it will certainly happen eventually. I think your sketch above deviates unnecessarily from what the standard says for UPDATE. In particular I think it'd be better to write things like

Re: [HACKERS] plpgsql.consistent_into

2014-01-22 Thread Jim Nasby
On 1/15/14, 12:35 AM, Tom Lane wrote: Jim Nasby j...@nasby.net writes: Do we actually support = right now? We already support v_field := field FROM table ... ; and I think it's a bad idea to have different meaning for = and :=. That ship sailed a *very* long time ago. See other thread about

Re: [HACKERS] plpgsql.consistent_into

2014-01-17 Thread Marti Raudsepp
On Wed, Jan 15, 2014 at 8:23 AM, Jim Nasby j...@nasby.net wrote: Do we actually support = right now? We already support v_field := field FROM table ... ; and I think it's a bad idea to have different meaning for = and :=. That was already discussed before. Yes, we support both = and := and

Re: [HACKERS] plpgsql.consistent_into

2014-01-15 Thread Pavel Stehule
2014/1/15 Jim Nasby j...@nasby.net On 1/14/14, 11:15 AM, Tom Lane wrote: How about: (a) = SELECT 1; (a, b) = SELECT 1, 2; (a, b) = INSERT INTO foo RETURNING col1, col2; Same semantics: TOO_MANY_ROWS on rows 1, sets FOUND and row_count. AFAICT this can be parsed unambiguously,

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Pavel Stehule
I am thinking so GUC and plpgsql option can live together. If you like to accent a some behave, then you can use a plpgsql option. On second hand, I would to use a some functionality, that is safe, but I don't would to dirty source code by using repeated options. But I have to check (and

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Pavel Stehule
2014/1/14 Florian Pflug f...@phlo.org On Jan14, 2014, at 00:52 , Marko Tiikkaja ma...@joh.to wrote: When I've worked with PL/PgSQL, this has been a source of a few bugs that would have been noticed during testing if the behaviour of INTO wasn't as dangerous as it is right now. The

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Marko Tiikkaja
On 1/14/14 10:16 AM, Pavel Stehule wrote: 2014/1/14 Florian Pflug f...@phlo.org So if we really want to change this, I think we need to have a LANGUAGE_VERSION attribute on functions. Each time a major postgres release changes the behaviour of one of the procedural languages, we'd increment

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Marti Raudsepp
I've always hated INTO in procedures since it makes the code harder to follow and has very different behavior on the SQL level, in addition to the multi-row problem you bring up. If we can make assignment syntax more versatile and eventually replace INTO, then that solves multiple problems in the

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Marko Tiikkaja
On 1/14/14 12:28 PM, Marti Raudsepp wrote: I've always hated INTO in procedures since it makes the code harder to follow and has very different behavior on the SQL level, in addition to the multi-row problem you bring up. If we can make assignment syntax more versatile and eventually replace

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Pavel Stehule
2014/1/14 Marko Tiikkaja ma...@joh.to On 1/14/14 12:28 PM, Marti Raudsepp wrote: I've always hated INTO in procedures since it makes the code harder to follow and has very different behavior on the SQL level, in addition to the multi-row problem you bring up. If we can make assignment

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Marko Tiikkaja
On 1/14/14 1:28 PM, Pavel Stehule wrote: I prefer subquery only syntax - a := (some) or (a,b,c) = (some a,b,c) with possible enhancing for statements with RETURNING a advance is compatibility with DB2 (SQL/PSM) syntax - and this code is written now - it is done in my sql/psm implementation

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Pavel Stehule
Hello 2014/1/14 Marko Tiikkaja ma...@joh.to On 1/14/14 1:28 PM, Pavel Stehule wrote: I prefer subquery only syntax - a := (some) or (a,b,c) = (some a,b,c) with possible enhancing for statements with RETURNING a advance is compatibility with DB2 (SQL/PSM) syntax - and this code is written

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Tom Lane
Marko Tiikkaja ma...@joh.to writes: On 1/14/14 12:28 PM, Marti Raudsepp wrote: Now, another question is whether it's possible to make the syntax work. Is this an assignment from the result of a subquery, or is it a query by itself? a = (SELECT foo FROM table); That looks like a scalar

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Marko Tiikkaja
On 1/14/14, 6:15 PM, Tom Lane wrote: Marko Tiikkaja ma...@joh.to writes: How about: (a) = SELECT 1; (a, b) = SELECT 1, 2; (a, b) = INSERT INTO foo RETURNING col1, col2; Same semantics: TOO_MANY_ROWS on rows 1, sets FOUND and row_count. AFAICT this can be parsed

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Tom Lane
Marko Tiikkaja ma...@joh.to writes: On 1/14/14, 6:15 PM, Tom Lane wrote: I'm not too sure what it'd take to make this work. Right now, SELECT (SELECT x, y FROM foo WHERE id = 42); would generate ERROR: subquery must return only one column, but I think it's mostly a historical artifact

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Jim Nasby
On 1/14/14, 11:15 AM, Tom Lane wrote: How about: (a) = SELECT 1; (a, b) = SELECT 1, 2; (a, b) = INSERT INTO foo RETURNING col1, col2; Same semantics: TOO_MANY_ROWS on rows 1, sets FOUND and row_count. AFAICT this can be parsed unambiguously, too, and we don't need to look at the

Re: [HACKERS] plpgsql.consistent_into

2014-01-14 Thread Tom Lane
Jim Nasby j...@nasby.net writes: Do we actually support = right now? We already support v_field := field FROM table ... ; and I think it's a bad idea to have different meaning for = and :=. That ship sailed a *very* long time ago. See other thread about documenting rather than ignoring this

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Jim Nasby
On 1/13/14, 1:44 AM, Pavel Stehule wrote: 2014/1/12 Florian Pflug f...@phlo.org mailto:f...@phlo.org On Jan12, 2014, at 22:37 , Pavel Stehule pavel.steh...@gmail.com mailto:pavel.steh...@gmail.com wrote: There is GUC for variable_conflict already too. In this case I would to

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Florian Pflug
On Jan13, 2014, at 22:49 , Jim Nasby j...@nasby.net wrote: ISTM that in this case, it should be safe to make the new default behavior STRICT; if you forget to set the GUC to disable than you'll get an error that points directly at the problem, at which point you'll go Oh, yeah... I forgot

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Marko Tiikkaja
On 1/14/14, 12:41 AM, Florian Pflug wrote: In fact, after reading the documentation on SELECT ... INTO, I'm convinced the the whole consistent_into thing is a bad idea. The documentation states clearly that For INSERT/UPDATE/DELETE with RETURNING, PL/pgSQL reports an error for more than

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Josh Berkus
On 01/13/2014 03:41 PM, Florian Pflug wrote: It therefor isn't an oversight that SELECT ... INTO allows multiple result rows but INSERT/UPDATE/DELETE forbids them, it's been done that way on purpose and for a reason. We shouldn't be second-guessing ourselves by changing that later - not,

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Florian Pflug
On Jan14, 2014, at 00:52 , Marko Tiikkaja ma...@joh.to wrote: When I've worked with PL/PgSQL, this has been a source of a few bugs that would have been noticed during testing if the behaviour of INTO wasn't as dangerous as it is right now. The question is, how many bugs stemmed from wrong SQL

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Jim Nasby
On 1/13/14, 5:57 PM, Josh Berkus wrote: On 01/13/2014 03:41 PM, Florian Pflug wrote: It therefor isn't an oversight that SELECT ... INTO allows multiple result rows but INSERT/UPDATE/DELETE forbids them, it's been done that way on purpose and for a reason. We shouldn't be second-guessing

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Jim Nasby
On 1/13/14, 6:16 PM, Florian Pflug wrote: On Jan14, 2014, at 00:52 , Marko Tiikkaja ma...@joh.to wrote: When I've worked with PL/PgSQL, this has been a source of a few bugs that would have been noticed during testing if the behaviour of INTO wasn't as dangerous as it is right now. The

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Florian Pflug
(Responding to both of your mails here) On Jan14, 2014, at 01:20 , Jim Nasby j...@nasby.net wrote: On 1/13/14, 5:57 PM, Josh Berkus wrote: On 01/13/2014 03:41 PM, Florian Pflug wrote: It therefor isn't an oversight that SELECT ... INTO allows multiple result rows but INSERT/UPDATE/DELETE

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Tom Lane
Florian Pflug f...@phlo.org writes: On Jan14, 2014, at 01:20 , Jim Nasby j...@nasby.net wrote: And if we've always had it, why on earth didn't we make STRICT the default behavior? Dunno, but AFAIK pl/pgsql mimics Oracle's PL/SQL, at least in some aspects, so maybe this is one of the areas

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Josh Berkus
On 01/13/2014 04:20 PM, Jim Nasby wrote: On 1/13/14, 5:57 PM, Josh Berkus wrote: I *really* don't want to go through all my old code to find places where I used SELECT ... INTO just to pop off the first row, and ignored the rest. I doubt anyone else does, either. Do you regularly have use

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Jim Nasby
On 1/13/14, 6:36 PM, Florian Pflug wrote: On Jan14, 2014, at 01:20 , Jim Nasbyj...@nasby.net wrote: On 1/13/14, 5:57 PM, Josh Berkus wrote: On 01/13/2014 03:41 PM, Florian Pflug wrote: It therefor isn't an oversight that SELECT ... INTO allows multiple result rows but INSERT/UPDATE/DELETE

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Marko Tiikkaja
On 1/14/14, 1:57 AM, Tom Lane wrote: Whatever your opinion of the default behavior, the fact that it's been that way for upwards of fifteen years without any mass protests should give you pause about changing it. For what it's worth, my patch does not change the default behaviour. I don't

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Jim Nasby
On 1/13/14, 7:06 PM, Josh Berkus wrote: On 01/13/2014 04:20 PM, Jim Nasby wrote: On 1/13/14, 5:57 PM, Josh Berkus wrote: I *really* don't want to go through all my old code to find places where I used SELECT ... INTO just to pop off the first row, and ignored the rest. I doubt anyone else

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Josh Berkus
On 01/13/2014 05:10 PM, Jim Nasby wrote: On 1/13/14, 7:06 PM, Josh Berkus wrote: Regularly? No. But I've seen it, especially as part of a does this query return any rows? test. That's not the best way to test that, but that doesn't stop a lot of people doing it. Right, and I certainly

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Marti Raudsepp
On Sun, Jan 12, 2014 at 7:51 AM, Marko Tiikkaja ma...@joh.to wrote: the behaviour of SELECT .. INTO when the query returns more than one row. Some of you might know that no exception is raised in this case Agreed. But I also agree with the rest of the thread about changing current INTO behavior

Re: [HACKERS] plpgsql.consistent_into

2014-01-13 Thread Marko Tiikkaja
On 2014-01-14 02:54, Marti Raudsepp wrote: On Sun, Jan 12, 2014 at 7:51 AM, Marko Tiikkaja ma...@joh.to wrote: the behaviour of SELECT .. INTO when the query returns more than one row. Some of you might know that no exception is raised in this case Agreed. But I also agree with the rest of

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Marko Tiikkaja
On 1/12/14, 7:47 AM, Pavel Stehule wrote: 2014/1/12 Marko Tiikkaja ma...@joh.to Greetings fellow elephants, I would humbly like to submit for your consideration my proposal for alleviating pain caused by one of the most annoying footguns in PL/PgSQL: the behaviour of SELECT .. INTO when the

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Pavel Stehule
2014/1/12 Marko Tiikkaja ma...@joh.to On 1/12/14, 7:47 AM, Pavel Stehule wrote: 2014/1/12 Marko Tiikkaja ma...@joh.to Greetings fellow elephants, I would humbly like to submit for your consideration my proposal for alleviating pain caused by one of the most annoying footguns in PL/PgSQL:

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Florian Pflug
On Jan12, 2014, at 06:51 , Marko Tiikkaja ma...@joh.to wrote: I would humbly like to submit for your consideration my proposal for alleviating pain caused by one of the most annoying footguns in PL/PgSQL: the behaviour of SELECT .. INTO when the query returns more than one row. Some of you

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Marko Tiikkaja
On 1/12/14, 10:19 PM, Florian Pflug wrote: On Jan12, 2014, at 06:51 , Marko Tiikkaja ma...@joh.to wrote: set plpgsql.consistent_into to true; I don't think a GUC is the best way to handle this. Handling this via a per-function setting similar to #variable_conflict would IMHO be better.

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Pavel Stehule
2014/1/12 Florian Pflug f...@phlo.org On Jan12, 2014, at 06:51 , Marko Tiikkaja ma...@joh.to wrote: I would humbly like to submit for your consideration my proposal for alleviating pain caused by one of the most annoying footguns in PL/PgSQL: the behaviour of SELECT .. INTO when the query

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Florian Pflug
On Jan12, 2014, at 22:37 , Pavel Stehule pavel.steh...@gmail.com wrote: There is GUC for variable_conflict already too. In this case I would to enable this functionality everywhere (it is tool how to simply eliminate some kind of strange bugs) so it needs a GUC. We have GUC for

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Gavin Flower
On 13/01/14 11:44, Florian Pflug wrote: On Jan12, 2014, at 22:37 , Pavel Stehule pavel.steh...@gmail.com wrote: There is GUC for variable_conflict already too. In this case I would to enable this functionality everywhere (it is tool how to simply eliminate some kind of strange bugs) so it

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Pavel Stehule
2014/1/12 Florian Pflug f...@phlo.org On Jan12, 2014, at 22:37 , Pavel Stehule pavel.steh...@gmail.com wrote: There is GUC for variable_conflict already too. In this case I would to enable this functionality everywhere (it is tool how to simply eliminate some kind of strange bugs) so it

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Pavel Stehule
2014/1/13 Gavin Flower gavinflo...@archidevsys.co.nz On 13/01/14 11:44, Florian Pflug wrote: On Jan12, 2014, at 22:37 , Pavel Stehule pavel.steh...@gmail.com wrote: There is GUC for variable_conflict already too. In this case I would to enable this functionality everywhere (it is tool how

Re: [HACKERS] plpgsql.consistent_into

2014-01-12 Thread Pavel Stehule
2014/1/12 Florian Pflug f...@phlo.org On Jan12, 2014, at 22:37 , Pavel Stehule pavel.steh...@gmail.com wrote: There is GUC for variable_conflict already too. In this case I would to enable this functionality everywhere (it is tool how to simply eliminate some kind of strange bugs) so it

[HACKERS] plpgsql.consistent_into

2014-01-11 Thread Marko Tiikkaja
Greetings fellow elephants, I would humbly like to submit for your consideration my proposal for alleviating pain caused by one of the most annoying footguns in PL/PgSQL: the behaviour of SELECT .. INTO when the query returns more than one row. Some of you might know that no exception is

Re: [HACKERS] plpgsql.consistent_into

2014-01-11 Thread Pavel Stehule
Hello 2014/1/12 Marko Tiikkaja ma...@joh.to Greetings fellow elephants, I would humbly like to submit for your consideration my proposal for alleviating pain caused by one of the most annoying footguns in PL/PgSQL: the behaviour of SELECT .. INTO when the query returns more than one row.