Thread: Upgrading from 7.1.2 to 7.3.3 - function may need to add explicit typecasts

Upgrading from 7.1.2 to 7.3.3 - function may need to add explicit typecasts

From
Stuart Woodward
Date:
I have just reinstalled a database which has been working fine on
version 7.1.2 to 7.3.3 does anyone have any idea where and what typecast
I need to apply to get this test code work again?

--------------
1. The exception that I am getting is as follows:

java.sql.SQLException: ERROR:  Function calcprice(numeric, integer, numeric) does not exist
        Unable to identify a function that satisfies the given argument types
        You may need to add explicit typecasts
----------------------------------
2. The code that is being called is as follows:

String sql = "select calcPrice(?,?,?) ";
PreparedStatement st = getCon().prepareStatement(sql);
st.setDouble(1, listPrice);
st.setInt(2, type);
st.setDouble(3, amount);
rs = st.executeQuery();

----------------------------------
3. The SQL used to creat the function is as follows:

CREATE FUNCTION calcprice (float8, smallint, float8)
RETURNS float8 AS
SELECT float8larger(0, CASE
WHEN $2 = 1 THEN $1 - $3
WHEN $2 = 2 THEN $1 *(1 - $3)
ELSE $3
END )'
LANGUAGE 'sql'
----------------
4. From psql the function looks like this

test=> \df calcprice
                                  List of functions
 Result data type | Schema |   Name    |             Argument data types
------------------+--------+-----------+----------------------------------------------
 double precision | public | calcprice | double precision, smallint, double precision
(1 row)



Stuart Woodward <woodward@garage.co.jp> writes:
> java.sql.SQLException: ERROR:  Function calcprice(numeric, integer, numeric) does not exist

> CREATE FUNCTION calcprice (float8, smallint, float8)

There's no implicit coercion from integer to smallint in 7.3.  I'd
suggest changing the function's declared argument type to integer.

            regards, tom lane