我想使用 TypeORM 在 Postgres 的陣列中搜索 cookieId。這個問題的答案在這里給出:How do I query an array in TypeORM
但是,當我實作代碼時:
user = await this.usersRepository
.createQueryBuilder('user')
.where('user.userCookieIds @> ARRAY[:cookieId]', {cookieId: userCookieId})
.getOne();
相關物體是:
@Column("varchar", { array: true })
userCookieIds: string[];
我收到一個錯誤:
QueryFailedError: operator does not exist: character varying[] @> text[]
在這種情況下,我如何cookieId在 postgres 中指定型別,所以它也是varchar?
uj5u.com熱心網友回復:
您應該能夠將值轉換為正確的型別:
user = await this.usersRepository
.createQueryBuilder('user')
.where('user.userCookieIds @> ARRAY[:cookieId]::varchar[]', {cookieId: userCookieId})
.getOne();
您還可以更改列以使用文本陣列而不是 varchar:https ://stackoverflow.com/a/4849030/735398
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/454604.html
標籤:PostgreSQL 巢穴 打字机
下一篇:CentOS7 安裝MySQL5.7企業版(商業版)及修改my.cnf默認datadir、socket路徑后無法啟動的處理方法
