Thread: Problem with numeric and operators

Problem with numeric and operators

From
DaVinci
Date:
 Hi all.

 I have a problem with data type 'numeric'. If I have a field of type
 'numeric' (in this case 'foo') and execute next query:

     select * from table_example where foo > 2.45

 I get error:

     ERROR:  Unable to identify an operator '>' for types 'numeric' and 'float8'
    You will have to retype this query using an explicit cast

 What is the meaning of this? Is it a bug? What am I doing wrong?...

 Thanks.

                 David

Re: Problem with numeric and operators

From
"Oliver Elphick"
Date:
DaVinci wrote:
  > Hi all.
  >
  > I have a problem with data type 'numeric'. If I have a field of type
  > 'numeric' (in this case 'foo') and execute next query:
  >
  >     select * from table_example where foo > 2.45
  >
  > I get error:
  >
  >     ERROR:  Unable to identify an operator '>' for types 'numeric' and 'flo
      >at8'
  >    You will have to retype this query using an explicit cast
  >
  > What is the meaning of this? Is it a bug? What am I doing wrong?...

There is not yet an automatic type conversion for such cases.

Add an explicit cast to your query:

  select * from table_example where foo > CAST (2.45 AS NUMERIC(12,2))


--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "If any of you lack wisdom, let him ask of God, who
      gives to all men generously and without reproach, and
      it will be given to him."           James 1:5