Re: Add CREATE SCHEMA ... LIKE support - Mailing list pgsql-hackers

From Jim Jones
Subject Re: Add CREATE SCHEMA ... LIKE support
Date
Msg-id 1a298a0b-7181-4baf-b4e4-83cba1157f65@uni-muenster.de
Whole thread Raw
In response to Re: Add CREATE SCHEMA ... LIKE support  (Jim Jones <jim.jones@uni-muenster.de>)
List pgsql-hackers

On 10/02/2026 11:09, Jim Jones wrote:

> In a scenario where a parent table and the partitioned tables live in
> different schemas, creating a schema based on the schema that contains
> only the partitions arguably generates useless tables.

> The same applies for creating schema that contains only the parent table

> Even if parent and children live in the same schema, they become
> detached in the new copy -- I'd argue that this one is a bug.

> Comments are also being ignored, but I guess it was already mentioned
> upthread:


I also just noticed that UNLOGGED tables are cloned as normal tables:

postgres=# CREATE SCHEMA s1;
CREATE UNLOGGED TABLE s1.t(c int);
CREATE SCHEMA s2 LIKE s1 INCLUDING ALL;
CREATE SCHEMA
CREATE TABLE
CREATE SCHEMA

postgres=# \d s1.t
               Unlogged table "s1.t"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 c      | integer |           |          |

postgres=# \d s2.t
                   Table "s2.t"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 c      | integer |           |          |


Adding this to collectSchemaTablesLike in schemacmds.c could do the trick:

newRelation->relpersistence = classForm->relpersistence;


Best, Jim



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: jsonb subscripting vs SQL/JSON array accessor semantics (SQL:2023)
Next
From: Marcos Pegoraro
Date:
Subject: Re: Add CREATE SCHEMA ... LIKE support