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

Rails/ActiveRecord/Postgres #3

Open
kornate opened this issue Aug 16, 2023 · 1 comment
Open

Rails/ActiveRecord/Postgres #3

kornate opened this issue Aug 16, 2023 · 1 comment

Comments

@kornate
Copy link

kornate commented Aug 16, 2023

Has anyone managed to get typeid-sql working with rails/activerecord/postgres?

Despite hours and hours of trying, I cannot get past this error:

PG::UndefinedFunction: ERROR:  operator is only a shell: character varying = typeid
LINE 1: ...rnal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT...
@divaltor
Copy link

I've met the same issue

Try to remove COMMUTATOR from operator overloading

CREATE OR REPLACE FUNCTION compare_type_id_equality(lhs_id typeid, rhs_id VARCHAR)
    RETURNS BOOLEAN AS $$
SELECT lhs_id = typeid_parse(rhs_id);
$$ LANGUAGE SQL IMMUTABLE;


CREATE OPERATOR = (
    LEFTARG = typeid,
    RIGHTARG = varchar,
    FUNCTION = compare_type_id_equality,
    NEGATOR = !=,
    HASHES,
    MERGES
);

When you provide COMMUTATOR parameter - PostgreSQL creates 2 operators for = - (typeid, varchar) and (varchar, typeid) and when on left side you have varchar value PostgreSQL try to execute function for validating typeid on right side even if you have no typeid type there

With COMMUTATOR
image

Without COMMUTATOR
image

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

No branches or pull requests

2 participants