There is a table 1 with string fields. f1, f2, f3, f4, ....
There is a table 2 with json arrays f1, f2, f3, f4, ...
Sample data:
Table 1: - Line 1 f1 = 'AB' f2 = 'CD' f3 = 'AD' f4 = 'P' - Line 2 f1 = 'AA' f2 = 'BB' f3 = 'CC' f4 = null Table 2: f1 = ['AA', 'BB'] f2 = ['CD', 'BB'] f3 = ['AD', 'CC', 'BB'] f4 = ['AB', 'CD', null]
I want to find a row from table 1, knowing the row from table 2. Of course, I can do this using php, but I want to get a result in one query. The search should be done like this: where t1 in ['AA', 'BB']
Matches must be counted for all columns. I can not figure out how to build a query and whether null will work.
json_array_elements
exactly what you need - Mikeselect '"BB"' in (select json_array_elements('["AA","BB","CC",null]')::text);
returns true, but there should be no quotes. Without quotes false - ilyaplot