Skip to content

int lists dumped as numeric[] regardless of their content [was: ANY not working] #293

@daxpryce

Description

@daxpryce

I'm trying to make use of the SELECT * FROM foo WHERE id = ANY(%s) syntax and my query execution never seems to return.

An example query:

import os
import psycopg

with psycopg.connect(os.environ["PGSQL_CONN"]) as conn:
    with conn.cursor() as cursor:
        results = conn.execute("SELECT id, url, vector FROM point WHERE id = ANY(%s)", [[1, 2, 3, 4]])

Executing that, it doesn't seem to return

However, the following DOES work:

import os
import psycopg

with psycopg.connect(os.environ["PGSQL_CONN"]) as conn:
    with conn.cursor() as cursor:
        results = conn.execute("SELECT id, url, vector FROM point WHERE id = ANY('{1, 2, 3, 4}')")

It comes back nearly instantly too.

If I EXPLAIN the first query, the cursor returns:

[('Gather  (cost=1000.00..36531388.10 rows=3511110 width=1367)',),
 ('  Workers Planned: 2',),
 ('  ->  Parallel Seq Scan on point  (cost=0.00..36179277.10 rows=1462962 width=1367)',),
 ("        Filter: ((id)::numeric = ANY ('{1,2,3,4}'::numeric[]))",),
 ('JIT:',),
 ('  Functions: 2',),
 ('  Options: Inlining true, Optimization true, Expressions true, Deforming true',)]

If I EXPLAIN the working query, the cursor returns:

[('Index Scan using points_pkey1 on point  (cost=0.57..22.35 rows=4 width=1367)',),
 ("  Index Cond: (id = ANY ('{1,2,3,4}'::integer[]))",)]

I don't know enough to know for sure that any of that is helpful, but I thought it was worth reporting just in case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions