Reputation: 87
I have a custom type "nameage" and a table "namesages".
CREATE TYPE nameage AS(
name_ varchar(50),
age smallint
);
CREATE TABLE namesages(
id serial,
namesandages nameage[]
);
INSERT INTO namesages(namesandages) VALUES(ARRAY[['john', 24],['david', 38]]::nameage[]);
Why does this query give error?;
ERROR: malformed record literal: "john"
LINE 1: insert into namesages(namesandages) values(ARRAY[['john', 24...
^
DETAIL: Missing left parenthesis.
********** Error **********
Upvotes: 2
Views: 5652
Reputation: 221370
What you meant to do was this:
INSERT INTO namesages(namesandages)
VALUES(ARRAY[ROW('john', 24),ROW('david', 38)]::nameage[]);
This creates a one dimensional array of user-defined composite types. I'm not sure what you intended to do when you defined a two-dimensional array...
Upvotes: 9