question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Float type unique field query

See original GitHub issue

Bug description

Can’t query on unique field when it has Float type.

How to reproduce

  1. Create passenger with next phone number 48999888777
  2. Try to query it using crud.passenger() or passenger.findOne based on phone
query {
  passenger(
    where:{
      phone:48999888777
    }
  ) {
    id
    phone
  }
}

Expected behavior

In our case query payload is null. Need to be a passenger data

Prisma information

model Passenger {
  id String @id @default(cuid())

  lastName  String
  firstName String
  password  String?
  phone     Float   @unique
  email     String? @unique
  isBlocked Boolean @default(false)
}

Environment & setup

  • OS: Mac OS Catalina
  • Database: PostgreSQL
  • Prisma version: prisma2@2.0.0-preview024, binary version: 377df4fe30aa992f13f1ba152cf83d5770bdbc85
  • Node.js version: 12.8.1

Logs

express:router dispatching POST / +5s
  express:router query  : / +0ms
  express:router expressInit  : / +0ms
  express:router corsMiddleware  : / +0ms
  body-parser:json content-type "application/json" +0ms
  body-parser:json content-encoding "identity" +0ms
  body-parser:json read body +0ms
  body-parser:json parse body +1ms
  body-parser:json parse json +0ms
  prisma-client Prisma Client call: +9s
  prisma-client prisma.passenger.findOne({
  prisma-client   where: {
  prisma-client     phone: 48999888777
  prisma-client   }
  prisma-client }) +0ms
  prisma-client Generated request: +1ms
  prisma-client query {
  prisma-client   findOnePassenger(where: {
  prisma-client     phone: 48999888777
  prisma-client   }) {
  prisma-client     id
  prisma-client     lastName
  prisma-client     firstName
  prisma-client     password
  prisma-client     phone
  prisma-client     email
  prisma-client     isBlocked
  prisma-client   }
  prisma-client }
  prisma-client  +0ms
  engine {
  engine   PRISMA_DML_PATH: '.../node_modules/@prisma/client/schema.prisma',
  engine   PORT: '49773',
  engine   RUST_BACKTRACE: '1',
  engine   RUST_LOG: 'info',
  engine   LOG_QUERIES: 'true',
  engine   OVERWRITE_DATASOURCES: '[]',
  engine   CLICOLOR_FORCE: '1'
  engine } +0ms
  engine {
  engine   cwd: '.../prisma'
  engine } +0ms
  plusX Execution permissions of /.../node_modules/@prisma/client/runtime/query-engine-darwin are fine +0ms
  engine { flags: [ '--enable-raw-queries' ] } +1ms
  engine stderr Printing to stderr for debugging +14ms
  engine stderr Listening on 127.0.0.1:49773 +0ms
  engine stdout {
  timestamp: 'Mar 19 19:05:31.841',
  level: 'INFO',
  target: 'quaint::pooled',
  fields: { message: 'Starting a postgresql pool with 9 connections.' }
} +8ms
prisma:info  Starting a postgresql pool with 9 connections.
  engine stdout {
  timestamp: 'Mar 19 19:05:31.850',
  level: 'INFO',
  target: 'prisma::server',
  fields: {
    message: 'Started http server on 127.0.0.1:49773',
    'log.target': 'prisma::server',
    'log.module_path': 'prisma::server',
    'log.file': 'query-engine/prisma/src/server.rs',
    'log.line': 95
  }
} +9ms
prisma:info  Started http server on 127.0.0.1:49773
  express:router dispatching POST / +624ms
  express:router query  : / +0ms
  express:router expressInit  : / +0ms
  express:router corsMiddleware  : / +0ms
  body-parser:json content-type "application/json" +0ms
  body-parser:json content-encoding "identity" +0ms
  body-parser:json read body +0ms
  body-parser:json parse body +0ms
  body-parser:json parse json +0ms
  engine stdout {
  timestamp: 'Mar 19 19:05:32.446',
  level: 'INFO',
  target: 'quaint::connector::metrics',
  fields: {
    query: 'SELECT "v1"."Passenger"."id", "v1"."Passenger"."lastName", "v1"."Passenger"."firstName", "v1"."Passenger"."password", "v1"."Passenger"."phone", "v1"."Passenger"."email", "v1"."Passenger"."isBlocked" FROM "v1"."Passenger" WHERE "v1"."Passenger"."phone" IN ($1) OFFSET $2',
    item_type: 'query',
    params: '[48999888777,0]',
    duration_ms: 117
  }
} +605ms
prisma:query SELECT "v1"."Passenger"."id", "v1"."Passenger"."lastName", "v1"."Passenger"."firstName", "v1"."Passenger"."password", "v1"."Passenger"."phone", "v1"."Passenger"."email", "v1"."Passenger"."isBlocked" FROM "v1"."Passenger" WHERE "v1"."Passenger"."phone" IN ($1) OFFSET $2
  express:router dispatching POST / +1m
  express:router query  : / +1ms
  express:router expressInit  : / +0ms
  express:router corsMiddleware  : / +0ms
  body-parser:json content-type "application/json" +0ms
  body-parser:json content-encoding "identity" +0ms
  body-parser:json read body +0ms
  body-parser:json parse body +0ms
  body-parser:json parse json +0ms

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Sakhrocommented, Mar 25, 2020

@Sakhro may i ask: why using a float for a phone number? i would strongly advice to use a string instead. Float usually do not guarantee that they can be checked to equality und can lead to unexpected behavior.

I just also implemented a prisma backend where phoneNumber is a unique field and my approach was to store a normalized string of the number. i used this package: https://www.npmjs.com/package/phone

The reason was my incompetence in that xD. Already changed it to the String type. Thx 😊

1reaction
Sakhrocommented, Mar 25, 2020

@pantharshit00 It works in latest alfa release prisma2@2.0.0-alpha.947

Read more comments on GitHub >

github_iconTop Results From Across the Web

Distinct Float - SQL Server Forums - SQLTeam.com
Hi, I have a query which uses Select Distinct on a table which contains some Float columns which is returning duplicate rows.
Read more >
ArcGIS field data types
The available types include a variety of number types, text types, date types, binary large objects (BLOBs), or globally unique identifiers (GUIDs). Choosing ......
Read more >
Find datatype, unique values and max values for all columns ...
For datatype do df.dtypes and it will show you all the columns types. For all unique values in a column you can use...
Read more >
Introduction to data types and field properties - Microsoft Support
Specifies whether the field has an index. There are three available values: Yes (No duplicates) Creates a unique index on the field. Yes...
Read more >
SQL Data Types - w3resource
SQL Data Types : A data type defines the kind of value a field (of a ... According to unicode.org "Unicode provides a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found