Re: clone_schema function - Mailing list pgsql-general

From David G. Johnston
Subject Re: clone_schema function
Date
Msg-id CAKFQuwbRhjPpHR7QrdjNL6d2iNg58zEVKUkSRFNH1um8GAyimQ@mail.gmail.com
Whole thread Raw
In response to Re: clone_schema function  (Melvin Davidson <melvin6925@gmail.com>)
Responses Re: clone_schema function
List pgsql-general
On Fri, Sep 11, 2015 at 4:23 PM, Melvin Davidson <melvin6925@gmail.com> wrote:
"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.

     SELECT replace(qry, source_schema, dest_schema) INTO dest_qry;

Or maybe you can at least mitigate the potential problem a bit by changing this to read:

replace(qry, source_schema || '.', dest_schema || '.') INTO dest_qry; ...

Posting code for public consumption involves accepting constructive criticism and even if the example is contrived I'm doubting the possibility of collision is as close to zero as you think it may be or as close as it could be with a simple re-evaluation of what constraints as imposed on a particular sequence of characters being interpreted as a schema.  You do still end up with a possible false-positive when you have a (column.composite).composite_field expression.

Regular expressions could maybe help here since the leading character is limited too...but less so then the trailing character.

David J.


pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Re: clone_schema function
Next
From: Melvin Davidson
Date:
Subject: Re: clone_schema function