Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with retrieving the jsonb columns #11

Open
sudhirmadyp opened this issue Jun 16, 2022 · 0 comments
Open

Issue with retrieving the jsonb columns #11

sudhirmadyp opened this issue Jun 16, 2022 · 0 comments

Comments

@sudhirmadyp
Copy link

Initially my SQL query is as follows:
$survey_answers = DB::Select(DB::raw(" SELECT survey_id, trigger_survey_id, cast((arr.response->>'q_id') as integer)as question_id, cast(((arr.response->'answer')->>'score') as decimal) as score, trim(lower(email)) as email FROM survey_answers, jsonb_array_elements(response) with ordinality arr(response,position) where submission='complete' and survey_id=2 and trigger_survey_id=4 and ((arr.response->'answer')->>'score') is not null group by 5,1,2,3,4 "));

But the output after conversion I got is as follows :
DB::table("survey_answers, jsonb_array_elements where_subquery_group_4_ with ordinality arr where_subquery_group_5_") ->select("survey_id", "trigger_survey_id", "cast ((arr.response->>'q_id') as integer) as question_id", "cast (((arr.response->'answer')->>'score') as decimal) as score", "trim (lower(email)) as email") ->where("submission", "=", complete) ->where("survey_id", "=", 2) ->where("trigger_survey_id", "=", 4) ->groupBy("5") ->get();

Please help me with retrieving the jsonb columns wise data extraction into Laravel Eloquent

Thanks In Advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant