Comments (10)
but why does not jdbcPG do something similar ?
I mean, when we create the
PreparedStatement
, all the?
types are defined in theParameterMetaData
. Moreover the data that is uses in theBigDecimal
isBigDecimal#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.
from pgjdbc.
If I remember correctly 06abfb7 only effects simple query mode which if you are using PreparedStatements this will not be the case.
from pgjdbc.
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.
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.
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.
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.
I ran
with and without
from pgjdbc.
I ran
with and without
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.
Sets it to be a BigDecimal
from pgjdbc.
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)
- Reuse buffers and reduce allocations in GSSInputStream
- Connection.rollback should cancel in-flight queries HOT 1
- Connection.abort should cancel in-flight queries HOT 3
- Test against PostgreSQL head. HOT 2
- DDL batch commit, pg_stat_activity displays execution one by one, not batch execution HOT 4
- Multiple BEGIN ATOMIC ... END; not supported for prepared statement. HOT 5
- Feature: please support getObject(int, byte[].class) for bytea HOT 3
- batched updates + reWriteBatchedInserts + transactions does not return row count of affected rows HOT 10
- ResultSetMetaData.getColumnType() java.sql.Types.BOOLEAN field misidentified as BIT HOT 1
- 42.7.3 GitHub release jar is different from the jar on maven HOT 1
- NamedParameterJdbcTemplate execute complex Insert Query HOT 1
- feature request: Add support for native java unix sockets without needing JNI
- ResultSet.getObject throws exeception for 'Infinity'::numeric values HOT 4
- ARRAY() function return result problem HOT 2
- capitalization matters for PGInterval HOT 1
- PgStatement.executeWithFlags(sql, QueryMode.Simple) does not execute in Simple mode
- SQLWarnings returned on successful SQL statements HOT 28
- Provide Enum implementation of java.sql.SQLType interface? HOT 1
- Using Flink Datastream API to read and write PostgreSQL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgjdbc.