Skip to content

A little confused about horizontal filtering and type casting #1650

Discussion options

You must be logged in to vote

@benjamin-thomas Hey there,

unknown casting lets pg infer the type based on the context.

In the SELECT 'true'::unknown = true case, the right operand is a boolean so the left operand is converted to the same type. Then true = true is true.

The date inputs like now, today, yesterday are special in pg. They're documented here: https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-TABLE.

So you can do:

select 'tomorrow'::timestamp;
2020-11-17 00:00:00

select 'yesterday'::timestamp;
2020-11-15 00:00:00

curl 'localhost:4444/todos?due_on=lt.now()'

pg parsing can look crazy here, but in fact it ignores certain special chars:

select ')()()()()tomorrow()()()('::

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by wolfgangwalther
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1650 on December 28, 2020 19:20.