@@ -198,7 +198,7 @@ func (og *operationGenerator) randOp(
198
198
// We can only ignore this error, if no other PgErrors
199
199
// were set in the clean up process.
200
200
if errors .Is (err , pgx .ErrNoRows ) &&
201
- ! errors .Is (err , & pgconn.PgError {}) {
201
+ ! errors .HasType (err , & pgconn.PgError {}) {
202
202
continue
203
203
}
204
204
// Table select had a primary key swap, so no statement
@@ -3878,11 +3878,18 @@ func (og *operationGenerator) createFunction(ctx context.Context, tx pgx.Tx) (*o
3878
3878
COALESCE(member->>'direction' = 'REMOVE', false) AS dropping
3879
3879
FROM enum_members
3880
3880
` )
3881
+ schemasQuery := With ([]CTE {
3882
+ {"descriptors" , descJSONQuery },
3883
+ }, `SELECT quote_ident(name) FROM descriptors WHERE descriptor ? 'schema'` )
3881
3884
3882
3885
enums , err := Collect (ctx , og , tx , pgx .RowToMap , enumQuery )
3883
3886
if err != nil {
3884
3887
return nil , err
3885
3888
}
3889
+ schemas , err := Collect (ctx , og , tx , pgx .RowTo [string ], schemasQuery )
3890
+ if err != nil {
3891
+ return nil , err
3892
+ }
3886
3893
3887
3894
// Roll some variables to ensure we have variance in the types of references
3888
3895
// that we aside from being bound by what we could make references to.
@@ -3916,6 +3923,9 @@ func (og *operationGenerator) createFunction(ctx context.Context, tx pgx.Tx) (*o
3916
3923
name := tree .Name (fmt .Sprintf ("udf_%s" , og .newUniqueSeqNumSuffix ()))
3917
3924
return & name
3918
3925
},
3926
+ "Schema" : func () (string , error ) {
3927
+ return PickOne (og .params .rng , schemas )
3928
+ },
3919
3929
"DroppingEnum" : func () (string , error ) {
3920
3930
return PickOne (og .params .rng , droppingEnums )
3921
3931
},
@@ -3947,9 +3957,9 @@ func (og *operationGenerator) createFunction(ctx context.Context, tx pgx.Tx) (*o
3947
3957
// to the schema workload but may become a nice to have.
3948
3958
stmt , expectedCode , err := Generate [* tree.CreateRoutine ](og .params .rng , og .produceError (), []GenerationCase {
3949
3959
// 1. Nothing special, fully self contained function.
3950
- {pgcode .SuccessfulCompletion , `CREATE FUNCTION { UniqueName } (i int, j int) RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$` },
3960
+ {pgcode .SuccessfulCompletion , `CREATE FUNCTION { Schema } . { UniqueName } (i int, j int) RETURNS VOID LANGUAGE SQL AS $$ SELECT NULL $$` },
3951
3961
// 2. 1 or more table or type references spread across parameters, return types, or the function body.
3952
- {pgcode .SuccessfulCompletion , `CREATE FUNCTION { UniqueName } ({ ParamRefs }) RETURNS { ReturnRefs } LANGUAGE SQL AS $$ SELECT NULL WHERE { BodyRefs } $$` },
3962
+ {pgcode .SuccessfulCompletion , `CREATE FUNCTION { Schema } . { UniqueName } ({ ParamRefs }) RETURNS { ReturnRefs } LANGUAGE SQL AS $$ SELECT NULL WHERE { BodyRefs } $$` },
3953
3963
// 3. Reference a table that does not exist.
3954
3964
{pgcode .UndefinedTable , `CREATE FUNCTION { UniqueName } () RETURNS VOID LANGUAGE SQL AS $$ SELECT * FROM "ThisTableDoesNotExist" $$` },
3955
3965
// 4. Reference a UDT that does not exist.
@@ -4092,7 +4102,19 @@ func (og *operationGenerator) alterFunctionSetSchema(
4092
4102
functionsQuery := With ([]CTE {
4093
4103
{"descriptors" , descJSONQuery },
4094
4104
{"functions" , functionDescsQuery },
4095
- }, `SELECT quote_ident(schema_id::REGNAMESPACE::TEXT) || '.' || quote_ident(name) FROM functions` )
4105
+ }, `SELECT
4106
+ quote_ident(schema_id::REGNAMESPACE::TEXT) || '.' || quote_ident(name) || '(' || array_to_string(funcargs, ', ') || ')'
4107
+ FROM functions
4108
+ JOIN LATERAL (
4109
+ SELECT
4110
+ COALESCE(array_agg(quote_ident(typnamespace::REGNAMESPACE::TEXT) || '.' || quote_ident(typname)), '{}') AS funcargs
4111
+ FROM pg_catalog.pg_type
4112
+ JOIN LATERAL (
4113
+ SELECT unnest(proargtypes) AS oid FROM pg_catalog.pg_proc WHERE oid = (id + 100000)
4114
+ ) args ON args.oid = pg_type.oid
4115
+ ) funcargs ON TRUE
4116
+ ` ,
4117
+ )
4096
4118
4097
4119
schemasQuery := With ([]CTE {
4098
4120
{"descriptors" , descJSONQuery },
0 commit comments