Skip to content

SQL functions: Detect parameter type mismatches (error 42883) #432

Open
@Donnerstagnacht

Description

@Donnerstagnacht

Bug report

  • [x ] I confirm this is a bug with Supabase, not with my own application.
  • [ x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

If a user defines an sql function, that takes in function parameters and these function parameters are used as query operators (for example where clauses), the PLS does not detect type mismatches in operator comparisons and postgres throws an error 42883.

-- Incorrect code (PLS should mark this as an error)
-- type input incorrect
create function test_error_42883_operator_type_mismatch(user_id int) returns users_hidden.users  language sql as
$$
select * from users_hidden.users u where u.id = user_id;
$$;

-- corect code
create function test_input_parameter_as_query(user_id uuid) returns users_hidden.users  language sql as
$$
select * from users_hidden.users u where u.id = user_id;
$$;

To Reproduce

  1. Declare a table with DDL
  2. Create a sql function taking in an incorrect typed parameter that is
  3. Use the parameter as an operator (for example a where clause)

I guess there are type mismatches possible for other operators and input parameter usages.

Expected behavior

The postgres language server should detect the type mismatch once the parameters are used as operators and mark the operator usage as invalid (code), e.g. extensions like the vs code extensions should indicate the type mismatch error with a squiggly line and a helpful type error message.

From a DX perspective, I would love it if the error message could include a hint that the type mismatch includes a function parameter and therefore the user should double check the function input parameter types.

System information

  • OS: windows AMD
  • PLS: 0.8.1 with vs-code extension
  • postgres supabase

PS: Do you consider this a bug or a feature request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions