Coder Social home page Coder Social logo

Comments (10)

davecramer avatar davecramer commented on June 28, 2024 1

but why does not jdbcPG do something similar ?

I mean, when we create the PreparedStatement, all the ? types are defined in the ParameterMetaData. Moreover the data that is uses in the BigDecimal is BigDecimal#getValue() returning a double. so :

  • The bytes array is the same between a double and a BigDecimal
  • We have the info of the parameter type in the metadata

what are the limitation to not do so ?

Because it requires a query to do so.

public ParameterMetaData getParameterMetaData() throws SQLException {

from pgjdbc.

davecramer avatar davecramer commented on June 28, 2024

If I remember correctly 06abfb7 only effects simple query mode which if you are using PreparedStatements this will not be the case.

from pgjdbc.

vlsi avatar vlsi commented on June 28, 2024

Unfortunately, that is the way PostgreSQL works.
If you have a numeric column, you need to use setBigDecimal for it. If you use setDouble + numeric column, you will have a performance issue.

There's no way driver could do about it, and if it worked previously, it was a pure luck 🤷‍♂️

from pgjdbc.

CharlesLgn avatar CharlesLgn commented on June 28, 2024

Are you requesting SimpleQuery mode when executing this ?

In fact I am not. so as I understand, and as @vlsi said in the issue post :

There's no way driver could do about it, and if it worked previously, it was a pure luck 🤷‍♂️

Sorry to have created a PR for no reason 😓

from pgjdbc.

davecramer avatar davecramer commented on June 28, 2024

Just for your elucidation if you are not requesting SimpleQuery mode then we would be using Extended Protocol and the code you were referring to would not be used

without SimpleQuery mode this is what is executed

2024-06-17 05:55:31.341 EDT [13722] LOG:  duration: 0.210 ms parse <unnamed>: SELECT $1 * 2
2024-06-17 05:55:31.341 EDT [13722] LOG:  duration: 0.046 ms  bind <unnamed>: SELECT $1 * 2
2024-06-17 05:55:31.341 EDT [13722] DETAIL:  Parameters: $1 = '1.6'
2024-06-17 05:55:31.341 EDT [13722] LOG:  duration: 0.002 ms  execute <unnamed>: SELECT $1 * 2
2024-06-17 05:55:31.341 EDT [13722] DETAIL:  Parameters: $1 = '1.6'

Same code with SimpleQuery mode

2024-06-17 05:59:35.778 EDT [14625] LOG:  duration: 0.341 ms  statement: SELECT ('1.6'::numeric) * 2

If you are seeing the second, then somehow you are enabling SimpleQuery mode

from pgjdbc.

CharlesLgn avatar CharlesLgn commented on June 28, 2024

2024-06-17 05:55:31.341 EDT [13722] DETAIL: Parameters: $1 = '1.6'

Is the type (numeric/double precision/...) here depending on the setDouble/setBigDecimal or is it determined by the value on the ParameterMetaData of the PreparedStatement ?

If you are seeing the second, then somehow you are enabling SimpleQuery mode

When I debuged, I didn't reach the code I was modifing (so I don't think I'm in SimpleMode). However, when we catch the request in the SGBD log, we have ('40.6'::double precision)

from pgjdbc.

davecramer avatar davecramer commented on June 28, 2024

I ran

public void testSetNumber() throws SQLException {

with and without

PGProperty.PREFER_QUERY_MODE.set(props, "simple");

from pgjdbc.

CharlesLgn avatar CharlesLgn commented on June 28, 2024

I ran

public void testSetNumber() throws SQLException {

with and without

PGProperty.PREFER_QUERY_MODE.set(props, "simple");

ok but you said :

2024-06-17 05:55:31.341 EDT [13722] LOG:  duration: 0.002 ms  execute <unnamed>: SELECT $1 * 2
2024-06-17 05:55:31.341 EDT [13722] DETAIL:  Parameters: $1 = '1.6'

how does the SGBD choose the type of 1.6 ?
Is it define by :

  • the SGBD ?
  • the type given in the setDouble/setBigDecimal/setFloat ?
  • the type known in the ParameterMetaData ?

from pgjdbc.

davecramer avatar davecramer commented on June 28, 2024

pstmt.setBigDecimal(1, new BigDecimal("1.6"));

Sets it to be a BigDecimal

from pgjdbc.

CharlesLgn avatar CharlesLgn commented on June 28, 2024

ok, understood.

so for my need, I did something like that in my code :

  public void setValues(PreparedStatement st, int index, double d) throws SQLException {
    int type = st.getParameterMetaData().getParameterType(index);
    if (type == Types.NUMERIC) {
      st.setBigDecimal(index, BigDecimal.valueOf(d));
    } else {
      st.setDouble(index, d);
    }
  }

but why does not jdbcPG do something similar ?

I mean, when we create the PreparedStatement, all the ? types are defined in the ParameterMetaData. Moreover the data that is uses in the BigDecimal is BigDecimal#getValue() returning a double. so :

  • The bytes array is the same between a double and a BigDecimal
  • We have the info of the parameter type in the metadata

what are the limitation to not do so ?

from pgjdbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.