typeid-sql icon indicating copy to clipboard operation
typeid-sql copied to clipboard

Rails/ActiveRecord/Postgres

Open kornate opened this issue 2 years ago • 1 comments

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...

kornate avatar Aug 16 '23 09:08 kornate

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

divaltor avatar Aug 22 '23 08:08 divaltor