diff --git a/src/query/validation.c b/src/query/validation.c index 82942523..7b5baf22 100644 --- a/src/query/validation.c +++ b/src/query/validation.c @@ -427,7 +427,9 @@ static Var *get_bucket_expression_column_ref(Node *bucket_expression) return (Var *)bucket_expression; /* If the bucket expression is not a direct column reference, it means it is a simple function call. */ FuncExpr *func_expr = castNode(FuncExpr, bucket_expression); - return castNode(Var, unwrap_cast(linitial(func_expr->args))); + + int primary_arg = primary_arg_index(func_expr->funcid); + return castNode(Var, unwrap_cast(list_nth(func_expr->args, primary_arg))); } static void verify_column_usage_in_filter(AccessLevel access_level, Node *bucket_expression, List *range_tables) diff --git a/test/expected/datetime.out b/test/expected/datetime.out index c03829a5..99bb8d0f 100644 --- a/test/expected/datetime.out +++ b/test/expected/datetime.out @@ -78,3 +78,10 @@ SELECT tz, count(*) FROM test_datetime GROUP BY 1; 2012-05-14 07:00:00+00 | 11 (1 row) +-- Datetime filtering +SELECT count(*) FROM test_datetime WHERE date_trunc('year', ts) = '2012-01-01'::timestamp; + count +------- + 11 +(1 row) + diff --git a/test/sql/datetime.sql b/test/sql/datetime.sql index ff714cf7..01482b86 100755 --- a/test/sql/datetime.sql +++ b/test/sql/datetime.sql @@ -53,3 +53,6 @@ SET pg_diffix.session_access_level = 'direct'; UPDATE test_datetime SET tz = '2012-05-14T08:00+01:00' WHERE true; SET pg_diffix.session_access_level = 'anonymized_trusted'; SELECT tz, count(*) FROM test_datetime GROUP BY 1; + +-- Datetime filtering +SELECT count(*) FROM test_datetime WHERE date_trunc('year', ts) = '2012-01-01'::timestamp;