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 **********
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With