Skip to content

Commit

Permalink
Merge pull request #449 from diffix/piotr/fix-where-datetime-validation
Browse files Browse the repository at this point in the history
Missed spot where primary_arg is nonzero
  • Loading branch information
pdobacz committed Sep 12, 2022
2 parents 1cab5d3 + 7a0d167 commit 81c2461
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/query/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/expected/datetime.out
Original file line number Diff line number Diff line change
Expand Up @@ -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)

3 changes: 3 additions & 0 deletions test/sql/datetime.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 81c2461

Please sign in to comment.