我有一列类型为 int2[] 数组。我想对此列进行 IN 查询。
我在谷歌上搜索它,发现 @> 运算符在数组列中搜索,但它似乎不适用于 int2 类型的数组列。但它适用于 int[]
有谁知道为什么它在 int2[] 上不起作用?
ecabuk=# CREATE TABLE "Test"("Column1" int2[]);
CREATE TABLE
ecabuk=# INSERT INTO "Test" VALUES ('{10, 15, 20}');
INSERT 0 1
ecabuk=# INSERT INTO "Test" VALUES ('{10, 20, 30}');
INSERT 0 1
ecabuk=# EXPLAIN ANALYZE SELECT * FROM "Test" WHERE "Column1" @> ARRAY[20];
ERROR: operator does not exist: smallint[] @> integer[]
LINE 1: ...LAIN ANALYZE SELECT * FROM "Test" WHERE "Column1" @> ARRAY[2...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
ecabuk=# ALTER TABLE "Test" ALTER COLUMN "Column1" type int[];
ALTER TABLE
ecabuk=# EXPLAIN ANALYZE SELECT * FROM "Test" WHERE "Column1" @> ARRAY[20];
QUERY PLAN
--------------------------------------------------------------------------------------------------
Seq Scan on "Test" (cost=0.00..26.38 rows=7 width=32) (actual time=0.200..0.204 rows=2 loops=1)
Filter: ("Column1" @> '{20}'::integer[])
Total runtime: 0.256 ms
(3 rows)
ecabuk=#