postgresql 当我使用 sequelize 时,将 uuid 转换为 postgres 中的 varchar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30910248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:56:15  来源:igfitidea点击:

cast uuid to varchar in postgres when I use sequelize

postgresqluuidsequelize.js

提问by lutaoact

I have a table with a column named _idof which the type is uuid. I cast the type of _idfrom uuidto varchar, in order to select the records as follows:

我有一个表_id,其中有一列名为uuid. 我将_idfrom的类型转换为uuidto varchar,以便按如下方式选择记录:

SELECT "_id" FROM "records" WHERE "_id"::"varchar" LIKE '%1010%';

and it works well.

它运作良好。

                 _id                  
--------------------------------------
 9a7a36d0-1010-11e5-a475-33082a4698d6
(1 row)

I use sequelize as ORM for operation postgres. how to build the query condition in sequelize?

我使用 sequelize 作为 ORM 来操作 postgres。如何在sequelize中建立查询条件?

回答by lutaoact

I write the query condition as follows, and it works well. Is there any better solution?

我把查询条件写成如下,效果很好。有没有更好的解决办法?

{where: ['_id::"varchar" like ?', '%1010%']},