drizzle-orm: [BUG]: Cannot run drizzle-studio with DATA-API. Unsupported data type "CHAR"
What version of drizzle-orm are you using?
0.34.1
What version of drizzle-kit are you using?
0.25.0
Describe the Bug
It was working fine last week but now, when trying to run the studio, I’m getting this error.
Error: The result contains the unsupported data type “CHAR”. at _ (https://local.drizzle.studio/index.js:14138:33349) at async https://local.drizzle.studio/index.js:14138:33539 at async Promise.all (index 1) at async $oi (https://local.drizzle.studio/index.js:13940:1587) at async Xkl (https://local.drizzle.studio/index.js:14138:33520)
I managed to debug and get the query responsible for this error. I reproduce this error within the query editor of RDS
SELECT
CASE
WHEN c.relkind = 'r' THEN 'table'
WHEN c.relkind = 'v' THEN 'view'
WHEN c.relkind = 'm' THEN 'mat_view'
END AS entity_type,
n.nspname AS table_schema,
c.relname AS table_name,
a.attname AS column_name,
pg_catalog.pg_get_expr(ad.adbin, ad.adrelid) AS column_default,
CASE a.attnotnull
WHEN TRUE THEN 'NO'
ELSE 'YES'
END AS is_nullable,
CASE
WHEN pg_catalog.pg_get_expr(ad.adbin, ad.adrelid) LIKE 'nextval(%'
AND format_type(a.atttypid, a.atttypmod) = 'integer' THEN 'serial'
WHEN pg_catalog.pg_get_expr(ad.adbin, ad.adrelid) LIKE 'nextval(%'
AND format_type(a.atttypid, a.atttypmod) = 'bigint' THEN 'bigserial'
WHEN pg_catalog.pg_get_expr(ad.adbin, ad.adrelid) LIKE 'nextval(%'
AND format_type(a.atttypid, a.atttypmod) = 'smallint' THEN 'smallserial'
ELSE format_type(a.atttypid, a.atttypmod)
END AS data_type,
CASE
WHEN t.typcategory = 'A' THEN 'ARRAY'
WHEN t.typtype = 'b' THEN a.atttypid::regtype::text
ELSE 'USER-DEFINED'
END AS additional_dt,
a.attndims AS array_dimensions,
a.attnum,
a.attidentity AS identity_type,
a.attgenerated AS generated_type,
seq_class.relname AS identity_name,
seq.seqincrement AS identity_increment,
seq.seqmax AS identity_max,
seq.seqmin AS identity_min,
seq.seqstart AS identity_start,
seq.seqcache AS identity_cache,
seq.seqcycle AS identity_cycle
FROM
pg_catalog.pg_attribute a
JOIN
pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN
pg_catalog.pg_namespace n ON c.relnamespace = n.oid
LEFT JOIN
pg_catalog.pg_depend dep ON dep.refobjid = c.oid AND dep.refobjsubid = a.attnum
LEFT JOIN
pg_catalog.pg_class seq_class ON seq_class.oid = dep.objid
LEFT JOIN
pg_catalog.pg_sequence seq ON seq_class.oid = seq.seqrelid
LEFT JOIN
pg_catalog.pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
JOIN
pg_catalog.pg_type t ON a.atttypid = t.oid
WHERE
c.relkind IN ('r', 'v', 'm')
AND a.attnum > 0
AND NOT a.attisdropped
AND n.nspname NOT LIKE 'pg\\_%'
AND n.nspname != 'information_schema'
ORDER BY
attnum;
Casting these 2 lines seems to fix the issue:
a.attidentity::text AS identity_type,
a.attgenerated::text AS generated_type
It seems similar to this issue: https://github.com/drizzle-team/drizzle-kit-mirror/issues/542
Thank you for your help 😊
Expected behavior
No response
Environment & setup
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 10
- Comments: 15
Commits related to this issue
- fix(drizzle-kit/bin): CHAR SQL type error on RDS Mentioned: https://github.com/drizzle-team/drizzle-orm/issues/3273#issuecomment-2452797795 — committed to NikolaRusakov/drizzle-orm by NikolaRusakov 2 years ago
here’s the patch while we’re waiting for proper fix
agree
So, after updating to the latest versions all the issues are still there.
reproducible with following config:
I’ve compiled all the patches here: https://gist.github.com/larryonward/5c845651b9a9a64875864b7ddcfc7323
drizzle-patch.shin root of your projectchmod +x drizzle-patch.sh./drizzle-patch.shThese are different issues but i’m linking them here because they are related to type casting in drizzle-studio. They make relation visualization / drizzle query editor unusable in the studio.
https://github.com/drizzle-team/drizzle-orm/issues/2583 https://github.com/drizzle-team/drizzle-orm/issues/3409
Would really be awesome if these were fixed 🙏
@valentinbeggi yeah, stumbled on that too.
temporary fixed by adding
here https://github.com/drizzle-team/drizzle-orm/blob/599da5ef7a037904989069596c8879690f9c5322/drizzle-orm/src/aws-data-api/pg/session.ts#L103
(should be a better way)
The patches were working for me but they suddenly stopped today. 😢
@larryonward, thank you for the sed expression.
I made a patch file out of your sed exp for
pnpm patch/npx patch-package. This applies to the latest drizzle-kit version0.28.0https://gist.github.com/NikolaRusakov/88858b5b6a4e1585ca772f40f4e4d559#file-drizzle-kit-0-28-0-patch
I am a several versions behind y’all because I am still experiencing this other issue as well.
I’m still locked at these versions (but i’d love to upgrade)
After combining answers in this thread, I managed to make a patch that works for users of patch-package. its pretty similar to @NikolaRusakov 's fix, but includes the fix for
bind message supplies 0 parametersand also the additionalconstraint_typefixes. (thanks to @larryonward and @valentinbeggi )I’ll share it here to help others:
I hope these issues (and the one related to
regclass)get fixed for folks using RDS soon