Hello, I'm using Prisma 1, and I have a Float that...
# orm-help
r
Hello, I'm using Prisma 1, and I have a Float that holds a timestamp (whch is very inefficient when trying query data by it in a table with a lot of records since in PostreSQL gets as a numeric with 65 digits percision) . 1. My plan si to convert the Float into a DateTime. Do you think that would be a better choice from performance perspective? 2. I suppose I would lose my data if I convert it straignt from the datamodel.graphql, right? So, I'm creating a new field and try to transfer the data. Is there an easy way to do that? updateMany methods can somehow reference itself record? Or, I need to query each field, get data and update it one by one?
r
Hey Raluca šŸ‘‹ 1. If you're wanting to query between dates then yes DateTime would be a much better choice. 2. To convert, currently the best way would be: • Create a new field with the DateTime type • Create a script that runs on all fields to convert the
Float
timestamp to a
DateTime
(and yes currently that would have to be done for each record, so best would be to loop over the records) • Delete the old
Float
field
r
oky, thanks Ryan! šŸ™‚
šŸ‘ 1
Hey @Ryan, I added a new Datetime field and created a script that transfered the data into it. So I have both fields now, and tested a query agains both if them, but I got some surprising results: • Query by FLOAT duration 342 • Query by DATE duration 630
r
Was the query for a date range?
r
timestamp: Float! timestampAsDate: DateTime
Copy code
let log_start1 = moment(new Date());
  let thisYearAvgFirstInfo = await ctx.db.query.historyAvgDataHourlies({
    where: {
      windTurbine: { id: windTurbineId },
      year: year,
    },
    orderBy: "timestamp_ASC",
    first: 1
  }, info);

  let log_end1 = moment(new Date());
  console.log("!!! Query by FLOAT duration", log_end1 - log_start1);

  let log_start2 = moment(new Date());
  thisYearAvgFirstInfo = await ctx.db.query.historyAvgDataHourlies({
    where: {
      windTurbine: { id: windTurbineId },
      year: year,
    },
    orderBy: "timestampAsDate_ASC",
    first: 1
  }, info);

  let log_end2 = moment(new Date());
  console.log("!!!Query by DATE duration", log_end2 - log_start2);