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.

Problem with big decimal field on table creation

See original GitHub issue
QueryFailedError: 🔨 Not supported 🔨 : The query you ran generated an AST which parts have not been read by the query planner. This means that those parts could be ignored:
    
        ⇨ .columns[6].dataType.config ([200,2])
    
    👉 pg-mem is work-in-progress, and it would seem that you've hit one of its limits.
    
    *️⃣ Failed SQL statement: 
    CREATE TABLE "public"."activity" (
      ... [ redacted ] ...
      "amount" numeric(200,2), 
      ... [ redacted ] ...
    );
    
        at new QueryFailedError (.../src/error/QueryFailedError.ts:9:9)
        at .../src/driver/postgres/PostgresQueryRunner.ts:188:30
        at Timeout._onTimeout (.../node_modules/pg-mem/src/adapters.ts:123:42)
        at listOnTimeout (internal/timers.js:554:17)
        at processTimers (internal/timers.js:497:7) 

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
oguimbalcommented, May 12, 2022

Hi, It would be easy to implement it naïvely, meaning that table creation would work, and usual operations as well.

BUT, doing that would not implement the actual behaviour of numeric, which is quite complex.

This would mean that you could get inconsistent results (numbers would not be truncated to the defined numeric precision, “Infinity” and “NaN” would not exist, …) 👉 These numbers would not behave exactly as actual postgres numeric values, and your tests might not behave as expected 🤷‍♂️

So, just a quick poll (anyone can answer): Vote 👍 if it would be of any use to implement that naïve version Vote 👎 if it’s useless, and you want to wait until I have enough time to implement a real numeric type

4reactions
oguimbalcommented, May 17, 2022

Now that I think about it, this workaround should work as well:

const db = newDb();
db.public.interceptQueries(sql => {
    const newSql = sql.replace(/\bnumeric\s*\(\s*\d+\s*,\s*\d+\s*\)/g, 'float');
    if (sql !== newSql) {
         return db.public.many(newSql);
    }
    // proceed to actual SQL execution for other requests.
    return null;
});

This should replace all numeric(x,y) instances in the executed queries with float.

And at least, if you copy-paste that, you know that you’re doing something wrong for your numeric types 😄

disclaimer: not tested 😃

disclaimer 2: dont try to insert strings that contain numeric(x,y) 😅

Tell me if it works… (it is in fact equivalent to the naive implementation) If it does, i’ll wait

Read more comments on GitHub >

github_iconTop Results From Across the Web

Four common pitfalls of the BigDecimal class and how to ...
Here, the x value has lost four decimal digits because a double has a precision of only 15–17 digits (a float has a...
Read more >
When a BigDecimal value is inserted into a NUMERIC column ...
When a BigDecimal value is inserted into a NUMERIC column using the Simba JDBC Driver for BigQuery, why is the numeric precision lost?...
Read more >
Math operations with decimal data type returning incorrect ...
Math operations with decimal data type returning incorrect values when using PreparedStatement and BigDecimal objects #1489. Open.
Read more >
Big Decimal (BigDecimal) Support for Real Numbers - IBM
The storage. bigDecimalRoundingMode property sets the rounding mode when Big Decimal is used. The default is HALF_UP, meaning that the rounding mode is...
Read more >
Decimal value is rounded up/down to integer value - Office
To work around this problem, manually set the Field Size property of the column to Double or to Decimal. Click the DataSheet tab....
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