-
Notifications
You must be signed in to change notification settings - Fork 64
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
Getting DB::ColumnTypeMismatchError
for Int32
columns in CockroachDB
#919
Comments
Oh nice. I wasn't aware of those types. Any idea how far back of a Postgres version that works on? At least to v12? |
From the PostgreSQL docs, as far back as v7.2: https://www.postgresql.org/docs/7.2/datatype.html |
nice! Yeah, in that case, it should be fine, I think. |
akadusei
added a commit
to akadusei/avram
that referenced
this issue
Jan 16, 2023
Fixes luckyframework#919 ``` In PG::ResultSet#read the column one returned a Int64 but a Int32 was expected. (DB::ColumnTypeMismatchError) from lib/db/src/db/result_set.cr:89:9 in 'read' from lib/db/src/db/query_methods.cr:202:9 in 'query_one?:as:args' from lib/avram/src/avram/database.cr:88:3 in 'query_one?:as:args:queryable' from lib/avram/src/avram/database.cr:88:3 in 'query_one?:args:queryable:as' from lib/avram/src/avram/queryable.cr:224:17 in 'any?' # ... ```
jwoertink
pushed a commit
that referenced
this issue
Jan 16, 2023
…920) Fixes #919 ``` In PG::ResultSet#read the column one returned a Int64 but a Int32 was expected. (DB::ColumnTypeMismatchError) from lib/db/src/db/result_set.cr:89:9 in 'read' from lib/db/src/db/query_methods.cr:202:9 in 'query_one?:as:args' from lib/avram/src/avram/database.cr:88:3 in 'query_one?:as:args:queryable' from lib/avram/src/avram/database.cr:88:3 in 'query_one?:args:queryable:as' from lib/avram/src/avram/queryable.cr:224:17 in 'any?' # ... ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have an app that I'm currently testing on CockroachDB, and encounter this error:
The problem appears to be that in CockroachDB (v22.2),
int
is an alias forint8
. In PostgreSQL,int
refers toint4
. So for anInt32
column in Avram, CockroachDB is creating anint8
column whereascrystal-pg
expects to read anint4
.Not tested, but this may be solved by changing the
Avram::Migrator::Columns::Int32Column#column_type
toint4
:avram/src/avram/migrator/columns/int32_column.cr
Line 11 in ac949e4
While at it, we may as well change
Avram::Migrator::Columns::PrimaryKeys::Int32PrimaryKey#column_type
toserial4
:avram/src/avram/migrator/columns/primary_keys/int32_primary_key.cr
Line 9 in ac949e4
These changes should make it explicit to both DB engines what the column type is. This should not be a breaking change.
The text was updated successfully, but these errors were encountered: