fix ervu_dashboard.spouse
This commit is contained in:
parent
8e1a2927b7
commit
68b4241930
1 changed files with 44 additions and 31 deletions
|
|
@ -627,37 +627,50 @@
|
|||
<schema_name/>
|
||||
</partitioning>
|
||||
<connection>ervu_person_registry</connection>
|
||||
<sql>with suprug as
|
||||
(select jsonb_array_elements(ri.info->'svedSemPolozh'->'suprugi') supr,
|
||||
ri.info->'svedSemPolozh'->'svedAZBrak'->>'nomerZapis' marriage_az_number,
|
||||
ri.info->'svedSemPolozh'->'svedAZBrak'->>'dataBrakKalend' marriage_date,
|
||||
ri.info->'svedSemPolozh'->'svedAZRazvod'->>'nomerZapis' divorce_az_number,
|
||||
ri.info->'svedSemPolozh'->'svedAZRazvod'->>'dataRastBrakKalend' divorce_date,
|
||||
case when (ri.info->'svedSemPolozh'->>'svedSuprIskl' = '1') then true
|
||||
else false
|
||||
end information_excluded,
|
||||
ri.recruit_id
|
||||
from public.recruits_info ri)
|
||||
select
|
||||
r.id recruit_id,
|
||||
supr->>'rodstvSvyazSuprugNaim' kinship_type,
|
||||
concat_ws(' ', supr->'svedFLBS'->'fio'->>'familiya',
|
||||
supr->'svedFLBS'->'fio'->>'imya',
|
||||
supr->'svedFLBS'->'fio'->>'otchestvo') full_name,
|
||||
make_date(NULLIF(supr->'svedFLBS'->'dataRozhdDok'->>'god', '')::int,
|
||||
NULLIF(supr->'svedFLBS'->'dataRozhdDok'->>'mesyacz','')::int,
|
||||
NULLIF(supr->'svedFLBS'->'dataRozhdDok'->>'den','')::int) birth_date,
|
||||
make_date(NULLIF(supr->'svedSmert'->>'god', '')::int,
|
||||
NULLIF(supr->'svedSmert'->>'mesyacz','')::int,
|
||||
NULLIF(supr->'svedSmert'->>'den','')::int) death_date,
|
||||
supr->'svedSmert'->>'nomerZapis' death_az_number,
|
||||
marriage_az_number,
|
||||
marriage_date,
|
||||
divorce_az_number,
|
||||
divorce_date,
|
||||
information_excluded
|
||||
from public.recruits r
|
||||
join suprug on r.id = suprug.recruit_id</sql>
|
||||
<sql>WITH suprug AS (
|
||||
SELECT
|
||||
supr.supri AS supr,
|
||||
ri.info->'svedSemPolozh'->'svedAZBrak'->>'nomerZapis' AS marriage_az_number,
|
||||
ri.info->'svedSemPolozh'->'svedAZBrak'->>'dataBrakKalend' AS marriage_date,
|
||||
ri.info->'svedSemPolozh'->'svedAZRazvod'->>'nomerZapis' AS divorce_az_number,
|
||||
ri.info->'svedSemPolozh'->'svedAZRazvod'->>'dataRastBrakKalend' AS divorce_date,
|
||||
CASE
|
||||
WHEN (ri.info->'svedSemPolozh'->>'svedSuprIskl' = '1') THEN true
|
||||
ELSE false
|
||||
END AS information_excluded,
|
||||
ri.recruit_id
|
||||
FROM public.recruits_info ri
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT jsonb_array_elements(ri.info->'svedSemPolozh'->'suprugi') AS supri
|
||||
WHERE jsonb_typeof(ri.info->'svedSemPolozh'->'suprugi') = 'array'
|
||||
) AS supr ON true
|
||||
)
|
||||
SELECT
|
||||
r.id AS recruit_id,
|
||||
supr->>'rodstvSvyazSuprugNaim' AS kinship_type,
|
||||
CONCAT_WS(' ',
|
||||
supr->'svedFLBS'->'fio'->>'familiya',
|
||||
supr->'svedFLBS'->'fio'->>'imya',
|
||||
supr->'svedFLBS'->'fio'->>'otchestvo'
|
||||
) AS full_name,
|
||||
MAKE_DATE(
|
||||
NULLIF(supr->'svedFLBS'->'dataRozhdDok'->>'god', '')::int,
|
||||
NULLIF(supr->'svedFLBS'->'dataRozhdDok'->>'mesyacz','')::int,
|
||||
NULLIF(supr->'svedFLBS'->'dataRozhdDok'->>'den','')::int
|
||||
) AS birth_date,
|
||||
MAKE_DATE(
|
||||
NULLIF(supr->'svedSmert'->>'god', '')::int,
|
||||
NULLIF(supr->'svedSmert'->>'mesyacz','')::int,
|
||||
NULLIF(supr->'svedSmert'->>'den','')::int
|
||||
) AS death_date,
|
||||
supr->'svedSmert'->>'nomerZapis' AS death_az_number,
|
||||
marriage_az_number,
|
||||
marriage_date,
|
||||
divorce_az_number,
|
||||
divorce_date,
|
||||
information_excluded
|
||||
FROM public.recruits r
|
||||
JOIN suprug ON r.id = suprug.recruit_id;</sql>
|
||||
<limit>0</limit>
|
||||
<lookup/>
|
||||
<execute_each_row>N</execute_each_row>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue