Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpwardPathQuery and DownwardPathQuery result in error due to default casting #10

Open
JackAtOmenApps opened this issue Sep 15, 2021 · 1 comment
Assignees

Comments

@JackAtOmenApps
Copy link
Collaborator

When performing path queries, the path is cast as bigint while the array of ids is cast as integer

Example query explain from our codebase:

WITH RECURSIVE traverse(parent_id, child_id, depth, PATH) AS
    (SELECT first.parent_id,
            first.child_id,
            1 AS depth, ARRAY[first.parent_id] AS PATH
     FROM flow_networks_networkedge AS FIRST
     WHERE parent_id = 4269
     UNION ALL SELECT first.parent_id,
                      first.child_id,
                      second.depth + 1 AS depth,
                      PATH || first.parent_id AS PATH
     FROM flow_networks_networkedge AS FIRST,
          traverse AS SECOND
     WHERE first.parent_id = second.child_id
         AND (first.parent_id <> ALL(second.path)) )
SELECT UNNEST(ARRAY[pkid]) AS pkid
FROM
    (SELECT PATH || ARRAY[4215], depth
     FROM traverse
     WHERE child_id = 4215
         AND depth <= 20
     LIMIT 1) AS x(pkid);

Result:

ERROR:  operator does not exist: bigint[] || integer[]
LINE 17:     (SELECT PATH || ARRAY[4215], depth
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 657
@JackAtOmenApps JackAtOmenApps self-assigned this Sep 15, 2021
@JackAtOmenApps
Copy link
Collaborator Author

JackAtOmenApps commented Sep 15, 2021

This is due to new Django versions allowing a default auto field of various types. In the past it was only an AutoField (::integer), but now the user can set it as a BigAutoField (::bigint), or UUIDField (::uuid).

https://docs.djangoproject.com/en/3.2/topics/db/models/#automatic-primary-key-fields

Additionally, the pkid type may be set manually per-model. Need to be able to account for this in the query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant