From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
---|---|
To: | jian he <jian(dot)universality(at)gmail(dot)com> |
Cc: | Feike Steenbergen <feikesteenbergen(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: pg18: Virtual generated columns are not (yet) safe when superuser selects from them |
Date: | 2025-06-23 13:13:40 |
Message-ID: | 3a0e2ba3-98aa-4a15-9fbd-d44937f2a07e@eisentraut.org |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 21.06.25 16:45, jian he wrote:
>> CREATE TABLE gtest1 (a int42 GENERATED ALWAYS AS ('1') VIRTUAL);
>> CREATE TABLE gtest2 (a int42 GENERATED ALWAYS AS ('1'::int42) VIRTUAL);
>> ERROR: generation expression uses user-defined type
>> LINE 1: CREATE TABLE gtest2 (a int42 GENERATED ALWAYS AS ('1'::int42...
>> ^
>> DETAIL: Virtual generated columns that make use of user-defined types
>> are not yet supported.
>>
>> Do we need error out for the first case?
>>
>
> I think these two cases both should error out.
>
> If generated column expressions do not allow user-defined types or functions, it
> makes sense to also disallow virtual generated columns from using user-defined
> types.
> Attached patch change CheckAttributeType to do the job.
> related tests also added.
>
> Note: Support for composite types in virtual generated columns is
> currently partial.
> for example:
>
> CREATE TYPE double_int as (a int, b int);
> --ok
> CREATE TABLE gtest4 (
> a int,
> b double_int GENERATED ALWAYS AS ((a * 2, a * 3)) VIRTUAL
> );
> --not ok.
> CREATE TABLE gtest4 (
> a int,
> b double_int GENERATED ALWAYS AS ((a * 2, a * 3)::double_int) VIRTUAL
> );
Your CheckAttributeType() change is conditional on TYPTYPE_BASE, but if
you remove that and check it for all types, then you get the right error
in both cases.
I have attached a patch that is similar to yours but with that change.
I've also written the test cases a bit differently, but it also covers
everything now.
(The two patches should be squashed. I'm just keeping them separate to
show what is changed.)
Attachment | Content-Type | Size |
---|---|---|
v2-0001-Restrict-virtual-columns-to-use-built-in-function.patch | text/plain | 14.2 KB |
v2-0002-Disallow-user-defined-type-for-virtual-generated-.patch | text/plain | 4.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Damien Clochard | 2025-06-23 13:18:43 | Re: Security Label Inheritance |
Previous Message | James Pang | 2025-06-23 12:28:21 | Re: pgv18: simple table scan take more time than pgv14 |