Search code examples
postgresqlhstorepostgresql-9.3

Postgres 9.3, hstore 1.1, unknown operator '?'


I have a log table that collects table changes using hstore. Something similar to:

CREATE TABLE "gt_wells"."log_edits" (
      "well_gid"    SERIAL
    , "modified_by" TEXT
    , "edit"        HSTORE
);

where "edit" is the difference between a record's previous and new values. It all works as expected.

I want to select rows where a specific column was edited, so using my login role with superuser privileges I can successfully run:

SELECT DISTINCT "well_gid"
FROM "gt_wells"."log_edits"
WHERE "edit" ? 'full_sized_class;

But when I run it from another role I get an unknown operator error:

SET ROLE "inl-trigger";
SELECT DISTINCT "well_gid"
FROM "gt_wells"."log_edits"
WHERE "edit" ? 'full_sized_class' AND "modified_by" != 'inl-trigger';
RESET ROLE;

Error : ERROR:  operator does not exist: public.hstore ? unknown
LINE 3: WHERE "edit" ? 'full_sized_class' AND "modified_by" != 'inl-...
                     ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

Casting 'full_sized_class' to TEXT doesn't help. hstore extension exists in the db and I've given "inl-trigger" privileges to the hstore type:

CREATE EXTENSION hstore;
Error : ERROR:  extension "hstore" already exists

GRANT ALL ON TYPE hstore TO "inl-trigger";
Affected rows : 0, Time: 0.00sec

If I make "inl-trigger" a superuser, everything works as expected. So what privileges am I missing? Why can't "inl-trigger" use hstore operators?


Solution

  • Needed usage on the schema hstore was installed to:

    GRANT USAGE ON SCHEMA public TO "inl-trigger";