1

My database has implicit cast from integer to text, so I'm getting some 'operator is not unique' issues. I'm trying to delete the operator || (text, anynonarray) with no success, the error message is

ERROR: cannot drop operator ||(text,anynonarray) because it is required by the database system SQL state: 2BP01

I have another database that doesn't have this operator, so I think is possible somehow. I cannot add explicit casts in hundreds of queries, neither remove the implicit casts. There's a way to force the remotion of this operator?

6
  • 2BP01 means it has dependent objects, Did you try it with cascade in your drop command? postgresql.org/docs/9.1/interactive/sql-dropoperator.html Be careful with cascades it might drop more then you want so make a backup first.
    – Eelke
    Apr 26, 2012 at 16:43
  • DROP OPERATOR ||(anynonarray, text) CASCADE; the error continues. Apr 26, 2012 at 16:51
  • 1
    It's a system operator i.e. you can't drop it. Apr 26, 2012 at 17:11
  • But there's another database here and it doesn't have these operators! Apr 26, 2012 at 17:15
  • What are the PostgreSQL versions involved?
    – kgrittn
    Apr 26, 2012 at 18:02

1 Answer 1

0

Seems I got it. The trick is to delete right from the pg_operator table.

delete from pg_operator where oprname = '||' and (oprleft = 25 or oprleft = 2776 ) and oprleft != oprright

Because I wanted to delete these operators:

OPERATOR ||("text", anynonarray);

OPERATOR ||(anynonarray, "text");

I don't know if there are any implications though, seems ok till now.

2
  • 1
    You are deleting operators from the basic Postgres system: textanycat and anytextcat. Expressions of the form 'a'::text || '1'::int or '1'::int || 'a'::text that would normally evaluate to the text a1 / 1a will produce an error. An extension or client or any SQL code may be assuming these operators and fail unexpectedly. In short: Don't try this at home! Jun 27, 2012 at 23:26
  • select 'a'::text || '1'::int and the other didn't produce error though Jun 28, 2012 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.