Re: query on smallint array column

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Zhihong Yu <zyu(at)yugabyte(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: query on smallint array column
Date: 2020-12-13 17:50:47
Message-ID: CAFj8pRAT7PuwiUuSv57k+cZ+UenJnMfrWr7P8oRfxtTGUuU-Tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

ne 13. 12. 2020 v 18:42 odesílatel Zhihong Yu <zyu(at)yugabyte(dot)com> napsal:

> Hi,
> I was experimenting with the following query.
>
> create table sint1(k int primary key, arr smallint[]);
> create index s1 on sint1(arr);
> insert into sint1 select s, array[s*s, s] FROM generate_series(1, 10) AS s;
> select * from sint1 where arr @> array[4];
> ERROR: operator does not exist: smallint[] @> integer[]
> LINE 1: select * from sint1 where arr @> array[4];
> ^
> HINT: No operator matches the given name and argument types. You might
> need to add explicit type casts.
> -------
>
> I wonder if someone can enlighten me on the correct way to perform the
> type cast.
>

postgres=# select * from sint1 where arr @> array[4::smallint];
┌───┬────────┐
│ k │ arr │
╞═══╪════════╡
│ 2 │ {4,2} │
│ 4 │ {16,4} │
└───┴────────┘
(2 rows)

postgres=# select * from sint1 where arr @> array[4]::smallint[];
┌───┬────────┐
│ k │ arr │
╞═══╪════════╡
│ 2 │ {4,2} │
│ 4 │ {16,4} │
└───┴────────┘
(2 rows)

postgres=#

>
> Thanks
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhihong Yu 2020-12-13 18:42:09 Re: query on smallint array column
Previous Message Zhihong Yu 2020-12-13 17:43:10 query on smallint array column