clkao / plv8js-migrated

Automatically exported from code.google.com/p/plv8js
Other
0 stars 0 forks source link

plv8.execute with json-based domain not converted to json #82

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run the test script below
2. note that the first output is [{"field":"foo","value":{"key":"value"}}]
3. note that the second output is with serialized json for the value column:  
[{"field":"foo","value":"{\"key\": \"value\"}"}]

What is the expected output? What do you see instead?

The column of json-based domain type should also be parsed as json.

test script:

DROP TABLE IF EXISTS plv8_test;
CREATE TABLE plv8_test (
    field text not null primary key,
    value json not null
);

INSERT into plv8_test VALUES('foo', '{"key": "value"}');
CREATE OR REPLACE FUNCTION test_json_select() RETURNS text AS $$
    var res = plv8.execute("select * from plv8_test");
    return JSON.stringify(res);
$$ LANGUAGE plv8;

select test_json_select();

drop domain if exists domain_json;
create domain domain_json as json;
DROP TABLE IF EXISTS plv8_test;
CREATE TABLE plv8_test (
    field text not null primary key,
    value domain_json not null
);

INSERT into plv8_test VALUES('foo', '{"key": "value"}');

select test_json_select();

Original issue reported on code.google.com by chiali...@gmail.com on 15 Oct 2013 at 5:22

GoogleCodeExporter commented 9 years ago
This should be a very simple fix. Just use getBaseType(typoid) to get the base 
type. If it's not a domain the argument passed in will be returned, if it is 
then the base type of the domain will be returned.

Original comment by AMDuns...@gmail.com on 17 Feb 2015 at 9:14

GoogleCodeExporter commented 9 years ago
Issue 109 has been merged into this issue.

Original comment by AMDuns...@gmail.com on 17 Feb 2015 at 9:16