I am replacing a legacy function get_data
in our database which takes some entity_id
and returns a refcursor.
I am writing a new function get_data_new
which is using different data sources, but the outputs are expected to be the same as get_data
for the same input.
I'd like to verify this with pgtap, and am doing so as follows within a test (with _expected
and _actual
being the names of the returned cursors):
SELECT schema.get_data('_expected', 123);
SELECT schema.get_data_new('_actual', 123);
SELECT results_eq(
'FETCH ALL FROM _actual',
'FETCH ALL FROM _expected',
'get_data_new should return identical results to the legacy version'
);
This works as expected for other functions, but the query in get_data
happens to return some json
columns meaning that comparison expectedly fails with ERROR: could not identify an equality operator for type json
.
I'd rather leave the legacy function untouched so refactoring to jsonb
isn't possible. I'm imagining a workaround to be transforming the data before comparison, hypothetically with something like SELECT entity_id, json_column::jsonb FROM (FETCH ALL FROM _actual)
, but this specific attempt obviously isn't valid.
What would be a suggested approach here? Write a helper function to insert data from the cursors into a couple of temporary tables? I'm hoping there's a cleaner solution I haven't discovered.
Using postgres 11.14, pgtap11