Re: Add CREATE SCHEMA ... LIKE support

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Matheus Alcantara <matheusssilv97(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Subject: Re: Add CREATE SCHEMA ... LIKE support
Date: 2026-02-09 20:53:17
Message-ID: CAB-JLwasr3Eaky5RkTB9h-J2q61-fuuGF8=SBiS9SJN_gHux0A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em seg., 9 de fev. de 2026 às 14:42, Matheus Alcantara <
matheusssilv97(at)gmail(dot)com> escreveu:

> So here is V2 with some documentation changes and also with the index
> name not being preserved issue that Marcos have mentioned earlier fixed.

You followed INCLUDING and EXCLUDING as CREATE TABLE LIKE does, but the
problem is that on command CREATE TABLE LIKE if you EXCLUDE any of
available options, which are: COMMENTS | COMPRESSION | CONSTRAINTS |
DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE, the table
will be created anyway, because none of them are obligatory
Now you are creating several objects and some of them are dependent, what
do you do if a table depends on a TYPE or a DOMAIN but they were not
included on the options list ? And more, a different TYPE or DOMAIN with
that name exists but on another schema that is in the search_path ?
I think only CREATE TABLE LIKE like you did will not work as expected.
Imagine something like this.

set search_path to public;
create domain i32 integer check (value > 0);
create schema a;
create table a.t1(id i32);
--create schema like should get an exception because a table cannot be
created without the domains it depends.
create schema b like a excluding domain;
--then a second problem
set search_path to a;
--create a second domain but same name. table a continues using public.i32.
create domain i32 integer check (value = 1);
--now we have two different domains, which on will be used ?
--create schema like would get an error because domain was not found on
search_path or would create a table using a wrong object ?
create schema b like a including all;

regards
Marcos

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-02-09 20:58:21 Re: pg_upgrade: transfer pg_largeobject_metadata's files when possible
Previous Message Tom Lane 2026-02-09 20:16:56 Re: Subquery pull-up increases jointree search space