Search code examples
postgresqlpostgresql-14

How to insert array embedded inside a postgresql custom type


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?


Solution

  • 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}') );