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.

[CockroachDB] No difference between `integer` and `bigInteger`

See original GitHub issue

Environment

Knex version: 0.95.15+ Database + version: CockroachDB v21.1.13 OS: macOS Monterrey

Bug

Both integer and bigInteger both result in a int8 column being created in CockroachDB, whereas Postgres creates them as int4 and int8 respectively. This becomes an issue, as int8s are always returned as a String by the pg connection library, causing unexpected incompatibilities between the database vendors.

knex.schema.createTable('example', (table) => {
  table.increments();

  table.integer('example_int');
  table.bigInteger('example_bigint');
});

Note how both columns are created as an int8 in CockroachDB.

I believe this is due to the fact that CockroachDB defaults to int8 when using .. ADD COLUMN example INTEGER, which is the default from here (AFAICT as the PG dialect doesn’t have a specific integer in the columncompiler).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kibertoadcommented, Jan 21, 2022

@nickrum I like that idea, but I wonder how intrusive that would be. Maybe it would be easier to achieve not as an option, but as a separate dialect, extending vanilla cockroachdb one. I would still like to hear @rafiss perspective first, because maybe we would be sabotaging crdb by overriding defaults that might be there for a good reason.

2reactions
rijkvanzantencommented, Jan 21, 2022

What are the implications of current misalignment between pg and crdb? numeric values need to be handled differently?

As of right now, it means that (for CRDB):

  • There’s no difference between integer/bigInteger and increments/bigIncrements
  • .increments doesn’t actually use auto-incrementing integers, like the name suggests
  • All integers are returned as Strings at all times
Read more comments on GitHub >

github_iconTop Results From Across the Web

INT | CockroachDB Docs
The different integer types place different constraints on the range of allowable values, but all integers are stored in the same way regardless...
Read more >
INT vs BIGINT - ObjectRocket
INT and BIGINT are both integer numeric data types. Let us compare both of them in terms of storage size, minimum value, maximum...
Read more >
CockroachDB - creating limited key ranges
... you're migrating an application to CockroachDB from a different database where the old database schema was using int-based keys, it is ...
Read more >
CockroachDB Data Types Cheatsheet - TablePlus
ARRAY, A 1-dimensional, 1-indexed, homogenous array of any non-array data type. ... INT, 64-bit, INTEGER, INT8, INT64, BIGINT.
Read more >
Using Prisma with CockroachDB
use Introspection for existing projects if you already have a CockroachDB database; use Prisma Migrate to migrate your database schema to a new...
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