postgresql - @> Operator not working on int2[] type -
i have column type of int2[] array. , want create in query on column.
i search on google , found @> operator search in array columns seems not working on int2 type array columns. works on int[]
has know why doesn't work on int2[]?
ecabuk=# create table "test"("column1" int2[]); create table ecabuk=# insert "test" values ('{10, 15, 20}'); insert 0 1 ecabuk=# insert "test" values ('{10, 20, 30}'); insert 0 1 ecabuk=# explain analyze select * "test" "column1" @> array[20]; error: operator not exist: smallint[] @> integer[] line 1: ...lain analyze select * "test" "column1" @> array[2... ^ hint: no operator matches given name , argument type(s). might need add together explicit type casts. ecabuk=# alter table "test" alter column "column1" type int[]; alter table ecabuk=# explain analyze select * "test" "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=#
when specify array[20] treating int[] rather int2[]. suitable casts create behave.
test=# explain analyze select * "test" "column1" @> array[2]; error: operator not exist: smallint[] @> integer[] line 1: ...lain analyze select * "test" "column1" @> array[2... ^ hint: no operator matches given name , argument type(s). might need add together explicit type casts. test=# explain analyze select * "test" "column1" @> array[20::int2]; query plan -------------------------------------------------------------------------------------------------- seq scan on "test" (cost=0.00..26.38 rows=7 width=32) (actual time=0.060..0.064 rows=2 loops=1) filter: ("column1" @> '{20}'::smallint[]) total runtime: 0.116 ms (3 rows) test=# explain analyze select * "test" "column1" @> array[20]::int2[]; query plan -------------------------------------------------------------------------------------------------- seq scan on "test" (cost=0.00..26.38 rows=7 width=32) (actual time=0.028..0.032 rows=2 loops=1) filter: ("column1" @> '{20}'::smallint[]) total runtime: 0.080 ms (3 rows) postgresql
No comments:
Post a Comment