Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

::INET column type not supported when creating #24129

Open
davidgg opened this issue May 8, 2024 · 4 comments
Open

::INET column type not supported when creating #24129

davidgg opened this issue May 8, 2024 · 4 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: create() topic: createMany() topic: @db.Inet Native type `Inet`

Comments

@davidgg
Copy link

davidgg commented May 8, 2024

Bug description

Related to #17929 (comment)

Inserting a inet column type triggers an error. Both for create and createMany

Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: ToSql(0), cause: Some(AddrParseError(Ip)) }), transient: false })
    at In.handleRequestError (node_modules/@prisma/client/runtime/library.js:122:7044)
    at In.handleAndLogRequestError 
    at In.request 
    at async l
    at async retrieve 
    at async runJob{

How to reproduce

Create a table with the inet type

model Subnet {
  id      String @id @default(cuid())
  subnet  String @db.Inet
}

Insert into the table

 await prisma.subnet.create({ data: { subnet: "0.0.0.0/8" } });

An error is thrown

Expected behavior

Prisma inserts correctly

Prisma information

Schema

model Subnet {
  id      String @id @default(cuid())
  subnet  String @db.Inet
}

Query

 await prisma.subnet.create({ data: { subnet: "0.0.0.0/8" } });

Environment & setup

  • OS: macOS
  • Database: PostgreSQL 16.2
  • Node.js version: v21.6.2

Prisma Version

5.13.0
@davidgg davidgg added the kind/bug A reported bug. label May 8, 2024
@davidgg
Copy link
Author

davidgg commented May 8, 2024

ping @RrredHead

@janpio
Copy link
Member

janpio commented May 8, 2024

To pinpoint: Does it work without /8, just a pure IP address?

@Druue Druue added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. topic: @db.Inet Native type `Inet` topic: createMany() topic: create() labels May 8, 2024
@davidgg
Copy link
Author

davidgg commented May 8, 2024

To pinpoint: Does it work without /8, just a pure IP address?

Yes. It works with a regular IP, without the mask.

@davidgg
Copy link
Author

davidgg commented May 8, 2024

As a workaround, for single insertion:

  const subnet = "0.0.0.0/8";

  await prisma.$executeRaw`
    INSERT INTO "Subnet" ("subnet")
    VALUES ${Prisma.sql`(${subnet}::INET)`}
    ON CONFLICT DO NOTHING;
  `;

For multiple insertion:

  await prisma.$executeRaw`
    INSERT INTO "Subnet" ("subnet")
    VALUES ${Prisma.join(
      data.map((row) => Prisma.sql`(${row.subnet}::INET`),
      ', ',
    )}
    ON CONFLICT DO NOTHING;
  `;

Note that I had to change the id column so postgresql generates it and I can run raw queries without worrying about it.

model Subnet {
  id      String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  subnet  String @db.Inet
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: create() topic: createMany() topic: @db.Inet Native type `Inet`
Projects
None yet
Development

No branches or pull requests

3 participants