E
E
Eugene Vdovenko2015-02-10 14:20:31
PostgreSQL
Eugene Vdovenko, 2015-02-10 14:20:31

Is it possible to do a native SELECT in PostgreSQL on an int[] field?

There are 2 tables. In the first - a list of articles, in the second - a list of categories. One article can belong to several categories. To do this, the table with articles has a field of type int[] (array) with category IDs. Is it possible to select articles with category names with a simple SELECTOM? Or do you need to get confused with functions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
krypt3r, 2015-02-10
@krypt3r

It is possible, type SELECT * FROM table WHERE 17 = ANY(id) It is
possible to put GIN indexes.
Take a closer look at the manual, which describes arrays. Everything is there

E
Eugene Vdovenko, 2015-02-10
@Misanthropist

Using

SELECT * FROM table WHERE 17 = ANY(id)
duplicate results will be blown out, but you need one result with all the category names, id that is in the record.
About indexes - thanks for tipping, now I will esteem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question