Skip to content

Float number on raw query: incorrect binary data format in bind parameter 1 #17110

@Renato66

Description

@Renato66

Bug description

error when trying to send a float number to raw query:

db error: ERROR: invalid byte sequence for encoding "UTF8"

How to reproduce

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()
const generate = async (): Promise<void> => {
  const result2 = await prisma.$queryRawUnsafe(`SELECT $1`, 100)
  console.log(result2) // [ { '?column?': '100' } ] works!
  const result = await prisma.$queryRawUnsafe(`SELECT $1`, 9.9)
  console.log(result) // Error
  // prisma 4.8.0 db error: ERROR: incorrect binary data format in bind parameter 1
  // prisma 3.15.2 Raw query failed. Code: `22021`. Message: `db error: ERROR: invalid byte sequence for encoding "UTF8": 0x00`
}

generate()
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })
  .finally(async () => {
    await prisma.$disconnect()
  })

Expected behavior

[ { '?column?': '9.9' } ]

Prisma information

any

Environment & setup

  • OS: MAC
  • Database: PostgreSQL
  • Node.js version: ˆ16

Prisma Version

tested on prisma 4.8.0 and prisma 3.15.2

Solution

when we add a ; to the first query it works fine

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()
const generate = async (): Promise<void> => {
  const result2 = await prisma.$queryRawUnsafe(`SELECT $1;`, 100)
  console.log(result2) // [ { '?column?': '100' } ] works!
  const result = await prisma.$queryRawUnsafe(`SELECT $1`, 9.9)
  console.log(result) // [ { '?column?': 9.9 } ] works!
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: floating point typesTopic related to floating point types and precision losstopic: prepared statement cachetopic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions