hasura / hasura/graphql-engine

When changing the materialized view column data type from json to jsonb all dependent functions throwing error while querying from console

Open
#9,054 0 comments 0 reactions 0 assignees View on GitHub
k/bug t/native-dbs
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version : 2.9.0

### What is the current behaviour?

We have a materialized view created by following DDL

CREATE MATERIALIZED VIEW roles_and_criteria_mv AS
SELECT rp.role_id,
rp.product,
rp.subproduct,
rp.criteria_type,
json_agg(DISTINCT rp.criteria_value) AS criteria_values
FROM common.role_profile rp
GROUP BY rp.role_id, rp.product, rp.subproduct, rp.criteria_type;

and a dependent function

CREATE OR REPLACE FUNCTION vam.get_entitled_top_accounts_fn(hasura_session json)
RETURNS SETOF vam.account_datagrouping_out
LANGUAGE sql
STABLE
AS $function$ WITH entitled_accs AS (
select vam.get_all_entitled_accounts_fn(hasura_session) as criteria_values
)
SELECT
va.account_id,
va.account_guid,
va.account_name,
'2' AS is_physical,
va.account_type,
va.parent_id,
va.isparent_physical,
va.bank_entityid,
va.prefix,
va.product_id,
va.status,
pa.corporate_name,
pa.corporate_guid,
pa.currency,
pa.country,
va.physical_accountguid,
pa.account_name AS physical_accountname,
pa.account_number AS physical_accountnumber,
bal.ledger_balance,
bal.rolledup_balance,
bal.available_balance,
bal.value_balance,
bal.created_at AS balance_created_at,
bal.updated_at AS balance_updated_at,
bal.lien_amount,
bal.unconfirm_credamount,
bal.rolledup_valuebalance,
bal.reporting_balance,
bal.rolledup_reportingbalance,
bal.latest_activity,
va.acc_name_number,
(
select
common.convert_ref_ccy(
hasura_session, va.currency, bal.available_balance
)
).amount_in_refccy as available_balance_inrefccy,
(
select
common.get_rate_ref_ccy(hasura_session, va.currency)
) as exchange_rate_inrefccy,
va.parent_ids
from
vam.virtual_acctbalance_master bal
join (
vam.physical_account_master pa
inner join vam.virtual_account_master va on va.status = 'ACTIVE' :: text
and va.corporate_guid = any (
array (
select
json_array_elements_text(
json_agg(
arr.item_object -> 'customer_guid'
)
)
from
common.domains d,
jsonb_array_elements(d.domain_entities) with ordinality arr(item_object, position)
where
d.domain_guid = (
hasura_session ->> 'x-hasura-domain-id'
) :: text
)
)
and (
va.account_guid in (
select
json_array_elements_text(criteria_values :: json)
from
entitled_accs
)
)
and (
not (
(
array(
select
json_array_elements_text(criteria_values :: json)
from
entitled_accs
)
) && (
array(
select
json_array_elements_text(va.parent_ids :: json)
)
)
)
)
and pa.account_guid = va.physical_accountguid
) ON bal.account_guid = va.account_guid
AND bal.currency = va.currency
union all
SELECT
pa.account_number AS account_id,
pa.account_guid,
pa.account_name,
'1' AS is_physical,
'PHYSICAL' :: text AS account_type,
NULL :: text AS parent_id,
false AS isparent_physical,
pa.bank_entityid,
NULL :: text AS prefix,
NULL :: text AS product_id,
'ACTIVE' :: text AS status,
pa.corporate_name,
pa.corporate_guid,
pa.currency,
pa.country,
pa.account_guid AS physical_accountguid,
pa.account_name AS physical_accountname,
pa.account_number AS physical_accountnumber,
pa.ledger_balance :: numeric AS ledger_balance,
NULL :: numeric AS rolledup_balance,
NULL :: numeric AS available_balance,
pa.value_balance :: numeric AS value_balance,
NULL :: timestamp with time zone AS balance_created_at,
NULL :: timestamp with time zone AS balance_updated_at,
NULL :: numeric AS lien_amount,
NULL :: numeric AS unconfirm_credamount,
NULL :: numeric AS rolledup_valuebalance,
NULL :: numeric AS reporting_balance,
NULL :: numeric AS rolledup_reportingbalance,
pa.latest_activity,
pa.account_name || pa.account_number AS acc_name_number,
(
select
common.convert_ref_ccy(
hasura_session, pa.currency, pa.value_balance
)
).amount_in_refccy as available_balance_inrefccy,
(
select
common.get_rate_ref_ccy(hasura_session, pa.currency)
) as exchange_rate_inrefccy,
NULL :: JSONB parent_ids
FROM
vam.primary_physical_accounts_vw pa
where
pa.corporate_guid = ANY (
ARRAY (
SELECT
json_array_elements_text(
json_agg(
arr.item_object -> 'customer_guid'
)
)
FROM
common.domains d,
jsonb_array_elements(d.domain_entities) WITH ORDINALITY arr(item_object, POSITION)
WHERE
d.domain_guid = (
hasura_session ->> 'x-hasura-domain-id'
) :: text
)
)
and (
pa.account_guid in (
select
json_array_elements_text(criteria_values :: json)
from
entitled_accs
)
) $function$

we have changed the column type of criertia_values in the roles_and_criteria_mv materialized view to jsonb using jsonb_agg.When querying the dependent function 'get_entitled_top_accounts_fn' from the Hasura console getting error :

"error": {
"description": null,
"exec_status": "FatalError",
"hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
"message": "function json_array_elements_text(jsonb) does not exist",

And the dependent function worked when directly querying from Postgres.

Contributor guide

Open the contributing guide

Research direction

Start with the roles_and_criteria_mv DDL and the get_entitled_top_accounts_fn definition, then reproduce the query from the Hasura console after changing criteria_values from json to jsonb. Compare the console failure with the successful direct PostgreSQL query; done means the dependent function can be queried through Hasura without the json_array_elements_text(jsonb) error.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql
Domain
api, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.