GithubHelp home page GithubHelp logo

Comments (2)

eulerto avatar eulerto commented on May 20, 2024

Please read JSON spec (http://json.org/). It defines number without quotation marks. Also, we wouldn't be consistent with postgres.

euler=# create table foo (a numeric(5,2));
CREATE TABLE
euler=# insert into foo values(1.23),(4.56),(7.89);
INSERT 0 3
euler=# select row_to_json(row(a)) from foo;
 row_to_json 
-------------
 {"f1":1.23}
 {"f1":4.56}
 {"f1":7.89}
(3 rows)

from wal2json.

rcoup avatar rcoup commented on May 20, 2024

Oh, I entirely understand that regular numbers aren't quoted in JSON.

Doing some more testing it seems the text outputs of numerics do have the correct precision & scale, so it's (reasonably) up to the JSON parser how they're interpreted from text back into numbers. 👍

eg.

# set extra_float_digits=3;
# create table x (id int primary key, a double precision, b numeric (30,20));
# insert into x values(10, '0.1'::float8*'0.1'::float8, '0.1'::numeric*'0.1'::numeric);
# select * from x;
 id |           a           |            b
----+-----------------------+-------------------------
 10 | 0.0100000000000000019 |  0.01000000000000000000

produces

{
	"change": [
		{
			"kind": "insert",
			"schema": "public",
			"table": "x",
			"columnnames": ["id", "a", "b"],
			"columntypes": ["integer", "double precision", "numeric(30,20)"],
			"columnvalues": [10, 0.01, 0.01000000000000000000]
		}
	]
}

from wal2json.

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.