Given a custom enum:
CREATE TYPE vehicle AS ENUM ('car', 'truck', 'bicycle');
And a table like so:
CREATE TABLE vehicle_events (
timestamp timestamptz NOT NULL DEFAULT current_timestamp,
labels vehicle[] NOT NULL,
mentions int4[] NOT NULL DEFAULT '{}'
);
When this is queried from our node application like so:
SELECT * FROM vehicle_events;
This returns a json structure like so:
[{"timestamp": "January, 06 2016 23:04:56", "labels": "{'car'}", "mentions": [1,2,3,4]}]
My question really is, why is the labels array coming back as a string(note also that the mentions array of a base type is not)? Is this because it is an array of an ENUM
? If so, how can I force it into a regular array? And why is postgres returning it in this manner?
sqlfiddle link: http://sqlfiddle.com/#!15/637ce/1
"[1,2,3,4]"
would be a string, while[1,2,3,4]
isn't. What makes you think it is a string? Your own code shows the opposite.