2

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 **********
2
  • 1
    Why don't you properly normalize your data model? Commented Nov 7, 2015 at 8:38
  • What is the intent of your two dimensional array? In your current code, you seem to need only a single dimension... Also, please, can you ask one question at a time. It will be much easier and more useful to answer Commented Nov 7, 2015 at 9:17

1 Answer 1

9

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.