Skip to content

Commit 41cc6e6

Browse files
committed
resolve type with empty search path
1 parent cfe10a0 commit 41cc6e6

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

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
@@ -160,18 +160,14 @@ func resolveType(ctx *sql.Context, typ *pgtypes.DoltgresType) (*pgtypes.Doltgres
160160
if typ.IsResolvedType() {
161161
return typ, nil
162162
}
163-
schema, err := core.GetSchemaName(ctx, nil, typ.ID.SchemaName())
164-
if err != nil {
165-
return nil, err
166-
}
167163
typs, err := core.GetTypesCollectionFromContext(ctx)
168164
if err != nil {
169165
return nil, err
170166
}
171-
resolvedTyp, err := typs.GetType(ctx, id.NewType(schema, typ.ID.TypeName()))
172-
if err != nil {
173-
return nil, err
174-
}
167+
168+
// schema name can be empty
169+
schema, _ := core.GetSchemaName(ctx, nil, typ.ID.SchemaName())
170+
resolvedTyp, _ := typs.GetType(ctx, id.NewType(schema, typ.ID.TypeName()))
175171
if resolvedTyp == nil {
176172
// If a blank schema is provided, then we'll also try the pg_catalog, since a type is most likely to be there
177173
if typ.ID.SchemaName() == "" {

testing/go/create_function_plpgsql_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,5 +1376,38 @@ END;
13761376
},
13771377
},
13781378
},
1379+
{
1380+
Name: "resolve type with empty search path",
1381+
SetUpScript: []string{
1382+
"set search_path to ''",
1383+
},
1384+
Assertions: []ScriptTestAssertion{
1385+
{
1386+
Query: `CREATE FUNCTION public.ambienttempdetail_insertupdate(p_panel_project_id integer, p_threshold_value numeric, p_reading_interval_in_min integer) RETURNS integer
1387+
LANGUAGE plpgsql
1388+
AS $$
1389+
DECLARE
1390+
v_rtn_value INTEGER;
1391+
BEGIN
1392+
IF NOT EXISTS (SELECT * FROM AmbientTempDetail WHERE PanelProjectId = p_panel_project_id) THEN
1393+
INSERT INTO AmbientTempDetail (PanelProjectId, Threshold_Value, ReadingIntervalInMin)
1394+
VALUES (p_panel_project_id, p_threshold_value, p_reading_interval_in_min)
1395+
RETURNING TempDetailId INTO v_rtn_value;
1396+
ELSE
1397+
UPDATE AmbientTempDetail
1398+
SET PanelProjectId = p_panel_project_id,
1399+
Threshold_Value = p_threshold_value,
1400+
ReadingIntervalInMin = p_reading_interval_in_min
1401+
WHERE PanelProjectId = p_panel_project_id;
1402+
v_rtn_value := p_panel_project_id;
1403+
END IF;
1404+
1405+
RETURN v_rtn_value;
1406+
END;
1407+
$$;`,
1408+
Expected: []sql.Row{},
1409+
},
1410+
},
1411+
},
13791412
})
13801413
}

0 commit comments

Comments
 (0)