From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Paul Jungwirth <pj(at)illuminatedcomputing(dot)com> |
Cc: | Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: SQL:2011 application time |
Date: | 2023-11-17 07:12:30 |
Message-ID: | CACJufxEchOxLEBgzUy4otMpEgvk_55LWeDXz4J6+PsbkzyBqDA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
based on v17.
begin;
drop table if exists s1;
CREATE TABLE s1 (id numrange, misc int, misc1 text);
create role test101 login;
grant update, select on s1 to test101;
insert into s1 VALUES ('[1,1000]',2);
set session authorization test101;
update s1 set id = '[1,1000]';
savepoint sp1;
update s1 FOR PORTION OF id from 10 to 100 set misc1 = 'test';
table s1;
savepoint sp2;
insert into s1 VALUES ('[2,1000]',12);
rollback;
In UPDATE FOR PORTION OF from x to y, if range [x,y) overlaps with the
"source" range
then the UPDATE action would be UPDATE and INSERT.
The above UPDATE FOR PORTION OF query should fail?
UPDATE FOR PORTION OF, may need insert privilege. We also need to document this.
Similarly, we also need to apply the above logic to DELETE FOR PORTION OF.
-------------------------------------------------------
+ <para>
+ If the table has a <link
linkend="ddl-periods-application-periods">range column
+ or <literal>PERIOD</literal></link>, you may supply a
should be
+ <para>
+ If the table has a range column or <link
linkend="ddl-periods-application-periods">
+ <literal>PERIOD</literal></link>, you may supply a
similarly the doc/src/sgml/ref/delete.sgml the link reference also broken.
--------------------------------------------------------
<para>
If the table has a range column or <link
linkend="ddl-periods-application-periods">
<literal>PERIOD</literal></link>, you may supply a
<literal>FOR PORTION OF</literal> clause, and your update will only
affect rows
that overlap the given interval. Furthermore, if a row's span extends outside
the <literal>FOR PORTION OF</literal> bounds, then it will be
truncated to fit
within the bounds, and new rows spanning the "cut off" duration will be
inserted to preserve the old values.
</para>
"given interval", "cut off" these words, imho, feel not so clear.
We also need a document that:
"UPDATE FOR PORTION OF" is UPDATE and INSERT (if overlaps).
If the "UPDATE FOR PORTION OF" range overlaps then
It will invoke triggers in the following order: before row update,
before row insert, after row insert. after row update.
---------------------------------------
src/test/regress/sql/for_portion_of.sql
You only need to create two triggers?
since for_portion_of_trigger only raises notice to output the triggers
meta info.
CREATE TRIGGER trg_for_portion_of_before
BEFORE INSERT OR UPDATE OR DELETE ON for_portion_of_test
FOR EACH ROW
EXECUTE FUNCTION for_portion_of_trigger();
CREATE TRIGGER trg_for_portion_of_after
AFTER INSERT OR UPDATE OR DELETE ON for_portion_of_test
FOR EACH ROW
EXECUTE FUNCTION for_portion_of_trigger();
From | Date | Subject | |
---|---|---|---|
Next Message | jian he | 2023-11-17 07:27:22 | Re: remaining sql/json patches |
Previous Message | Richard Guo | 2023-11-17 06:41:12 | Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500 |