2

I have polygon(properties) in postgis table and have a info of excel which need to join on posting table property. But it's not simple join it based on two column with matching individual column with separated value by "," .

Postgis table enter image description here

Excel table enter image description here

I want match if any of comma seperated match the value in respective column. In above case all should be matched.

So far I tried this script but not work good.

SELECT tbl1.gid, id,tbl1.matchid1,cast(tbl2."matchid1" AS varchar) ,  tbl1.matchid2,cast(tbl2.matchid2 AS varchar),  tbl1.geom
    FROM public.tbl1 tbl1 left join  tbl2 on (cast(tbl1.matchid1 AS varchar) ~~ cast(tbl2.matchid1 AS varchar)) or
    (cast(tbl1.matchid2 AS varchar) ~~ cast(tbl2.matchid2 AS varchar))
1
  • If you also want to ask the question from an ArcGIS perspective then please do that in a separate question so that you can describe what you have tried to do with that, and where you are stuck with it.
    – PolyGeo
    Commented Jul 14, 2017 at 6:03

1 Answer 1

2

Don't try this with regex comparison. Since your data is already nicely delimited with comma's, just put it into arrays. Here is the way to go: Make new array columns (type TEXT[]) to your tables where you use the function string_to_array(matchid1,',') Join the tables based on matching array values tbl1.matchid2_array && tbl2.matchid2

If this is still slow (it probably is) then make sure you build indexes on the new array columns.

1
  • Can you show sample Code? is It based on "Join"? Commented Jul 19, 2017 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.