Skip to content

json_extract_array_element_text for strings #3

@mbrackett

Description

@mbrackett

Compare:
select json_extract_array_element_text('["Sandwich", "Omelette", "Tikka Masala"]', 0)

In Redshift, that gets you an unquoted Sandwich, in docker-pgredshift that gets you a double-quoted "Sandwich".

Adding .strip('"') to the json.dumps seems to solve it:

CREATE FUNCTION json_extract_array_element_text(json_array text, array_index int) RETURNS text immutable as $$
    import json
    result = json.loads(json_array)[array_index]
    return json.dumps(result).strip('"')
    $$ LANGUAGE plpythonu;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions