create table like including storage parameter

Поиск
Список
Период
Сортировка
Искать

create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
hi.

attached patch is to make CREATE TABLE LIKE copy source relation
storage parameter
demo:

create table t(a text) with (fillfactor = 100, toast.vacuum_truncate=true);
create table t2(like t including storage parameter) with (parallel_workers = 3);

                                          Table "public.t2"
 Column | Type | Collation | Nullable | Default | Storage  |
Compression | Stats target | Description
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
 a      | text |           |          |         | extended |
  |              |
Access method: heap
Options: parallel_workers=3, fillfactor=100, toast.vacuum_truncate=true

of course, duplicate storage mention would result error,
for example:
create table t3(like t including storage parameter) with (fillfactor = 100);

Since we already support INCLUDING STORAGE, I’m not sure that
INCLUDING STORAGE PARAMETER is the right syntax to go with.

Re: create table like including storage parameter

От:
"David G. Johnston" <david.g.johnston@gmail.com>
Дата:
On Sunday, September 28, 2025, jian he <jian.universality@gmail.com> wrote:
Since we already support INCLUDING STORAGE, I’m not sure that
INCLUDING STORAGE PARAMETER is the right syntax to go with.

I’d just call it “including parameters”; sure, all of the existing ones are storage related, but if there were non-storage ones we’d include those as well, so qualifying with a parameter type doesn’t seem correct.

David J.

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
On Mon, Sep 29, 2025 at 9:28 AM David G. Johnston
 wrote:
>
> On Sunday, September 28, 2025, jian he  wrote:
>>
>> Since we already support INCLUDING STORAGE, I’m not sure that
>> INCLUDING STORAGE PARAMETER is the right syntax to go with.
>
> I’d just call it “including parameters”; sure, all of the existing ones are storage related, but if there were non-storage ones we’d include those as well, so qualifying with a parameter type doesn’t seem correct.
>

“including parameters” would add another keyword "PARAMETERS''.
currently "INCLUDING STORAGE PARAMETER" no need to add a new keyword.
If other people favor “including parameters”, then we can do it that
way in the future.

attached is just a simple rebase of v1.

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
On Wed, Oct 1, 2025 at 2:42 PM jian he  wrote:
>
> “including parameters” would add another keyword "PARAMETERS''.
> currently "INCLUDING STORAGE PARAMETER" no need to add a new keyword.
> If other people favor “including parameters”, then we can do it that
> way in the future.
>
> attached is just a simple rebase of v1.

hi.
https://api.cirrus-ci.com/v1/artifact/task/5202996067303424/testrun/build/testrun/regress/regress/regression.diffs

+ERROR:  relation "t" already exists
I made the same mistake, regress test using a simple name like "t" will conflict
with other regress tests.

please check the attached, mainly regress tests changes.

Re: create table like including storage parameter

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Sun, Sep 28, 2025 at 08:28:45PM -0500, David G. Johnston wrote:
> On Sunday, September 28, 2025, jian he  wrote:
>> Since we already support INCLUDING STORAGE, I’m not sure that
>> INCLUDING STORAGE PARAMETER is the right syntax to go with.
> 
> I’d just call it “including parameters”; sure, all of the existing ones are
> storage related, but if there were non-storage ones we’d include those as
> well, so qualifying with a parameter type doesn’t seem correct.

+1

-- 
nathan


Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
On Sat, Oct 25, 2025 at 1:48 AM Nathan Bossart  wrote:
>
> On Sun, Sep 28, 2025 at 08:28:45PM -0500, David G. Johnston wrote:
> > On Sunday, September 28, 2025, jian he  wrote:
> >> Since we already support INCLUDING STORAGE, I’m not sure that
> >> INCLUDING STORAGE PARAMETER is the right syntax to go with.
> >
> > I’d just call it “including parameters”; sure, all of the existing ones are
> > storage related, but if there were non-storage ones we’d include those as
> > well, so qualifying with a parameter type doesn’t seem correct.
>
> +1
>
> --
> nathan

hi.

attached patch using syntax:
CREATE TABLE LIKE INCLUDING PARAMETERS.

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
On Thu, Oct 30, 2025 at 9:57 AM jian he  wrote:
>
> attached patch using syntax:
> CREATE TABLE LIKE INCLUDING PARAMETERS.

hi.
rebased, with minor comment polishing.


--
jian
https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
"Euler Taveira" <euler@eulerto.com>
Дата:
Вложения:
On Mon, Dec 15, 2025, at 5:48 AM, jian he wrote:
> rebased, with minor comment polishing.
>

I started reviewing this patch. Why don't you reuse untransformRelOptions()?
Even if this function is used by various extensions [1][2], that's not an
excuse to duplicate code. I adjusted the code in the fixup. I did a bunch of
stylish changes and fixed a few typos. I also ran pgindent. I removed some
superfluous comments ("Fetch heap tuple", "Get the toast reloptions",). Don't
think they are saying something important. Coverage looks good. As a homework,
add a nice commit message. Showing how it works is not a good commit message.

