Re: Rethinking plpgsql's assignment implementation

2021-01-20 Thread Pavel Stehule
út 19. 1. 2021 v 19:21 odesílatel Pavel Stehule napsal: > Hi > > Now, I am testing subscribing on the jsonb feature, and I found one issue, > that is not supported by parser. > > When the target is scalar, then all is ok. But we can have a plpgsql array > of jsonb values. > > postgres=# do $$ > d

Re: Rethinking plpgsql's assignment implementation

2021-01-19 Thread Pavel Stehule
Hi Now, I am testing subscribing on the jsonb feature, and I found one issue, that is not supported by parser. When the target is scalar, then all is ok. But we can have a plpgsql array of jsonb values. postgres=# do $$ declare j jsonb[]; begin j[1] = '{"b":"Ahoj"}'; raise notice '%', j; r

Re: Rethinking plpgsql's assignment implementation

2021-01-03 Thread Pavel Stehule
ne 3. 1. 2021 v 19:07 odesílatel Tom Lane napsal: > Pavel Stehule writes: > > I found inconsistency in work with slicings (this is not directly related > > to this patch, but can be interesting, because with new functionality the > > array slicings can be edited more often). > > > a = array[1,2,

Re: Rethinking plpgsql's assignment implementation

2021-01-03 Thread Tom Lane
Pavel Stehule writes: > I found inconsistency in work with slicings (this is not directly related > to this patch, but can be interesting, because with new functionality the > array slicings can be edited more often). > a = array[1,2,3,4,5]; > a[1:5] = 10; -- correctly fails, although for some pe

Re: Rethinking plpgsql's assignment implementation

2021-01-03 Thread Pavel Stehule
Hi I continue in review. I found inconsistency in work with slicings (this is not directly related to this patch, but can be interesting, because with new functionality the array slicings can be edited more often). a = array[1,2,3,4,5]; a[1:5] = 10; -- correctly fails, although for some people c

Re: Rethinking plpgsql's assignment implementation

2020-12-27 Thread Pavel Stehule
po 28. 12. 2020 v 0:55 odesílatel Tom Lane napsal: > Pavel Stehule writes: > > Now, the behavior of SELECT INTO is behind the assign statement and this > > fact should be documented. Usually we don't need to use array's fields > > here, but somebody can try it. > > It's been behind all along --

Re: Rethinking plpgsql's assignment implementation

2020-12-27 Thread Tom Lane
Pavel Stehule writes: > Now, the behavior of SELECT INTO is behind the assign statement and this > fact should be documented. Usually we don't need to use array's fields > here, but somebody can try it. It's been behind all along --- this patch didn't really change that. But I don't mind documen

Re: Rethinking plpgsql's assignment implementation

2020-12-27 Thread Pavel Stehule
so 26. 12. 2020 v 19:00 odesílatel Pavel Stehule napsal: > Hi > > I repeated tests. I wrote a set of simple functions. It is a synthetical > test, but I think it can identify potential problems well. > > I calculated the average of 3 cycles and I checked the performance of each > function. I didn

Re: Rethinking plpgsql's assignment implementation

2020-12-26 Thread Pavel Stehule
Hi I repeated tests. I wrote a set of simple functions. It is a synthetical test, but I think it can identify potential problems well. I calculated the average of 3 cycles and I checked the performance of each function. I didn't find any problem. The total execution time is well too. Patched code

Re: Rethinking plpgsql's assignment implementation

2020-12-16 Thread Pavel Stehule
út 15. 12. 2020 v 21:18 odesílatel Tom Lane napsal: > I realized that the speedup patch I posted yesterday is flawed: it's > too aggressive about applying the R/W param mechanism, instead of > not aggressive enough. > > To review, the point of that logic is that if we have an assignment > like >

Re: Rethinking plpgsql's assignment implementation

2020-12-15 Thread Tom Lane
I realized that the speedup patch I posted yesterday is flawed: it's too aggressive about applying the R/W param mechanism, instead of not aggressive enough. To review, the point of that logic is that if we have an assignment like arrayvar := array_append(arrayvar, some-scalar-expression);

Re: Rethinking plpgsql's assignment implementation

2020-12-14 Thread Pavel Stehule
po 14. 12. 2020 v 17:25 odesílatel Tom Lane napsal: > Pavel Stehule writes: > > I checked a performance and it looks so access to record's field is > faster, > > but an access to arrays field is significantly slower > > Hmm, I'd drawn the opposite conclusion in my own testing ... > > > for i

Re: Rethinking plpgsql's assignment implementation

2020-12-14 Thread Tom Lane
Pavel Stehule writes: > I checked a performance and it looks so access to record's field is faster, > but an access to arrays field is significantly slower Hmm, I'd drawn the opposite conclusion in my own testing ... > for i in 1..5000 > loop > if a[i] > a[i+1] then > aux :

Re: Rethinking plpgsql's assignment implementation

2020-12-14 Thread Pavel Stehule
Hi I checked a performance and it looks so access to record's field is faster, but an access to arrays field is significantly slower do $$ declare a int[]; aux int; rep boolean default true; begin for i in 1..5000 loop a[i]:= 5000 - i; end loop; raise notice '%', a[1:10]; wh

Re: Rethinking plpgsql's assignment implementation

2020-12-13 Thread Pavel Stehule
ne 13. 12. 2020 v 22:41 odesílatel Tom Lane napsal: > I wrote: > > So my idea here is to add a parsing-mode option to raw_parser(), > > which would be an enum with values like "normal SQL statement", > > "expression only", "type name", "plpgsql assignment statement". > > Here's a fleshed-out patc

Re: Rethinking plpgsql's assignment implementation

2020-12-13 Thread Tom Lane
I wrote: > So my idea here is to add a parsing-mode option to raw_parser(), > which would be an enum with values like "normal SQL statement", > "expression only", "type name", "plpgsql assignment statement". Here's a fleshed-out patch series that attacks things that way. I'm a lot better pleased w

Re: Rethinking plpgsql's assignment implementation

2020-12-11 Thread Tom Lane
I wrote: > In any case, that approach still involves inserting some query text > that the user didn't write, so I'm not sure how much confusion it'd > remove. The "SET n:" business at least looks like it's some weird > prefix comparable to "LINE n:", so while people wouldn't understand > it I thin

Re: Rethinking plpgsql's assignment implementation

2020-12-11 Thread Tom Lane
Chapman Flack writes: > On 12/11/20 12:21, Tom Lane wrote: >> solution I adopted was just to invent a new CoercionContext value >> COERCION_PLPGSQL, representing "use pl/pgsql's rules". (Basically >> what that means nowadays is to apply CoerceViaIO if assignment cast >> lookup doesn't find a cast

Re: Rethinking plpgsql's assignment implementation

2020-12-11 Thread Pavel Stehule
Hi It is great. I expected much more work. pá 11. 12. 2020 v 18:21 odesílatel Tom Lane napsal: > We've had complaints in the past about how plpgsql can't handle > assignments to fields in arrays of records [1], that is cases like > > arrayvar[n].field := something; > > and also complain

Re: Rethinking plpgsql's assignment implementation

2020-12-11 Thread Chapman Flack
On 12/11/20 12:21, Tom Lane wrote: > solution I adopted was just to invent a new CoercionContext value > COERCION_PLPGSQL, representing "use pl/pgsql's rules". (Basically > what that means nowadays is to apply CoerceViaIO if assignment cast > lookup doesn't find a cast pathway.) That seems like a

Rethinking plpgsql's assignment implementation

2020-12-11 Thread Tom Lane
We've had complaints in the past about how plpgsql can't handle assignments to fields in arrays of records [1], that is cases like arrayvar[n].field := something; and also complaints about how plpgsql can't handle assignments to array slices [2], ie arrayvar[m:n] := something; A