create table like including storage parameter
Thread notes
1 note#feature#moderate#enhancement
hackorum-bot#feature#moderate#enhancement
@global #feature #moderate #enhancement
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.
Attachments:
v1-0001-create-table-like-incluing-storage-parameter.patchtext/x-patch; charset=US-ASCII; name=v1-0001-create-table-like-incluing-storage-parameter.patchDownload+200-2
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.
On Mon, Sep 29, 2025 at 9:28 AM David G. Johnston
<david.g.johnston@gmail.com> wrote:
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.
“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.
Attachments:
v2-0001-create-table-like-incluing-storage-parameter.patchapplication/x-patch; name=v2-0001-create-table-like-incluing-storage-parameter.patchDownload+200-2
On Wed, Oct 1, 2025 at 2:42 PM jian he <jian.universality@gmail.com> 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.
+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.
Attachments:
v3-0001-create-table-like-incluing-storage-parameter.patchtext/x-patch; charset=US-ASCII; name=v3-0001-create-table-like-incluing-storage-parameter.patchDownload+200-2
On Sun, Sep 28, 2025 at 08:28:45PM -0500, David G. Johnston wrote:
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.
+1
--
nathan
On Sat, Oct 25, 2025 at 1:48 AM Nathan Bossart <nathandbossart@gmail.com> wrote:
On Sun, Sep 28, 2025 at 08:28:45PM -0500, David G. Johnston wrote:
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.+1
--
nathan
hi.
attached patch using syntax:
CREATE TABLE LIKE INCLUDING PARAMETERS.
Attachments:
v4-0001-create-table-like-incluing-parameters.patchtext/x-patch; charset=US-ASCII; name=v4-0001-create-table-like-incluing-parameters.patchDownload+199-3
On Thu, Oct 30, 2025 at 9:57 AM jian he <jian.universality@gmail.com> wrote:
attached patch using syntax:
CREATE TABLE LIKE INCLUDING PARAMETERS.
hi.
rebased, with minor comment polishing.
Attachments:
v5-0001-create-table-like-incluing-parameters.patchtext/x-patch; charset=US-ASCII; name=v5-0001-create-table-like-incluing-parameters.patchDownload+213-3
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]https://codesearch.debian.net/search?q=untransformRelOptions&literal=1[2]https://github.com/search?q=untransformRelOptions&type=code, 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/
Attachments:
v6-0001-create-table-like-incluing-parameters.patchtext/x-patch; name="=?UTF-8?Q?v6-0001-create-table-like-incluing-parameters.patch?="Download+213-3
v6-0002-fixup-create-table-like-incluing-parameters.patchtext/x-patch; name="=?UTF-8?Q?v6-0002-fixup-create-table-like-incluing-parameters.patch?="Download+60-101
On Tue, Dec 16, 2025 at 1:52 AM Euler Taveira <euler@eulerto.com> 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 <jian.universality@gmail.com>
Reviewed-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: David G. Johnston <david.g.johnston@gmail.com>
(delete this line later) commitfest:
https://commitfest.postgresql.org/patch/6088
discussion: /messages/by-id/CACJufxHr=nKEsS66M7rTHgB+mXdQ948=_eJ1jztAc7PT-eJefA@mail.gmail.com
----------------------------------
Attachments:
v7-0001-Add-INCLUDING-PARAMETERS-to-CREATE-TABLE-LIKE.patchtext/x-patch; charset=US-ASCII; name=v7-0001-Add-INCLUDING-PARAMETERS-to-CREATE-TABLE-LIKE.patchDownload+201-8
Hi,
current, v7 the DOC changes:
+ <varlistentry id="sql-createtable-parms-like-opt-storage-paramter">
+ <term><literal>INCLUDING PARAMETERS</literal></term>
+ <listitem>
+ <para>
+ All table parameters, such as the <literal>storage
parameter</literal>
+ settings of the source table, will be copied. For table storage
+ parameters, see <xref linkend="sql-createtable-storage-parameters"/>
+ below for more information.
+ </para>
+ </listitem>
+ </varlistentry>
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?
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/
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.
Attachments:
v8-0001-Add-INCLUDING-PARAMETERS-to-CREATE-TABLE-LIKE.patchtext/x-patch; charset=US-ASCII; name=v8-0001-Add-INCLUDING-PARAMETERS-to-CREATE-TABLE-LIKE.patchDownload+218-8
Hi.
Because of https://cfbot.cputube.org/patch_6088.log
A trivial rebase is attached.
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:
Show quoted text
Hi.
Because of https://cfbot.cputube.org/patch_6088.log
A trivial rebase is attached.
On Tue, Apr 28, 2026 at 3:24 PM lakshmi <lakshmigcdac@gmail.com> 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.
On Tue, Sep 29, 2026 at 9:01 AM jian he <jian.universality@gmail.com> wrote:
On Tue, Apr 28, 2026 at 3:24 PM lakshmi <lakshmigcdac@gmail.com> 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
On Tue, Oct 6, 2026 at 3:52 PM Fujii Masao <masao.fujii@gmail.com> 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.