Feature(s) impacted
Hi,
I have an issue while searching in a specific table, in which I’ve had to include field renaming. In more details:
My table is defined as follow:
const ShopItem = sequelize.define('shopItem', {
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
},
price: {
type: DataTypes.DOUBLE,
allowNull: false,
},
category: {
type: DataTypes.ENUM(
'discount',
'print',
'goodies',
'undefined',
),
field: 'category',
defaultValue: "undefined",
allowNull: false,
},
couponLink: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
},
picture1: {
type: DataTypes.STRING,
field: 'picture_1',
allowNull: false,
},
picture1ld: {
type: DataTypes.STRING,
field: 'picture_1_ld',
},
picture2: {
type: DataTypes.STRING,
field: 'picture_2',
},
picture2ld: {
type: DataTypes.STRING,
field: 'picture_2_ld',
},
picture3: {
type: DataTypes.STRING,
field: 'picture_3',
},
picture3ld: {
type: DataTypes.STRING,
field: 'picture_3_ld',
},
quantity: {
type: DataTypes.INTEGER,
},
descriptionFr: {
type: DataTypes.STRING,
},
descriptionEs: {
type: DataTypes.STRING,
},
descriptionEn: {
type: DataTypes.STRING,
},
howToUseFr: {
type: DataTypes.STRING,
},
howToUseEs: {
type: DataTypes.STRING,
},
howToUseEn: {
type: DataTypes.STRING,
},
tag: {
type: DataTypes.STRING,
field: 'testTag',
},
isValidated: {
type: DataTypes.BOOLEAN,
field: 'validate',
defaultValue: false,
},
}, {
tableName: 'shop_item',
underscored: true,
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
As you can see, the last two columns, “validate” and “testTag” has been renamed in respectively “isValidated” and “tag” to avoid previous issues I had:
- I renamed “validate” to avoid interaction with Sequelize built-in method
- I renamed “testTag” cause Forest will look for “test_tag” in DB instead of testTag
Anyway, it sounds to me that this renaming has unexpected side effects when searching within the table in certain cases.
Observed behavior
When searching within this table, I’ve got this error :
Executing (default): SELECT "id", "price", "category", "coupon_link" AS "couponLink", "created_at" AS "createdAt", "picture_1" AS "picture1", "picture_1_ld" AS "picture1ld", "picture_2" AS "picture2", "picture_2_ld" AS "picture2ld", "picture_3" AS "picture3", "picture_3_ld" AS "picture3ld", "quantity", "description_fr" AS "descriptionFr", "description_es" AS "descriptionEs", "description_en" AS "descriptionEn", "how_to_use_fr" AS "howToUseFr", "how_to_use_es" AS "howToUseEs", "how_to_use_en" AS "howToUseEn", "testTag" AS "tag", "validate" AS "isValidated", "owner_id" AS "ownerIdKey" FROM "shop_item" AS "shopItem" WHERE (lower("shopItem"."coupon_link") LIKE lower('%s%') OR lower("shopItem"."picture_1") LIKE lower('%s%') OR lower("shopItem"."picture_1_ld") LIKE lower('%s%') OR lower("shopItem"."picture_2") LIKE lower('%s%') OR lower("shopItem"."picture_2_ld") LIKE lower('%s%') OR lower("shopItem"."picture_3") LIKE lower('%s%') OR lower("shopItem"."picture_3_ld") LIKE lower('%s%') OR lower("shopItem"."description_fr") LIKE lower('%s%') OR lower("shopItem"."description_es") LIKE lower('%s%') OR lower("shopItem"."description_en") LIKE lower('%s%') OR lower("shopItem"."how_to_use_fr") LIKE lower('%s%') OR lower("shopItem"."how_to_use_es") LIKE lower('%s%') OR lower("shopItem"."how_to_use_en") LIKE lower('%s%') OR lower("shopItem"."testTag") LIKE lower('%s%')) LIMIT 10 OFFSET 0;
[forest] 🌳🌳🌳 Unexpected error: function lower(boolean) does not exist
{
"name": "SequelizeDatabaseError",
"parent": {
"length": 209,
"name": "error",
"severity": "ERROR",
"code": "42883",
"hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
"position": "1335",
"file": "parse_func.c",
"line": "627",
"routine": "ParseFuncOrColumn",
"sql": "SELECT \"id\", \"price\", \"category\", \"coupon_link\" AS \"couponLink\", \"created_at\" AS \"createdAt\", \"picture_1\" AS \"picture1\", \"picture_1_ld\" AS \"picture1ld\", \"picture_2\" AS \"picture2\", \"picture_2_ld\" AS \"picture2ld\", \"picture_3\" AS \"picture3\", \"picture_3_ld\" AS \"picture3ld\", \"quantity\", \"description_fr\" AS \"descriptionFr\", \"description_es\" AS \"descriptionEs\", \"description_en\" AS \"descriptionEn\", \"how_to_use_fr\" AS \"howToUseFr\", \"how_to_use_es\" AS \"howToUseEs\", \"how_to_use_en\" AS \"howToUseEn\", \"testTag\" AS \"tag\", \"validate\" AS \"isValidated\", \"owner_id\" AS \"ownerIdKey\" FROM \"shop_item\" AS \"shopItem\" WHERE (lower(\"shopItem\".\"coupon_link\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_1\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_1_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_2\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_2_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_3\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_3_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_fr\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_es\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_en\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_fr\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_es\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_en\") LIKE lower('%s%') OR lower(\"shopItem\".\"testTag\") LIKE lower('%s%')) LIMIT 10 OFFSET 0;"
},
"original": {
"length": 209,
"name": "error",
"severity": "ERROR",
"code": "42883",
"hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
"position": "1335",
"file": "parse_func.c",
"line": "627",
"routine": "ParseFuncOrColumn",
"sql": "SELECT \"id\", \"price\", \"category\", \"coupon_link\" AS \"couponLink\", \"created_at\" AS \"createdAt\", \"picture_1\" AS \"picture1\", \"picture_1_ld\" AS \"picture1ld\", \"picture_2\" AS \"picture2\", \"picture_2_ld\" AS \"picture2ld\", \"picture_3\" AS \"picture3\", \"picture_3_ld\" AS \"picture3ld\", \"quantity\", \"description_fr\" AS \"descriptionFr\", \"description_es\" AS \"descriptionEs\", \"description_en\" AS \"descriptionEn\", \"how_to_use_fr\" AS \"howToUseFr\", \"how_to_use_es\" AS \"howToUseEs\", \"how_to_use_en\" AS \"howToUseEn\", \"testTag\" AS \"tag\", \"validate\" AS \"isValidated\", \"owner_id\" AS \"ownerIdKey\" FROM \"shop_item\" AS \"shopItem\" WHERE (lower(\"shopItem\".\"coupon_link\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_1\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_1_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_2\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_2_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_3\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_3_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_fr\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_es\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_en\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_fr\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_es\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_en\") LIKE lower('%s%') OR lower(\"shopItem\".\"testTag\") LIKE lower('%s%')) LIMIT 10 OFFSET 0;"
},
"sql": "SELECT \"id\", \"price\", \"category\", \"coupon_link\" AS \"couponLink\", \"created_at\" AS \"createdAt\", \"picture_1\" AS \"picture1\", \"picture_1_ld\" AS \"picture1ld\", \"picture_2\" AS \"picture2\", \"picture_2_ld\" AS \"picture2ld\", \"picture_3\" AS \"picture3\", \"picture_3_ld\" AS \"picture3ld\", \"quantity\", \"description_fr\" AS \"descriptionFr\", \"description_es\" AS \"descriptionEs\", \"description_en\" AS \"descriptionEn\", \"how_to_use_fr\" AS \"howToUseFr\", \"how_to_use_es\" AS \"howToUseEs\", \"how_to_use_en\" AS \"howToUseEn\", \"testTag\" AS \"tag\", \"validate\" AS \"isValidated\", \"owner_id\" AS \"ownerIdKey\" FROM \"shop_item\" AS \"shopItem\" WHERE (lower(\"shopItem\".\"coupon_link\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_1\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_1_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_2\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_2_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_3\") LIKE lower('%s%') OR lower(\"shopItem\".\"picture_3_ld\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_fr\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_es\") LIKE lower('%s%') OR lower(\"shopItem\".\"description_en\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_fr\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_es\") LIKE lower('%s%') OR lower(\"shopItem\".\"how_to_use_en\") LIKE lower('%s%') OR lower(\"shopItem\".\"testTag\") LIKE lower('%s%')) LIMIT 10 OFFSET 0;",
"stack": "SequelizeDatabaseError: function lower(boolean) does not exist\n at Query.formatError
However, if I remove these two alias fields “isValidated” and “tag” from my schema, I no longer have any error and everything is fine.
Do you think that the alias could induced unexpected behavior in SQL request? I’ve also have this issue with another table having an alias, while I don’t have any issues when tables does not have any alias.
Thanks a lot for your feedback.
Have a nice day,
C.
Context
- Project name: BavAR[t]
- Team name: Operation
- Environment name: Dev & production
- Agent type & version: …
- Recent changes made on your end if any: …