Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cast uuid to varchar in postgres when I use sequelize

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

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?

like image 235
lutaoact Avatar asked Jun 18 '15 08:06

lutaoact


People also ask

Does Postgres support UUID?

The uuid-ossp module provides additional functions that implement other standard algorithms for generating UUIDs. PostgreSQL also provides the usual comparison operators shown in Table 9.1 for UUIDs.

What is the data type for UUID in PostgreSQL?

The data type uuid stores Universally Unique Identifiers (UUID) as defined by RFC 4122, ISO/IEC 9834-8:2005, and related standards. (Some systems refer to this data type as a globally unique identifier, or GUID, instead.)


1 Answers

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

{where: ['_id::"varchar" like ?', '%1010%']},
like image 150
lutaoact Avatar answered Oct 11 '22 10:10

lutaoact