Repository navigation
Closed
Description
What am i doing?
Trying to access int4range data in postgresql, model find returning no actual data, just empty arrays
Here's my model
var Activity = sequelize.define('activity', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true
},
type: {
type: Sequelize.ENUM('user', 'default'),
allowNull: false
},
approved: {
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false
},
name: {
type: Sequelize.STRING,
allowNull: false,
trim: true
},
description: {
type: Sequelize.STRING,
allowNull: false,
trim: true
},
content: {
type: Sequelize.TEXT,
trim: true
},
ageRange: {
type: Sequelize.RANGE(Sequelize.INTEGER)
},
userRange: {
type: Sequelize.RANGE(Sequelize.INTEGER)
},
timeRange: {
type: Sequelize.RANGE(Sequelize.INTEGER)
}
}
);
Activity.belongsTo(User, {as: 'creator'});Here's the code that's trying to access it:
/**
* List of Articles
*/
exports.list = function(req, res) {
Activity.findAll()
.then(function(activitys){
console.log(activitys[0].dataValues.ageRange);
return res.send(activitys);
})
.catch(function(err){
return res.status(400).send(err);
});
};I have a single row in the db with the ageRange having this value: [8, 77)
What do i expect to happen?
I expect the find query to return the in the response of the query.
What is actually happening?
The output for the request is this:
[
{
"id": "2108125d-3bfb-4c8f-9f37-5fa0df793179",
"type": "user",
"approved": false,
"name": "Party",
"description": "Throw a party",
"content": null,
"ageRange": [
[],
[]
],
"userRange": null,
"timeRange": null,
"createdAt": "2016-11-19T13:20:50.451Z",
"updatedAt": "2016-11-19T13:20:50.472Z",
"creatorId": "a0abee24-698e-4218-a5f2-d63d6ab69e28"
}
]and the console.log is outputting this:
[ [], [], inclusive: [ true, false ] ]
Dialect: postgres
Database version: PostgreSQL 9.5.5 running on ubuntu
Sequelize version: [email protected]
Metadata
Metadata
Assignees
Labels
No labels
Activity
FREEZX commentedon Nov 19, 2016
Found the core of the issue and submitted PR #6897.
The oid_map array defines int4 as internal value 1007
https://github.com/sequelize/sequelize/blob/v3/lib/dialects/postgres/data-types.js#L341
while the postgres parser defines that as an array of integers.
https://github.com/brianc/node-pg-types/blob/master/lib/textParsers.js#L155
And sequelize tries to parse each number as an array, which clearly gives out empty arrays.
https://github.com/sequelize/sequelize/blob/v3/lib/dialects/postgres/range.js#L70
janmeier commentedon Nov 23, 2016
Good work, thanks for taking the timing to scratch your own itch ;)