pksunkara / pgx_ulid

Postgres extension for ulid
MIT License
289 stars 18 forks source link

Problems with joins in PG 16 #45

Open kydemy-fran opened 1 month ago

kydemy-fran commented 1 month ago

We have installed the extension in a schema called utils:

CREATE SCHEMA utils;
CREATE EXTENSION ULID SCHEMA utils;

The function utils.gen_monotonic_ulid() works fine.

If I run the following query in postgresql 16.1:

SELECT CAST('01HTHV582X9B5YBFP7GRBWXRHX' AS utils.ulid) = CAST('01HTHV582X9B5YBFP7GRBWXRHX' AS utils.ulid)

Same result if we do:

SELECT utils.gen_monotonic_ulid() = utils.gen_monotonic_ulid();

I am getting the following error:

[2024-05-22 16:28:51] [42725] ERROR: operator is not unique: utils.ulid = utils.ulid [2024-05-22 16:28:51] Hint: Could not choose a best candidate operator. You might need to add explicit type casts.

I have checked and I have the = operator defined in the DB for ulid types:

SELECT
    n.nspname,
    o.oprname,
    o.oprleft,
    o.oprright,
    o.oprresult,
    p.proname
FROM
    pg_operator o
        JOIN
    pg_namespace n ON o.oprnamespace = n.oid
        JOIN
    pg_proc p ON o.oprcode = p.oid
WHERE
    n.nspname = 'utils' AND oprname = '=';
Returns: nspname oprname oprleft oprright oprresult proname
utils = 1403350 1403350 16 ulid_eq
utils = 1403766 1403766 16 geometry_eq
utils = 1404472 1404472 16 geography_eq

We are having that same error I reported when joining tables by ULID ids.

Thank you!

kydemy-fran commented 1 month ago

We have been able to circumvent this issue by casting to TExT, but other views / operators / functions that use operators fail.

For instance:

SELECT NULLIF(utils.gen_monotonic_ulid(),utils.gen_monotonic_ulid());