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

Add support for JSONB. #20

Open
rafaelveloso opened this issue Mar 23, 2015 · 2 comments
Open

Add support for JSONB. #20

rafaelveloso opened this issue Mar 23, 2015 · 2 comments

Comments

@rafaelveloso
Copy link

pl/v8 can't seem to properly handle JSONB.

Test case

Having the following function:

CREATE OR REPLACE FUNCTION jsonb_test(data anyelement)
  RETURNS jsonb AS
    $BODY$
       return JSON.stringify(data);
    $BODY$
LANGUAGE plv8 STABLE STRICT;

When running:

SELECT jsonb_test('{"a":1, "b":{"c": 2}}'::json);
result: {"a": 1, "b": {"c": 2}}

will result in {"a": 1, "b": {"c": 2}} which is the expected result.

When running

SELECT jsonb_test('{"a":1, "b":{"c": 2}}'::jsonb);

we get "{\"a\": 1, \"b\": {\"c\": 2}}", which is not ideal.

@trailsandtribulations
Copy link

some notes:

  1. SELECT jsonb_test('{"a":1, "b":{"c": 2}}'::json) works fine
  2. the type jsonb seems to be internal to the pg database, that is, not stored as a string but parsed, so don't see quite how {}::jsonb as an argument makes sense
  3. that said, there appears to be a bug, nonetheless, plv8 claims to support json, not jsonb.
  4. I don't see the pg engine supporting json in any fashion except for text, so it seems to me nothing gained anywhere by typing something to jsonb within a javascript function.

@rafaelveloso
Copy link
Author

There is a recently merged PR regarding JSONB support for plv8
plv8/plv8#116

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