Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:04:55+00:00 2026-06-09T22:04:55+00:00

I was using postgresql version 8.2.22, then I upgraded to postgresql 9.1.3 and the

  • 0

I was using postgresql version 8.2.22, then I upgraded to postgresql 9.1.3 and the upgrade was successfully completed.

But now some casts are not working the same as before!

In Postgres 8.2.22

I run these two queries and they both work correctly:

POSTGRES8222=# select TO_NUMBER('12345678',9999999999.99);

to_number
=========   
 12345678
(1 row)

POSTGRES8222=# select a ||'$'|| b from test;
 ?column?
----------
 1$abcdef
 2$ghijkl
 3$3456
(3 rows)

After upgrade to Postgres 9.1.3

I run the same queries and now they throw errors:

select TO_NUMBER('12345678',9999999999.99);

ERROR:  function to_number(unknown, numeric) does not exist
LINE 1: select TO_NUMBER('12345678',9999999999.99);
               ^
HINT:  No function matches the given name and argument types. You might 
need to add explicit type casts.

EXCEPTION
org.postgresql.util.PSQLException: ERROR: function to_number(numeric, numeric) 
does not exist

Hint: No function matches the given name and argument types. You might need 
to add explicit type casts.

Position: 150



select a ||'$'|| b from test;
ERROR:  operator is not unique: numeric || unknown
LINE 1: select a ||'$'|| b from test;
                 ^
HINT:  Could not choose a best candidate operator. You might need to 
add explicit type casts.

********** Error **********
ERROR: operator is not unique: numeric || unknown
SQL state: 42725
Hint: Could not choose a best candidate operator. You might need to  
add explicit type casts.
Character: 10

Why is it that casting in postgresql is not working as it did before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:04:57+00:00Added an answer on June 9, 2026 at 10:04 pm

    Beginning with PostgreSQL 8.3 there are fewer automatic casts. This was changed for two reasons:

    1. Many new high-powered types were being introduced, and automatic casting prevented these from being able to use literals in a way that “first-class” types could. Narrowing the cases where the parser tried to guess a data type allowed new types that a user could plug in to be used in a more natural way.

    2. Numerous bug reports turned out to be people accidentally getting the “benefit” of automatic casting when they didn’t recognize that it was happening, making it hard to find their application coding errors. After 8.3 was released, there were roughly the same number of people posting to say that the change uncovered hidden bugs in their own code as there were people complaining that their code now needed casts where it previously didn’t.

    It appears that you tried to “solve” this “problem” by adding implicit typecasts. This is a minefield; I don’t recommend it. You will limit what features you can safely use and you will have no end of quirky little bugs that nobody else does, and nobody can easily help you with. It is better to fix your code not to assume so many implicit conversions.

    One thing which may be confusing you is that in PostgreSQL, '1.2' is not a string literal. It is a literal of unknown type:

    test=# select pg_typeof('1.2');
     pg_typeof 
    -----------
     unknown
    (1 row)
    

    PostgreSQL holds off on resolving the type of a literal as long as it can, which works great with all those new data types I was describing. As a last resort, if the time comes when it has to resolve the type and there are no other clues, it treats it as type text.

    test=# select pg_typeof(case when true then '1.2' else null end);
     pg_typeof 
    -----------
     text
    (1 row)
    
    test=# select pg_typeof(case when true then '1.2' else 2.3 end);
     pg_typeof 
    -----------
     numeric
    (1 row)
    

    Problem 2, “aftertypecast”, is failing because with all the implicit type casts you added, there is more than one possible operator || which could be chosen depending on which implicit typecasts it performed, and there was no principled way to choose among them. If you change that line to the following, it should work again:

    select a || '$'::text || b from test;
    

    I’m arguing it would be cleaner and safer not to add those implicit casts and change the first problem code from:

    select TO_NUMBER('12345678',9999999999.99);
    

    to:

    select TO_NUMBER('12345678', '9999999999.99');
    

    After all, that second parameter is a format string, not a number. You can’t omit the quoting if you want to do something like:

    test=# select to_number('12,454.8-', '99G999D9S');
     to_number 
    -----------
      -12454.8
    (1 row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running a local postgresql server in version 9.1 and using the postgresql-9.1-901.jdbc4.jar
I am using pgAdmin version 1.14.3. PostgreSQL database version is 9.1. I got all
I'm using the standard (as opposed to NonRel) version of Django connected to PostgreSQL
I am using PostgreSQL version 9.1 and looking at the Postgres docs , I
I'm using PostgreSQL 8.1.11. And I'm losing my mind. Why can I not use
I've got two PostgreSQL databases that have been created using the same sql file.
I can't get Hibernate working with java.util.UUID for PostgreSQL. Here is the mapping using
Using the EclipseLink JPA2 implementation (not sure if it's the same with the Hibernate
I've installed PostgreSQL using MacPorts on a couple of different computers, no problem, but
I using PostgreSQL and I want to create a function in pl/perl, but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.