Re: clone_schema function - Mailing list pgsql-general

From Igor Neyman
Subject Re: clone_schema function
Date
Msg-id A76B25F2823E954C9E45E32FA49D70ECCD5158B2@mail.corp.perceptron.com
Whole thread Raw
In response to Re: clone_schema function  (Melvin Davidson <melvin6925@gmail.com>)
List pgsql-general

 

 

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Melvin Davidson
Sent: Friday, September 11, 2015 4:24 PM
To: Daniel Verite <daniel@manitou-mail.org>
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] clone_schema function

 

"seriously flawed" is a bit of a stretch. Most sane developers would not have schema names of one letter.

They usually name a schema something practical, which totally avoids your nit picky exception.

However, if you are that concerned about the "serious flaw", you have the option of using the method

of dumping the schema, editing the dump and reloading. Or, I invite you to use your great skills and

write a better method.

 

On Fri, Sep 11, 2015 at 4:06 PM, Daniel Verite <daniel@manitou-mail.org> wrote:

        Melvin Davidson wrote:

> I've added error checking and verified that it now copies the
> current sequnce values, table data, views and functions.

The code dealing with functions is seriously flawed.

Consider that part:
     SELECT pg_get_functiondef(func_oid) INTO qry;
     SELECT replace(qry, source_schema, dest_schema) INTO dest_qry;
     EXECUTE dest_qry;

It suggests that to duplicate a function in schema A to B,
every letter A in the entire function definition should be replaced
by B, garbling everything along the way.
For example CREATE FUNCTION would become CREBTE FUNCTION,
DECLARE would become DECLBRE and so on.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite


____________________________________________________

 

It does not have to be one-letter schema name.

Consider the following:

 

Schema called “vector” has a table called “vector_config” referenced in some function.

Now, what happens if schema “vector” is copied into some destination schema using your script?

 

Melvin, you needn’t consider every critique of your script to be a personal attack on you.

 

Regards,

Igor Neyman

 

 

pgsql-general by date:

Previous
From: Charles Lynch
Date:
Subject: BDR problem
Next
From: "Daniel Verite"
Date:
Subject: Re: clone_schema function