SOLVED: PgArray returning most values, but one `NaN`?

I have a postgres view that is performing a string_agg. I've mapped it to drizzle as shown below. When querying it, most of the values are correct, but each array contains one NaN value. Querying the database directly returns all values correctly. What is my best strategy to debug this? Logging the query shows nothing unusual.
export const viewsSchema = pgSchema('views')
const optionsByReleaseWithGroups = viewsSchema
.view('options_by_group_and_subgroup_by_release', {
releaseId: integer('release_id').notNull(),
id: integer('option_id').notNull(),
name: text('version_name').notNull(),
wholesalePrice: integer('version_wholesale_price'),
uom: text('version_uom').notNull(),
groupId: integer('group_id'),
groupName: text('group_name'),
subgroupId: integer('subgroup_id'),
subgroupName: text('subgroup_name'),
packageOnly: boolean('version_package_only'),
optionType: text('option_type').notNull(),
_versionId: integer('version_id').notNull(),
seriesId: integer('series_id').notNull(),
// vvv PROBLEM FIELD vvv
modelIds: integer('model_ids').array(),
// ^^^ PROBLEM FIELD ^^^
})
.existing()
export const viewsSchema = pgSchema('views')
const optionsByReleaseWithGroups = viewsSchema
.view('options_by_group_and_subgroup_by_release', {
releaseId: integer('release_id').notNull(),
id: integer('option_id').notNull(),
name: text('version_name').notNull(),
wholesalePrice: integer('version_wholesale_price'),
uom: text('version_uom').notNull(),
groupId: integer('group_id'),
groupName: text('group_name'),
subgroupId: integer('subgroup_id'),
subgroupName: text('subgroup_name'),
packageOnly: boolean('version_package_only'),
optionType: text('option_type').notNull(),
_versionId: integer('version_id').notNull(),
seriesId: integer('series_id').notNull(),
// vvv PROBLEM FIELD vvv
modelIds: integer('model_ids').array(),
// ^^^ PROBLEM FIELD ^^^
})
.existing()
1 Reply
catfive
catfiveOP2w ago
This has been solved by my teammate—the key was to cast to integer in the postgres view itself: array_agg(mbr.models_id order by mbr.models_id) :: int[] as model_ids

Did you find this page helpful?