Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt is converted into text in jsonb-conversion #485

Closed
alexeyfadeev opened this issue Apr 23, 2022 · 1 comment
Closed

BigInt is converted into text in jsonb-conversion #485

alexeyfadeev opened this issue Apr 23, 2022 · 1 comment

Comments

@alexeyfadeev
Copy link

alexeyfadeev commented Apr 23, 2022

BigInt is appeared in v8 not so long ago. In plv8 it is supported from 3.0.0. If sql query contains bigint columns, values are converted correctly after plv8.execute. But if function returns JSONB, bigint json fields are converted to text. Example:

CREATE OR REPLACE function plv8.test_count(
    "tableName" text)
  RETURNS jsonb AS $$

  const data = plv8.execute(`SELECT COUNT(*) AS "count" FROM ${tableName}`);
  return data[0]
$$ LANGUAGE plv8;

SELECT * FROM plv8.test_count('my_table');
-- returns: {"count": "9"}

Value of count is text value. Totally unexpected behaviour, hope for soon fix.
p.s. In plv8 v 2.x.x this function works correct (if count value fits into int).

@JerrySievert
Copy link
Member

BigInt is not serializable in v8 (or in the spec) as JSON, and after much previous discussion it was decided that by default plv8 will follow with this decision in v8 and the spec.

if you feel that you must break the spec, you can look at https://github.com/plv8/plv8/blob/v3.1.2/Makefile#L77-L79 which allows you to tell plv8 to ignore the spec and try to do a "best guess" at how to figure out how to serialize/deserialize a BigInt, probably making mistakes as it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants