lidavidm commented on PR #1407:
URL: https://github.com/apache/arrow-java/pull/1407#issuecomment-6938709012

   But a float can't actually represent `0.1` exactly. We just write and print 
that as shorthand for the closest value. 
   
   Also, for PostgreSQL, it appears what you're seeing is actually an artifact 
of text vs binary format; when the binary format is used, you instead get 
`0.1000...`.
   
   ```
   prepareThreshold=0
   getString() 0.1
   getObject() 0.1
   getFloat() 0.1
   getDouble() 0.1
   getBigDecimal() 0.1
   
   prepareThreshold=-1
   getString() 0.1
   getObject() 0.1
   getFloat() 0.1
   getDouble() 0.10000000149011612
   getBigDecimal() 0.1
   ```
   
   <details>
   
   ```java
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.util.Properties;
   
   public class PgjdbcFloatReproducer {
     public static void main(String[] args) throws Exception {
       if (args.length != 3) {
         throw new IllegalArgumentException(
             "Usage: PgjdbcFloatReproducer <jdbc-url> <username> <password>");
       }
   
       for (int threshold : new int[] {0, -1}) {
         Properties properties = new Properties();
         properties.setProperty("user", args[1]);
         properties.setProperty("password", args[2]);
         properties.setProperty("prepareThreshold", 
Integer.toString(threshold));
         properties.setProperty("binaryTransfer", "true");
         properties.setProperty("preferQueryMode", "extended");
   
         try (Connection connection = DriverManager.getConnection(args[0], 
properties);
             PreparedStatement statement = connection.prepareStatement("SELECT 
CAST(0.1 AS real)");
             ResultSet rs = statement.executeQuery()) {
           rs.next();
           System.out.println("\nprepareThreshold=" + threshold);
           System.out.println("getString() " + rs.getString(1));
           System.out.println("getObject() " + rs.getObject(1));
           System.out.println("getFloat() " + rs.getFloat(1));
           System.out.println("getDouble() " + rs.getDouble(1));
           System.out.println("getBigDecimal() " + rs.getBigDecimal(1));
         }
       }
     }
   }
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to