Skip to content

Issues found on page 'CREATE MACRO Statement' #7011

Description

@rpbouman

Suggesting some points of improvement:

  1. Today (not sure since what version exacctly), parameters may be typed. But this is rather under-documented. It is mentioned once and very superficially in the examples of the Scalar Macros section: https://duckdb.org/docs/current/sql/statements/create_macro#scalar-macros
Image
  1. I believe the parameter syntax in the the syntax diagram is wrong:
Image
  • the param-name and param-name := default-value appear as if in a required succession, while they really should be alternatives
  • there is no mention of the optional type declaration for the parameter
  • the current diagram suggests the parameter list plus the AS-clause can be repeteated. This repetition should apply to the parameter declarations
  1. The default value feature is also under documented:
Image
  • it should mention that parameters declarations with defaults cannot be declared before parameter declarations without defaults.
  1. There ought to be something that explains assigning values to named parameters when calling the macro. In particular, it should explicitly explain the assignment operator :=. This is the only correct way to assign values to macro parameters, while built-in functions with named parameters may also support plain '='. This can be a real gotcha, especially when passing parameters from one macro to the next, because an expression like a = a is still valid - it's just that it evaluates to TRUE rather than assigning the value of the a parameter from the outer macro to the a parameter of the macro being called. For example:
create macro m1(arg1 boolean := false) as 
(select arg1);

create macro m2(arg1) as 
(select m1(arg1 = arg1));

select macro m2(false); 
-- result is TRUE because in the definition of m2, 
-- the result of comparing the argument with itself (arg1 = arg1 ) is passed into m1
-- rather than assigning the value of m2's arg1 to m1's arg1

Page URL: https://duckdb.org/docs/current/sql/statements/create_macro.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions