Skip to content

Commit 1f77a73

Browse files
committed
fix(postgres): avoid regex backrefs for cross-engine cast parsing
1 parent db887c5 commit 1f77a73

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

models/Grammars/PostgresGrammar.cfc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,13 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
342342
var defaultValue = column.getDefaultValue();
343343
// Normalize PostgreSQL cast shorthand (value::TYPE) so runtimes that
344344
// parse ":" for named params don't break schema DDL execution.
345-
if ( reFindNoCase( "(.+)::([a-zA-Z_][a-zA-Z0-9_\\[\\]\\.\\s]*)$", defaultValue ) ) {
346-
defaultValue = reReplaceNoCase(
347-
defaultValue,
348-
"^(.+)::([a-zA-Z_][a-zA-Z0-9_\\[\\]\\.\\s]*)$",
349-
"CAST(\\1 AS \\2)"
350-
);
345+
var castMatch = reFindNoCase( "::([a-zA-Z_][a-zA-Z0-9_\\[\\]\\.\\s]*)$", defaultValue, 1, true );
346+
if ( castMatch.pos[ 1 ] > 0 ) {
347+
var castPosition = castMatch.pos[ 1 ];
348+
var castLength = castMatch.len[ 1 ];
349+
var valuePart = left( defaultValue, castPosition - 1 );
350+
var typePart = right( defaultValue, castLength - 2 );
351+
defaultValue = "CAST(#valuePart# AS #typePart#)";
351352
}
352353

353354
switch ( column.getType() ) {

0 commit comments

Comments
 (0)