Skip to content

Indexing for query on data->>'created_at' #28

Description

@FranckPachot

For the following query (PostgresSwitch4):

SELECT data
            FROM github.pulls
            WHERE (to_timestamp((data->>'created_at')::text, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') >= NOW() - INTERVAL '3 months')
            LIMIT 10;

Why is it cast from text to timestamp and then back to text?
The problem is that this function is not immutable and cannot be indexed.

With the followingquery, an index on github.pulls ((data->>'created_at') asc) could be used

SELECT data
            FROM github.pulls
            WHERE data->>'created_at' >= to_char(NOW() - INTERVAL '3 months','YYYY-MM-DD"T"HH24:MI:SS"Z"')
            LIMIT 10;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions