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

Sql parsing problem #15

Open
bobitza opened this issue Jul 3, 2024 · 0 comments
Open

Sql parsing problem #15

bobitza opened this issue Jul 3, 2024 · 0 comments

Comments

@bobitza
Copy link

bobitza commented Jul 3, 2024

This sql is not parsed corectly

select
	pad_data.id,
	coalesce(apps.slug,
	blapps.slug,
	'') as slug,
	case
		when (
		select
			id
		from
			ai_responses
		where
			pad_urls_id = pad_data.id) > 0 then 1
		else 0
	end ai_published,
	case
		when ( (
		select
			COUNT(pad_urls_id)
		from
			pad_apk_crawler
		where
			pad_urls_id = pad_data.id
			and is_done = true
			and step = 'finished'
			and last_version <> '') > 0
		or ((pad_data.pflags ? 'has_apk'
			or pad_data.pflags ? 'has_xapk')
		and (pad_content.override #>> '{primary_download_url}' like 'apk://%'
			or pad_content.override #>> '{primary_download_url}' like 'dld://%')) ) then 1
		else 0
	end have_apk,
	pad_data.status,
	pad_data.tries,
	pad_data.created_at,
	pad_data.updated_at,
	pad_data.response,
	pad_data.valid_status,
	pad_data.priority,
	pad_data.validated_at,
	pad_data.download,
	pad_data.lang_id,
	pad_data.lang_score,
	coalesce(apps.views_total,
	blapps.views_total,
	0) as views_total,
	coalesce(apps.views_month1,
	blapps.views_month1,
	0) as views_month1,
	coalesce(apps.views_week1,
	blapps.views_week1,
	0) as views_week1,
	coalesce(apps.views_day1,
	blapps.views_day1,
	0) as views_day1,
	coalesce(apps.have_review,
	blapps.have_review,
	false) as have_review,
	initcap(coalesce(apps.ad_type,
	blapps.ad_type,
	'')) as ad_type,
	coalesce((apps_data.json_review ->> 'publish_date'::text),
	(blapps_data.json_review ->> 'publish_date'::text),
	'') as review_publish_date,
	coalesce(app_info.distrib_status,
	'') as distrib_status,
	coalesce(app_info.distrib_at,
	'1970-01-01') as distrib_at,
	coalesce(app_info.sync_at,
	'1970-01-01') as sync_at,
	coalesce(app_info.sync_status,
	'') as sync_status,
	pad_content.json_data #>> '{xml_diz_info,program_info,program_name}' as program_name,
	pad_content.json_data #>> '{xml_diz_info,company_info,company_name}' as company_name,
	case
		when apps.id is not null then 1
		else 0
	end is_visible,
	case
		when blapps.id is not null then 1
		else 0
	end is_blacklisted,
	case
		when apps.id is not null then 1
		else case
			when blapps.id is not null then 2
			else 0
		end
	end is_active
from
	pad_data
left join live_website.apps on
	(pad_data.id = apps.id)
left join live_website.apps_data on
	(pad_data.id = apps_data.id)
left join website_soft112.blapps on
	(pad_data.id = blapps.id)
left join website_soft112.blapps_data on
	(pad_data.id = blapps_data.id)
left join website_soft112.app_info on
	(pad_data.id = app_info.id)
left join pad_content on
	pad_data.id = pad_content.id
left join ai_responses on
	(pad_data.id = ai_responses.pad_urls_id
		and ai_responses.is_active = true
		and ai_responses.published <> '')
order by
	pad_data.id asc
limit 25 offset 0
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