Add CREATE SCHEMA ... LIKE support

From: "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com>
To: <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Add CREATE SCHEMA ... LIKE support
Date: 2026-02-06 14:22:46
Message-ID: DG7Y34A6VBEG.76L7K1OML5DI@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers

I was reading the TODO wiki page and found the "Add CREATE SCHEMA ...
LIKE that copies a schema" item and I thought that it could be a good
idea to have this at core.

It's common for certain applications to have a different schema for each
customer and having a built-in way to copy an entire schema could be
useful for this use case.

I'd like to propose the introduction of the LIKE syntax on CREATE SCHEMA
command with the following syntax:
  CREATE SCHEMA <name> LIKE <source_schema> [like_options...]

Where like_options is:
  { INCLUDING | EXCLUDING } { TABLE | INDEX | ... | ALL }

The idea of LIKE syntax is to create a new schema with all objects that
exist on source schema like tables, indexes, sequences, functions,
views, etc.

I'm attaching a PoC patch that implements the LIKE syntax for tables and
indexes. I would like to start a discussion to see if this feature make
sense and if it could be useful to have at core. I have intention to add
support for more objects(sequence, functions, ...) in future patches if
It makes sense.

Thoughts?

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachment Content-Type Size
v1-0001-Add-CREATE-SCHEMA-.-LIKE-support.patch text/plain 18.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-02-06 14:35:09 Re: Add CREATE SCHEMA ... LIKE support
Previous Message Andrew Dunstan 2026-02-06 14:12:20 Re: [PING] fallocate() causes btrfs to never compress postgresql files