Does anyone know how it is possible in postgresql, I have two tables with column type ARRAY and use WHERE, to select the records by this column?

Asked

Viewed 100 times

-3

I have two TABLE . TAB1 and TAB2

TAB1 GROUPS = {11, 15, 13, 20}

TAB2 got the spine:

REG1 GROUPS = {11, 8, 15}

REG2 GROUPS = {21, 5, 7}

REG3 GROUPS = {1, 13, 21}

Make a SELECT using the table column TAB1 [GROUPS] to return : REG1 and REG3 of TAB2

Grateful

  • To avoid assumptions describe which condition should be met to be included in the desired result. In TAB2 you have 3 different columns, named REG1, REG2 and REG3, or these are different rows of the same column?

  • Sorry.. are three lines.! TAB2 has three lines and should return the lines that in the group column have some code in common with TAB1 GROUP

1 answer

0

If in both tables you have a field called GROUPS and want to know which lines have the GROUPS field element(s) in common then use the && (overlap):

SELECT * FROM tab1 INNER JOIN tab2 ON (tab1.grupos && tab2.grupos);
  • Wonder worked!! Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.