Skip to content

double precision field not parsed correctly, loss of precision #64

Description

@gabooh

I get data from fields in postgresql 9.4 :

create table bookseller
(
...
	maplatitude double precision,
	maplongitude double precision,
...
);

And setting up node-pg like this :


const {Pool} = require('pg')
const types = require('pg').types

types.setTypeParser(701, (val) => {
  console.log(`val double : ${val}`)
  return parseFloat(val)
})

Data from pg looks like this :

maplatitude : 43.84668200000001
maplongitude : 5.559941999999999

But I get this with node-pg, whatever I do (default type parser, or with above override).

maplatitude : 43.846682
maplongitude : 5.559942

The result from node-pg :

Result {
  command: 'SELECT',
  rowCount: 1,
  oid: NaN,
  rows: 
   [ anonymous {
     ...
       maplatitude: 43.846682,
       maplongitude: 5.559942 } ],
  fields: 
...
     Field {
       name: 'maplatitude',
       tableID: 724451,
       columnID: 11,
       dataTypeID: 701,
       dataTypeSize: 8,
       dataTypeModifier: -1,
       format: 'text' },
     Field {
       name: 'maplongitude',
       tableID: 724451,
       columnID: 12,
       dataTypeID: 701,
       dataTypeSize: 8,
       dataTypeModifier: -1,
       format: 'text' } ],

I've read countless bug report and node-pg docs on this, seams like it should work correctly. Is this a bug ? Or something I'm not doing correctly ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions