timescale icon indicating copy to clipboard operation
timescale copied to clipboard

Discussion: Should we support positional arguments for optional arguments?

Open davydog187 opened this issue 3 years ago • 2 comments

For functions like time_bucket, optional arguments can be passed as named arguments, but they can be passed positionally.

Should we support both? CC: @akoutmos

SELECT time_bucket('5 minutes', time, '-2.5 minutes'::INTERVAL) + '2.5 minutes'
  AS five_min, avg(cpu)
FROM metrics
GROUP BY five_min
ORDER BY five_min DESC LIMIT 10;

davydog187 avatar Aug 27 '22 14:08 davydog187

We can definitely do that. Those functions can be simple passthroughs to the named argument versions so that we can lean on the same types of validations/type castings in the queries. We'll need to make sure that all of our arguments (both required and optional) align in terms of ordering and name in the documentation so that there is no confusion for library users what positional arguments are.

For example, I think for the time bucket one functions, I made the column name the first arg, but it is actually the second arg in the TimescaleDB function. Same with the first and last functions. The argument names differ from the TimescaleDB docs and we will want to be more consistent.

akoutmos avatar Aug 27 '22 16:08 akoutmos

Very good point @akoutmos, completely agree with that path

davydog187 avatar Aug 27 '22 18:08 davydog187