Home > Software engineering >  How to insert array embedded inside a postgresql custom type
How to insert array embedded inside a postgresql custom type

Time:07-20

I have defined a new type

 CREATE TYPE days_of_week as (
    days integer[]
  );

I have a table as follows:

 create table rr( idd days_of_Week);

I am trying to insert an array in days_of_week like

insert into rr ( idd ) VALUES ( ('{1,3}') );

I get an error: ERROR: malformed record literal: "{1,3}"

How do I fix this?

CodePudding user response:

You could try to use this one;

insert into rr ( idd ) VALUES ( row('{1,3}')::days_of_week );

Also,

insert into rr ( idd ) VALUES ( row('{1,3}') );
  • Related