This v6 is your v5 plus my suggestions.

[1] https://codesearch.debian.net/search?q=untransformRelOptions&literal=1
[2] https://github.com/search?q=untransformRelOptions&type=code


-- 
Euler Taveira
EDB   https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
On Tue, Dec 16, 2025 at 1:52 AM Euler Taveira  wrote:
>
> I started reviewing this patch. Why don't you reuse untransformRelOptions()?
> Even if this function is used by various extensions [1][2], that's not an
> excuse to duplicate code.

yech, duplicate code is not good. I encountered the same issue in the CAST
DEFAULT patch.  I guess I was posting it in the "post early post often" spirit
for the rebase.

> This v6 is your v5 plus my suggestions.
>

your suggestions are great.
I have incorporated all the changes you proposed.

in transformTableLikeClause, we have:
    if (relation->rd_rel->relkind != RELKIND_RELATION &&
        relation->rd_rel->relkind != RELKIND_VIEW &&
        relation->rd_rel->relkind != RELKIND_MATVIEW &&
        relation->rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
        relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
        relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
        ereport(ERROR,
                (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                 errmsg("relation \"%s\" is invalid in LIKE clause",
                        RelationGetRelationName(relation)),
                 errdetail_relkind_not_supported(relation->rd_rel->relkind)));

except RELKIND_RELATION, RELKIND_MATVIEW can also specify storage parameters, I
added a test for it too.

to test CREATE FOREIGN LIKE will silently ignore INCLUDING PARAMETERS, i also
slightly modified create_table_like.sql.

The last SELECT query output is too wide, to make it more readable, I
have to use \gx.

Below is the commit message I have drafted:
----------------------------------
Add INCLUDING PARAMETERS to CREATE TABLE LIKE

Introduce the PARAMETERS option to copy parameters when using CREATE TABLE LIKE.
Currently, this primarily applies to the storage parameters, but in the future,
it may encompass other kind parameters in the table.

Since storage parameters are not in the standard, INCLUDING PARAMETERS does not
comply with the standard.  Also because foreign tables cannot specify storage
parameters, CREATE FOREIGN TABLE LIKE will silently ignore INCLUDING PARAMETERS.

This makes creating a new table via CREATE TABLE LIKE more convenient, as the
user would otherwise have to manually specify every storage parameter. It is a
further step toward making a new table created with CREATE TABLE LIKE more
identical to the original table.

Author: jian he 
Reviewed-by: Euler Taveira 
Reviewed-by: Nathan Bossart 
Reviewed-by: David G. Johnston 

(delete this line later) commitfest:
https://commitfest.postgresql.org/patch/6088
discussion: https://postgr.es/m/CACJufxHr=nKEsS66M7rTHgB+mXdQ948=_eJ1jztAc7PT-eJefA@mail.gmail.com
----------------------------------

--
jian
https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Hi,

current, v7 the DOC changes:
+       
+        INCLUDING PARAMETERS
+        
+         
+          All table parameters, such as the storage
parameter
+          settings of the source table, will be copied.  For table storage
+          parameters, see 
+          below for more information.
+         
+        
+       

https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-ATTRIBUTE-OPTION

Does the "parameter" (INCLUDING PARAMETERS) definition is close to "option"?
This raises the question of whether we should also copy column-level options to
the new table.

What do you think?

--
jian
https://www.enterprisedb.com


Re: create table like including storage parameter

От:
"Euler Taveira" <euler@eulerto.com>
Дата:
On Wed, Dec 17, 2025, at 3:41 AM, jian he wrote:
> Does the "parameter" (INCLUDING PARAMETERS) definition is close to "option"?
> This raises the question of whether we should also copy column-level options to
> the new table.
>

I don't think so. The current attribute options (n_distinct and
n_distinct_inherited) are closely tied to the data. I'm afraid that this
decision would impose bad plans in the future.


-- 
Euler Taveira
EDB   https://www.enterprisedb.com/


Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
transformTableLikeClause, we have:
```
    if (relation->rd_rel->relkind != RELKIND_RELATION &&
        relation->rd_rel->relkind != RELKIND_VIEW &&
        relation->rd_rel->relkind != RELKIND_MATVIEW &&
        relation->rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
        relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
        relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
        ereport(ERROR,
                (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                 errmsg("relation \"%s\" is invalid in LIKE clause",
                        RelationGetRelationName(relation)),
                 errdetail_relkind_not_supported(relation->rd_rel->relkind)));
```
RELKIND_COMPOSITE_TYPE, RELKIND_FOREIGN_TABLE,
RELKIND_PARTITIONED_TABLE cann't/don't have storage parameters.

https://www.postgresql.org/docs/current/sql-creatematerializedview.html says
"All parameters supported for CREATE TABLE are also supported for
CREATE MATERIALIZED VIEW"

