Skip to content

Commit 80c70ee

Browse files
committed
workload/schemachanger: fix invalid function syntax errors
Previously, the random schema changer workload used $$ as a delimiter for function definitions. Unfortunately, randomly generated strings used by functions could easily contain $$ causing the definition to terminator to show up. To address this patch modifies the delimiter to be $FUNC_BODY$. Fixes: #148555 Release note: None
1 parent 6d30ef4 commit 80c70ee

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/workload/schemachange/operation_generator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4400,15 +4400,15 @@ FROM
44004400
// 1. Nothing special, fully self contained function.
44014401
{pgcode.SuccessfulCompletion, `CREATE FUNCTION { Schema } . { UniqueName } (i int, j int) RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$`},
44024402
// 2. 1 or more table or type references spread across parameters, return types, or the function body.
4403-
{pgcode.SuccessfulCompletion, `CREATE FUNCTION { Schema } . { UniqueName } ({ ParamRefs }) RETURNS { ReturnRefs } LANGUAGE SQL AS $$ SELECT NULL WHERE { BodyRefs } $$`},
4403+
{pgcode.SuccessfulCompletion, `CREATE FUNCTION { Schema } . { UniqueName } ({ ParamRefs }) RETURNS { ReturnRefs } LANGUAGE SQL AS $FUNC_BODY$ SELECT NULL WHERE { BodyRefs } $FUNC_BODY$`},
44044404
// 3. Reference a table that does not exist.
44054405
{pgcode.UndefinedTable, `CREATE FUNCTION { UniqueName } () RETURNS VOID LANGUAGE SQL AS $$ SELECT * FROM "ThisTableDoesNotExist" $$`},
44064406
// 4. Reference a UDT that does not exist.
44074407
{pgcode.UndefinedObject, `CREATE FUNCTION { UniqueName } (IN p1 "ThisTypeDoesNotExist") RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$`},
44084408
// 5. Reference an Enum that's in the process of being dropped
44094409
{pgcode.UndefinedObject, `CREATE FUNCTION { UniqueName } (IN p1 { NonPublicEnum }) RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$`},
44104410
// 6. Reference an Enum value that's in the process of being dropped
4411-
{pgcode.InvalidParameterValue, `CREATE FUNCTION { UniqueName } () RETURNS VOID LANGUAGE SQL AS $$ SELECT { NonPublicEnumMember } $$`},
4411+
{pgcode.InvalidParameterValue, `CREATE FUNCTION { UniqueName } () RETURNS VOID LANGUAGE SQL AS $FUNC_BODY$ SELECT { NonPublicEnumMember } $FUNC_BODY$`},
44124412
}, placeholderMap)
44134413
if err != nil {
44144414
return nil, err
@@ -5342,7 +5342,7 @@ func (og *operationGenerator) createTrigger(ctx context.Context, tx pgx.Tx) (*op
53425342
return nil, err
53435343
}
53445344

5345-
triggerFunction := fmt.Sprintf(`CREATE FUNCTION %s() RETURNS TRIGGER AS $$ BEGIN %s;RETURN NULL;END; $$ LANGUAGE PLpgSQL`, triggerFunctionName, selectStmt.sql)
5345+
triggerFunction := fmt.Sprintf(`CREATE FUNCTION %s() RETURNS TRIGGER AS $FUNC_BODY$ BEGIN %s;RETURN NULL;END; $FUNC_BODY$ LANGUAGE PLpgSQL`, triggerFunctionName, selectStmt.sql)
53465346

53475347
og.LogMessage(fmt.Sprintf("Created trigger function %s", triggerFunction))
53485348

0 commit comments

Comments
 (0)