Error inserting array into PostgreSQL column: Malformed array literal

148 views Asked by At

I'm encountering an issue while trying to insert an array of strings into a PostgreSQL database column. The column is defined as follows:

path TEXT[] NOT NULL

here is the schema:

path: { type: 'array', items: { type: 'string' }, notNull: true }

here I send the format of path like this

await updateGlobalChatNotificationOptIn({
      variables: {
        path: ['chat'],
        option: updatedGlobalChatNotificationOptIn,
      },

updateNotificationOption(path: [String!]!, option: String!): NotificationUserOption

when I pass the path something like this ['chat']


  // If no existing record, create a new one
      return NotificationUserOption.query().upsertGraphAndFetch(
        { userId, path, groupId, option },
        { insertMissing: true },
      )
    },
    
  extend type Mutation {
    updateNotificationOption(path: [String!]!, option: String!): NotificationUserOption
  }

However, when I try to insert the array using this code, I encounter the following error:

malformed array literal: "["chat"]" "[" must introduce explicitly-specified array dimensions.

I've tried using single brackets ('{chat}') and double brackets ([['chat']]), but neither seems to work.

How can I correctly format the array literal so that I can insert the array into the PostgreSQL column without encountering this error?

0

There are 0 answers