Re: poc - possibility to write window function in PL languages

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: poc - possibility to write window function in PL languages
Date: 2020-08-26 15:06:22
Message-ID: CAFj8pRDXN66M7UHc__S7xQxboK6Lpobmv6XYZTkcLr2W-EY15A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

I simplified access to results of winfuncargs functions by proxy type
"typedvalue". This type can hold any Datum value, and allows fast cast to
basic buildin types or it can use (slower) generic cast functions. It is
used in cooperation with a plpgsql assign statement that can choose the
correct cast implicitly. When the winfuncarg function returns a value of
the same type, that is expected by the variable on the left side of the
assign statement, then (for basic types), the value is just copied without
casts. With this proxy type is not necessary to have special statement for
assigning returned value from winfuncargs functions, so source code of
window function in plpgsql looks intuitive to me.

Example - implementation of "lag" function in plpgsql

create or replace function pl_lag(numeric)
returns numeric as $$
declare v numeric;
begin
v := get_input_value_in_partition(windowobject, 1, -1, 'seek_current',
false);
return v;
end;
$$ language plpgsql window;

I think this code is usable, and I assign this patch to commitfest.

Regards

Pavel

Attachment Content-Type Size
plpgsql-window-function-support.patch text/x-patch 58.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2020-08-26 15:41:17 Re: LWLockAcquire and LockBuffer mode argument
Previous Message Peter Eisentraut 2020-08-26 14:33:20 Re: renaming configure.in to configure.ac