Skip to content

Commit 81c2461

Browse files
authored
Merge pull request #449 from diffix/piotr/fix-where-datetime-validation
Missed spot where primary_arg is nonzero
2 parents 1cab5d3 + 7a0d167 commit 81c2461

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/query/validation.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ static Var *get_bucket_expression_column_ref(Node *bucket_expression)
427427
return (Var *)bucket_expression;
428428
/* If the bucket expression is not a direct column reference, it means it is a simple function call. */
429429
FuncExpr *func_expr = castNode(FuncExpr, bucket_expression);
430-
return castNode(Var, unwrap_cast(linitial(func_expr->args)));
430+
431+
int primary_arg = primary_arg_index(func_expr->funcid);
432+
return castNode(Var, unwrap_cast(list_nth(func_expr->args, primary_arg)));
431433
}
432434

433435
static void verify_column_usage_in_filter(AccessLevel access_level, Node *bucket_expression, List *range_tables)

test/expected/datetime.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ SELECT tz, count(*) FROM test_datetime GROUP BY 1;
7878
2012-05-14 07:00:00+00 | 11
7979
(1 row)
8080

81+
-- Datetime filtering
82+
SELECT count(*) FROM test_datetime WHERE date_trunc('year', ts) = '2012-01-01'::timestamp;
83+
count
84+
-------
85+
11
86+
(1 row)
87+

test/sql/datetime.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ SET pg_diffix.session_access_level = 'direct';
5353
UPDATE test_datetime SET tz = '2012-05-14T08:00+01:00' WHERE true;
5454
SET pg_diffix.session_access_level = 'anonymized_trusted';
5555
SELECT tz, count(*) FROM test_datetime GROUP BY 1;
56+
57+
-- Datetime filtering
58+
SELECT count(*) FROM test_datetime WHERE date_trunc('year', ts) = '2012-01-01'::timestamp;

0 commit comments

Comments
 (0)