Advanced PostgreSQL functions like json_to_recordset(json) / jsonb_to_recordset(jsonb)

Thanks @charettes, this example was very helpful. I did find that I needed to alter this part of the snippet:

params = lhs_params + rhs_params

to

params.extend(rhs_params)

to avoid

     20 lhs, lhs_params = self.process_lhs(compiler, connection)
     21 rhs, rhs_params = self.process_rhs(compiler, connection)
---> 22 params = lhs_params + rhs_params

TypeError: can only concatenate tuple (not "list") to tuple

The reason being that Lookup.get_db_prep_lookup() returns ("%s", [value]).

Grepping through django/db/models/lookups.py, extend or append seems to be the norm, except for Regex, which does the lhs_params + rhs_params, but maybe that works because there’s a prepare_rhs = False attribute? Haven’t looked into it.

Do you think there’s a best pattern for dealing with the params, or do you think there’s an edge here we can soften?