crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Computed column function optional arguments are not accounted for when values are passed

Open Tam opened this issue 1 year ago • 1 comments

Summary

Optional function arguments on computed columns are not accounted for when values are passed to the function. This means if you skip an optional parameter, the next parameter is passed in it's place and will be wrong.

Steps to reproduce

The function below accepts two ints and one float.

create function public.image_src (
  image public.image
, width int = null
, height int = null
, aspect float = null
) returns varchar as $$ ... $$ language plpgsql immutable;

When called from GraphQL the generated SQL looks like this:

{
  src (width: 100, aspect: 1)
}
public.image_src(
  __image__
, __image_identifiers__."id1"
, __image_identifiers__."id2"
);

The last argument is in the wrong place and will error, in this case: ERROR: function public.image_src(image, integer, double precision) does not exist.

Possible Solution

Use named parameters when calling computed functions with parameters, so:

public.image_src(
  __image__
, width => __image_identifiers__."id1"
, aspect => __image_identifiers__."id2"
);

Tam avatar Oct 18 '24 16:10 Tam

Hmmm; that's weird, it should be using named parameters.

benjie avatar Oct 18 '24 16:10 benjie