Re: operator does not exist - Mailing list pgsql-admin

From Dimitri Fontaine
Subject Re: operator does not exist
Date
Msg-id 87d3z0wu26.fsf@hi-media-techno.com
Whole thread Raw
In response to operator does not exist  (Julius Tuskenis <julius@nsoft.lt>)
Responses Re: operator does not exist
List pgsql-admin
Julius Tuskenis <julius@nsoft.lt> writes:

> select '1' = 1 results in true

This is a undecorated literal, which PostgreSQL will cast as integer
when it discovers that's what makes sense.

> while select sum(msg_price) from messages where msg_itemid = 0 results in
> error:
> ERROR:  operator does not exist: character varying = integer
> LINE 1: select sum(msg_price) from messages where msg_itemid = 0

Here, msg_itemid is known to be a varchar, and 0 is a numeric literal,
which is in the range of an integer, so the type is resolved as an
integer. Now the = operator does not exist for varchar, integer.

> I will add the operator ant then we'll fix the queries, but is the first
> example ok? Should it not raise error ?

Not as written. Try to decorate the literal to force PostgreSQL into
considering it of the type you have in mind:

  SELECT text '1' = 1;

Or even do a cast, this way:

  SELECT '1'::text = 1;

Regards,
--
dim

pgsql-admin by date:

Previous
From: Julius Tuskenis
Date:
Subject: operator does not exist
Next
From: Julius Tuskenis
Date:
Subject: Re: operator does not exist