Spaces:
Sleeping
Sleeping
refact: "Nova query com datas para identificação do problema"
Browse files
query.sql
CHANGED
@@ -1,26 +1,38 @@
|
|
1 |
SELECT
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
COALESCE(NULLIF(mineralization->'region'->>'
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
SELECT jsonb_extract_path_text(concentration, 'name_of_ore') || ' - (' || jsonb_extract_path_text(concentration, 'concentration_of_ore') || ')'
|
14 |
FROM jsonb_array_elements(mineralization->'concentration') AS concentration
|
15 |
), ', '), ''), 'Não especificado') AS "Concentração de mineralização",
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
COALESCE(NULLIF(mineralization->'geological_context'->>'tectonic_context', ''), 'Não especificado') AS "Contexto tectônico", -- OK
|
21 |
COALESCE(NULLIF(mineralization->'geological_context'->>'geological_context_description', ''), 'Não especificado') AS "Contexto geológico", -- OK
|
22 |
COALESCE(NULLIF(mineralization->'geological_context'->>'context_of_present_rocks', ''), 'Não especificado') AS "Rochas presentes", -- OK
|
23 |
-
|
|
|
24 |
-- Rochas sedimentares
|
25 |
COALESCE(NULLIF(array_to_string(ARRAY(
|
26 |
SELECT jsonb_extract_path_text(sedimentares, 'name') || ' (' || 'Tipo: ' || jsonb_extract_path_text(sedimentares, 'type') || ', Relações de contato: ' || jsonb_extract_path_text(sedimentares, 'contact_relations') || ')'
|
@@ -79,7 +91,16 @@ SELECT
|
|
79 |
COALESCE(NULLIF(data->'responseData'->11->'response'->>'explanation', '[]'), 'Não especificado') AS "Explicação da favorabilidade",
|
80 |
COALESCE(NULLIF(data->'responseData'->11->'response'->>'favorability', '[]'), 'Não especificado') AS "Favorabilidade"
|
81 |
|
82 |
-
|
83 |
-
|
|
|
84 |
CROSS JOIN LATERAL
|
85 |
-
jsonb_array_elements(data->'responseData'->0->'response'->'mineralizations') AS t(mineralization)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
SELECT
|
2 |
+
id AS "Id da entrada no banco",
|
3 |
+
"createdAt" AS "Data Criação",
|
4 |
+
e.name AS "Nome do documento",
|
5 |
+
-- alvo
|
6 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(DISTINCT NULLIF(NULLIF(mineralization->'region'->>'target_or_deposit', 'Não especificado'), '')), ', '), ''), 'Não especificado') AS "Alvo ou depósito", -- OK
|
7 |
+
-- ore
|
8 |
+
array_to_string(ARRAY_AGG(DISTINCT(mineralization->>'ore')), ', ') AS "Tipo de mineralização",
|
9 |
+
-- cidade
|
10 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(DISTINCT NULLIF(NULLIF(t.mineralization->'region'->>'city', 'Não especificado'), '')), ', '), ''), 'Não especificado') AS "Cidades",
|
11 |
+
-- estado
|
12 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(DISTINCT NULLIF(NULLIF(t.mineralization->'region'->>'state', 'Não especificado'), '')), ', '), ''), 'Não especificado') AS "Estado",
|
13 |
+
-- país
|
14 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(DISTINCT NULLIF(NULLIF(t.mineralization->'region'->>'country', 'Não especificado'), '')), ', '), ''), 'Não especificado') AS "País",
|
15 |
+
-- região
|
16 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(DISTINCT NULLIF(NULLIF(t.mineralization->'region'->>'region_name', 'Não especificado'), '')), ', '), ''), 'Não especificado') AS "Região",
|
17 |
+
-- quantidade mineralizacão
|
18 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(DISTINCT NULLIF(NULLIF(t.mineralization->>'quantity', 'Não especificado'), '')), ', '), ''), 'Não especificado') AS "Quantidade de mineralização",
|
19 |
|
20 |
+
COALESCE(NULLIF(array_to_string(ARRAY(
|
21 |
SELECT jsonb_extract_path_text(concentration, 'name_of_ore') || ' - (' || jsonb_extract_path_text(concentration, 'concentration_of_ore') || ')'
|
22 |
FROM jsonb_array_elements(mineralization->'concentration') AS concentration
|
23 |
), ', '), ''), 'Não especificado') AS "Concentração de mineralização",
|
24 |
+
|
25 |
+
-- extra_info
|
26 |
+
COALESCE(NULLIF(array_to_string(ARRAY_AGG(NULLIF(NULLIF(t.mineralization->'region'->>'extra_info', 'Não especificado'), '')), ' | '), ''), 'Não especificado') AS "Informações adicionais",
|
27 |
+
|
28 |
+
---------
|
29 |
+
COALESCE(NULLIF(data->'responseData'->2->'response'->>'mineralizationSignatures', ''), 'Não identificado') AS "Assinaturas de mineralização", -- OK
|
30 |
|
31 |
COALESCE(NULLIF(mineralization->'geological_context'->>'tectonic_context', ''), 'Não especificado') AS "Contexto tectônico", -- OK
|
32 |
COALESCE(NULLIF(mineralization->'geological_context'->>'geological_context_description', ''), 'Não especificado') AS "Contexto geológico", -- OK
|
33 |
COALESCE(NULLIF(mineralization->'geological_context'->>'context_of_present_rocks', ''), 'Não especificado') AS "Rochas presentes", -- OK
|
34 |
+
----------
|
35 |
+
|
36 |
-- Rochas sedimentares
|
37 |
COALESCE(NULLIF(array_to_string(ARRAY(
|
38 |
SELECT jsonb_extract_path_text(sedimentares, 'name') || ' (' || 'Tipo: ' || jsonb_extract_path_text(sedimentares, 'type') || ', Relações de contato: ' || jsonb_extract_path_text(sedimentares, 'contact_relations') || ')'
|
|
|
91 |
COALESCE(NULLIF(data->'responseData'->11->'response'->>'explanation', '[]'), 'Não especificado') AS "Explicação da favorabilidade",
|
92 |
COALESCE(NULLIF(data->'responseData'->11->'response'->>'favorability', '[]'), 'Não especificado') AS "Favorabilidade"
|
93 |
|
94 |
+
|
95 |
+
FROM
|
96 |
+
public."Extraction" e
|
97 |
CROSS JOIN LATERAL
|
98 |
+
jsonb_array_elements(e.data->'responseData'->0->'response'->'mineralizations') AS t(mineralization)
|
99 |
+
GROUP BY
|
100 |
+
e."createdAt",
|
101 |
+
e.id,
|
102 |
+
e.name,
|
103 |
+
mineralization;
|
104 |
+
|
105 |
+
|
106 |
+
|