Skip to content

Commit e919d78

Browse files
authored
Merge pull request #2324 from dolthub/jennifer/type
resolve type in CREATE FUNCTION with empty search path
2 parents a65f4ab + 4ddb697 commit e919d78

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

postgres/parser/types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ var familyNames = map[Family]string{
12561256
BytesFamily: "bytes",
12571257
CollatedStringFamily: "collatedstring",
12581258
DateFamily: "date",
1259-
DecimalFamily: "decimal",
1259+
DecimalFamily: "numeric",
12601260
EnumFamily: "enum",
12611261
FloatFamily: "float",
12621262
GeographyFamily: "geography",

server/analyzer/resolve_type.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,14 @@ func resolveType(ctx *sql.Context, typ *pgtypes.DoltgresType) (*pgtypes.Doltgres
175175
if typ.IsResolvedType() {
176176
return typ, nil
177177
}
178-
schema, err := core.GetSchemaName(ctx, nil, typ.ID.SchemaName())
179-
if err != nil {
180-
return nil, err
181-
}
182178
typs, err := core.GetTypesCollectionFromContext(ctx)
183179
if err != nil {
184180
return nil, err
185181
}
186-
resolvedTyp, err := typs.GetType(ctx, id.NewType(schema, typ.ID.TypeName()))
187-
if err != nil {
188-
return nil, err
189-
}
182+
183+
// schema name can be empty
184+
schema, _ := core.GetSchemaName(ctx, nil, typ.ID.SchemaName())
185+
resolvedTyp, _ := typs.GetType(ctx, id.NewType(schema, typ.ID.TypeName()))
190186
if resolvedTyp == nil {
191187
// If a blank schema is provided, then we'll also try the pg_catalog, since a type is most likely to be there
192188
if typ.ID.SchemaName() == "" {

testing/go/create_function_plpgsql_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,5 +1376,48 @@ END;
13761376
},
13771377
},
13781378
},
1379+
{
1380+
Name: "resolve type with empty search path",
1381+
SetUpScript: []string{
1382+
"set search_path to ''",
1383+
`CREATE TABLE public.ambienttempdetail (tempdetailid integer NOT NULL, panelprojectid integer, threshold_value numeric(10,2), readingintervalinmin integer);`,
1384+
`insert into public.ambienttempdetail values (1, 101, 25.5, 15);`,
1385+
},
1386+
Assertions: []ScriptTestAssertion{
1387+
{
1388+
Query: `CREATE FUNCTION public.ambienttempdetail_insertupdate(p_panel_project_id integer, p_threshold_value numeric, p_reading_interval_in_min integer) RETURNS integer
1389+
LANGUAGE plpgsql
1390+
AS $$
1391+
DECLARE
1392+
v_rtn_value INTEGER;
1393+
BEGIN
1394+
IF NOT EXISTS (SELECT * FROM AmbientTempDetail WHERE PanelProjectId = p_panel_project_id) THEN
1395+
INSERT INTO AmbientTempDetail (PanelProjectId, Threshold_Value, ReadingIntervalInMin)
1396+
VALUES (p_panel_project_id, p_threshold_value, p_reading_interval_in_min)
1397+
RETURNING TempDetailId INTO v_rtn_value;
1398+
ELSE
1399+
UPDATE AmbientTempDetail
1400+
SET PanelProjectId = p_panel_project_id,
1401+
Threshold_Value = p_threshold_value,
1402+
ReadingIntervalInMin = p_reading_interval_in_min
1403+
WHERE PanelProjectId = p_panel_project_id;
1404+
v_rtn_value := p_panel_project_id;
1405+
END IF;
1406+
1407+
RETURN v_rtn_value;
1408+
END;
1409+
$$;`,
1410+
Expected: []sql.Row{},
1411+
},
1412+
{
1413+
Query: "set search_path to 'public'",
1414+
},
1415+
{
1416+
Skip: true,
1417+
Query: "SELECT public.ambienttempdetail_insertupdate(101, 25.5, 15);",
1418+
Expected: []sql.Row{{101}},
1419+
},
1420+
},
1421+
},
13791422
})
13801423
}

0 commit comments

Comments
 (0)