However for RELKIND_VIEW:
CREATE TABLE t_sp (a text) WITH (toast_tuple_target = 128);
CREATE VIEW v1 with (check_option=local) as select a from t_sp;
CREATE TABLE t_sp1 (LIKE v1 INCLUDING PARAMETERS);
ERROR:  unrecognized parameter "check_option"

INCLUDING PARAMETERS: basically copy source pg_class.reloptions and
use it for the target table.
RELKIND_VIEW pg_class.reloptions is different from RELKIND_RELATION,
Therefore INCLUDING PARAMETERS should not be applied when the source
relation is RELKIND_VIEW.


--
jian
https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
Hi.

Because of https://cfbot.cputube.org/patch_6088.log
A trivial rebase is attached.


--
jian
https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
Dapeng Wang <wangdp20191008@gmail.com>
Дата:
Hi,

I pulled the v9 patch and gave it a spin on 19devel.

Everything I tried worked fine - basic parameter copying,
merging with WITH clause, duplicate detection, EXCLUDING,
and the VIEW/materialized view cases all behaved correctly.

make check passed too (one unrelated ICU collation diff
in collate.icu.utf8).

Looks good to me.

Regards,
Dapeng Wang

Re: create table like including storage parameter

От:
Dapeng Wang <wangdp20191008@gmail.com>
Дата:
Hi,

I pulled the v9 patch and gave it a spin on 19devel.

Everything I tried worked fine - basic parameter copying,
merging with WITH clause, duplicate detection, EXCLUDING,
and the VIEW/materialized view cases all behaved correctly.

make check passed too (one unrelated ICU collation diff
in collate.icu.utf8).

Looks good to me.

Regards,
Dapeng Wang

Re: create table like including storage parameter

От:
lakshmi <lakshmigcdac@gmail.com>
Дата:

Hi all,

I tested the patch on current HEAD.

INCLUDING PARAMETERS works as expected. It correctly copies storage parameters. Duplicate parameters raise an error, and existing LIKE behavior remains unchanged.

When used with a VIEW, parameters are ignored (since they are not valid for tables), and the command completes without error.

Overall, the feature looks good from my testing. It might be worth documenting the behavior for VIEWs.

Regards,
Lakshmi G


On Tue, Apr 28, 2026 at 12:49 PM jian he <jian.universality@gmail.com> wrote:
Hi.

Because of https://cfbot.cputube.org/patch_6088.log
A trivial rebase is attached.


--
jian
https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
Вложения:
On Tue, Apr 28, 2026 at 3:24 PM lakshmi  wrote:
>
> Hi all,
>
> I tested the patch on current HEAD.
>
> INCLUDING PARAMETERS works as expected. It correctly copies storage parameters. Duplicate parameters raise an error, and existing LIKE behavior remains unchanged.
>
> When used with a VIEW, parameters are ignored (since they are not valid for tables), and the command completes without error.
>
> Overall, the feature looks good from my testing. It might be worth documenting the behavior for VIEWs.
>

CREATE TABLE t (a int) WITH (fillfactor = 70);
CREATE TABLE p (LIKE t INCLUDING ALL) PARTITION BY LIST (a);
ERROR:  42809: cannot specify storage parameters for a partitioned table
HINT:  Specify storage parameters for its leaf partitions instead.
LOCATION:  partitioned_table_reloptions, reloptions.c:2350

The abvove ERROR seems not necessary.
So I made the CREATE TABLE (...) PARTITION BY ignore the PARAMETERS option.



--
jian
https://www.enterprisedb.com/

Re: create table like including storage parameter

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Tue, Sep 29, 2026 at 9:01 AM jian he  wrote:
>
> On Tue, Apr 28, 2026 at 3:24 PM lakshmi  wrote:
> >
> > Hi all,
> >
> > I tested the patch on current HEAD.
> >
> > INCLUDING PARAMETERS works as expected. It correctly copies storage parameters. Duplicate parameters raise an error, and existing LIKE behavior remains unchanged.

So, if two source tables both set fillfactor, wouldn't

    CREATE TABLE ... (LIKE t1 INCLUDING ALL, LIKE t2 INCLUDING ALL)

fail with this patch even though it succeeds today? I'm concerned that this
could be a backward compatibility issue.

Regards,

-- 
Fujii Masao


Re: create table like including storage parameter

От:
jian he <jian.universality@gmail.com>
Дата:
On Tue, Oct 6, 2026 at 3:52 PM Fujii Masao  wrote:
>
> So, if two source tables both set fillfactor, wouldn't
>
>     CREATE TABLE ... (LIKE t1 INCLUDING ALL, LIKE t2 INCLUDING ALL)
>
> fail with this patch even though it succeeds today? I'm concerned that this
> could be a backward compatibility issue.
>

Hi.

CREATE TABLE LIKE is not guaranteed to be error-free.
For example, the following will fail:

create table t(a int);
create table t1(a int);
CREATE TABLE t2 (LIKE t INCLUDING ALL, LIKE t1 INCLUDING ALL);

I think this failure is not different from the fillfactor one: certain
conditions have to be met, otherwise CREATE TABLE ... LIKE fails.


FAQ