1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# name: test/sql/catalog/function/test_macro_default_arg.test
# group: [function]
statement ok
set storage_compatibility_version='v0.10.2'
statement ok
pragma enable_verification;
statement ok
CREATE MACRO f(x := NULL) AS x+1;
query I
SELECT f();
----
NULL
query I
SELECT f(x := 41)
----
42
query I
SELECT f(x := (SELECT 41));
----
42
query I
select f(x:=(select 1 a));
----
2
query I
select f(x:=a) from (select 41) t(a);
----
42
statement ok
create table t as select 41 a;
query I
select f(x:=a) from t;
----
42
statement error
create macro my_macro1(a, b := a) as a + b;
----
Binder Error: Default value for parameter 'b' cannot contain column names
statement ok
create table integers (a integer);
# this used to be allowed but is no longer (and for good reason)
statement error
create macro my_macro2(a := i) as (
select min(a) from integers
)
----
Binder Error: Default value for parameter 'a' cannot contain column names
statement ok
drop table integers;
statement ok
Create table t1 (a int, b int);
statement ok
Create table t2 (c int, d int);
statement ok
CREATE OR REPLACE MACRO eq(x := NULL, y := NULL) AS x = y
statement ok
INSERT INTO t1 VALUES (1, 1), (1, 2), (2, 2), (3, 4);
statement ok
INSERT INTO t2 VALUES (4, 1), (2, 10), (6, 2), (2, 6);
statement ok
SELECT * FROM t1 as t1_alias inner join (select * from t2) as t2_alias ON (eq(x := t1_alias.a, y := t2_alias.c))
# no default parameters with incorrect names
statement error
SELECT * FROM t1 as t1_alias inner join (select * from t2) as t2_alias ON (eq(a := t1_alias.a, c := t2_alias.c))
----
Binder Error
|