Inserting into columns of type Enum

Hi! I am not sure how to insert data into enum column type...

export const batchTransactionTypeEnum = pgEnum("type", [
    "IN",
    "OUT"
]);

export const batchTransaction = pgTable('batch_transaction', {
    id: serial('id').primaryKey(),
    type: batchTransactionTypeEnum("type"),
})

and query:

        let bt = await tx.insert(batchTransaction).values({
          batchId: b.id,
          type: "IN",
          quantityInBaseUnit: ds.document_subline.quantityInBaseUnit,
        });


above code results in ungly error:
Query: insert into "batch_transaction" ("id", "quantity_in_base_unit", "type", "created_at", "batch_id") values (default, $1, $2, default, $3) -- params: ["25.00", "IN", 9]
H:\projects\wms\backend-express\node_modules\postgres\cjs\src\connection.js:790
    const error = Errors.postgres(parseError(x))
                         ^
PostgresError: nieprawidłowa wartość wejścia dla enumeracji type: "IN"
    at ErrorResponse (H:\projects\wms\backend-express\node_modules\postgres\cjs\src\connection.js:790:26)
    at handle (H:\projects\wms\backend-express\node_modules\postgres\cjs\src\connection.js:476:6)
    at Socket.data (H:\projects\wms\backend-express\node_modules\postgres\cjs\src\connection.js:315:9)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Socket.Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  severity_local: 'BŁĄD',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $2 = '...'",
  file: 'enum.c',
  line: '133',
  routine: 'enum_in'
}



Found simmilar topic, but solution with adding cosnt to enum value does not work.
helpInserting into columns of type Enum
Was this page helpful?