SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
Dados Tipo Json Entendendo como usar em situações reais no seu Sistema
Waldir Pimentel
Graduado em Sistemas de Informação.
Especialista em Gestão de Negócios para Desenvolvimento Web.
Programador há 15 anos.
10 anos usando Postgres.
Gerente de TI - Telecontrol Networking.
Palestrante telecontrol.com.br
A Telecontrol telecontrol.com.br
Pós-Venda Pedido-Web Import
{
"Dados tipo JSON":
"Entendendo como usar em situações reais no seu Sistema"
}
JSON
{
"JSON": "(JavaScript Object Notation - Notação de Objetos JavaScript)”,
"Definicao": “É uma formatação leve de troca de dados. Para seres humanos, é fácil de ler
e escrever. Para máquinas, é fácil de interpretar e gerar.",
"Ref.": “www.json.org"
}
Antes do 9.3
FUNCTION JSON_FIELD(search, field)
BEGIN
IF POSITION ($1 IN $2) = 0 THEN
RETURN NULL;
END IF;
RETURN REGEXP_REPLACE($2, E'^.*?"'||$1||E'":s?"?([^,"]}]*)"?[,]} ].*$', E'1');
END;
TYPES
{
"Version": {
"9.2": {
"TYPE": "JSON"
},
"9.4": {
"TYPE": ["JSON", "JSONB"]
}
}
}
{
"JSON" : "Valida formato Json antes de salvar porém armazena no formato TEXTO",
"JSONB": "Valida formato Json antes de salvar porém armazena no formato BINARIO"
}
Resquest & Response
Parametrizações
Logs
JsonB
Onde utilizamos !!!
APIs
JsonB
Pesquisa de satisfação
Resquest & Response
pgconf=# insert into tbl_log_integracao2(request) values ('{"api":
"mailchimp""method": "GET","rota": "https://us7.api.mailchimp.com/3.0/
lists","headers": {"Authorization": "apikey 23127a6581b23cb194d80b9c1f335612
us7”,"Content-Type": “application/json"}}') returning log_integracao ; ;
{
"api": "mailchimp"
"method": "GET",
"rota": "https://us7.api.mailchimp.com/3.0/lists",
"headers": {
"Authorization": "apikey 23127a6581b23cb194d80b9c1f335612-us7”,
"Content-Type": "application/json"
}
}
ERROR: invalid input syntax for type json
LINE 1: insert into tbl_log_integracao(request) values ('{"api": "ma...
^
DETAIL: Expected "," or "}", but found ""method"".
CONTEXT: JSON data, line 1: {"api": "mailchimp""method"...
Resquest & Response
pgconf=# insert into tbl_log_integracao(request) values ('{"api":
"mailchimp","method": "GET","rota": "https://us7.api.mailchimp.com/3.0/
lists","headers": {"Authorization": "apikey 23127a6581b23cb194d80b9c1f33561
us7","Content-Type": "application/json"}}') returning log_integracao ; ;
{
"api": “mailchimp",
"method": "GET",
"rota": "https://us7.api.mailchimp.com/3.0/lists",
"headers": {
"Authorization": "apikey 23127a6581b23cb194d80b9c1f335612-us7”,
"Content-Type": "application/json"
}
}
log_integracao
----------------
4
(1 row)
INSERT 0 1
Resquest & Response
pgconf=# select *from tbl_log_integracao ;
-[ RECORD 1 ]--
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------
log_integracao | 2
request | {"api": "mailchimp", "rota": "https://us7.api.mailchimp.com/3.0/lists", "method": "GET", "headers":
{"Content-Type": "application/json", "Authorization": "apikey 23127a6581b23cb194d80b9c1f335637-us7"}}
response |
data_input | 2018-07-23 22:58:19.284664
Response
{
"lists": [
{
"id": "408c5508c0",
"web_id": 317607,
"name": "Nova lista SEG 05_2018",
"contact": {
"company": "Seg International",
"address1": "Av. Bartolomé Mitre 1400, Florida Oeste, Buenos Aires, Argentina",
"address2": "",
"city": "Buenos Aires",
"state": "Buenos Aires",
"zip": "B1604AKG",
"country": "AR",
"phone": "(011) 4761-7661"
},
"permission_reminder": "Bienvenido a SEG International",
"use_archive_bar": true,
"campaign_defaults": {
"from_name": "SEG International",
"from_email": "info@seg.com.ar",
"subject": "",
"language": "en"
}………
Operadores
Operador Tipo Descrição
-> Json e JsonB Retorna valor json por uma chave
->> Json e JsonB Retorna valor como texto
#> Json e JsonB
Retorna valor json usando um
caminho
#>> Json e JsonB
Retorna valor texto usando um
caminho
Operadores
SELECT request,
request->'api' AS api,
request->'rota' AS rota,
request->'method' AS method,
request->'headers' AS headers,
request->'headers'->'Content-Type' AS contentType,
request->'headers'->'Authorization' AS Authorization
FROM tbl_log_integracao ;
SELECT request,
request->>'api' AS api,
request->>’rota' AS rota,
request->>’method' AS method,
request->>’headers' AS headers,
request->'headers'->>'Content-Type' AS contentType,
request->’headers'->>'Authorization' AS Authorization
FROM tbl_log_integracao ;
Operadores
SELECT
request->'api' AS OperadorChaveApi,
pg_typeof(request->'api') AS TypeOperadorChaveApi,
request->>'api' AS OperadorTextoApi,
pg_typeof(request->>'api') AS TypeOperadorTextoapi,
request->'headers' AS OperadorChaveHeaders,
pg_typeof(request->'headers') AS TypeOperadorChaveHeaders,
request->>'headers' AS OperadorTextoHeaders,
pg_typeof(request->>'headers') AS TypeOperadorTextoHeaders
FROM tbl_log_integracao ;
Operadores
SELECT
request->>'api' as api,
request->>'rota' as rota,
request->>'method' as method,
request->>'headers' as headers,
request#>'{headers,Content-Type}' as contentType,
request->'headers'->'Authorization' as Authorization
FROM tbl_log_integracao ;
Operadores
Operador Tipo Descrição
@> JsonB
Se contém no JSON da esquerda o
valor da direita
<@ JsonB
Se contém na direita valor da es
querda
? JsonB
Verifica se existe a chave dentro do
Json
?| JsonB
Verifica se alguma chave existe no
Json
?& JsonB
Verifica se todas as chaves existem no
Json
Indexes
{
"Indexes": {
“Btree": “Usar em uma chave do json, ex: request->api. Pesquisas
com =, like, ilike”,
“GIN”:"Usar em uma coluna tipo jsonB, ex: response. Pesquisa com
contém @>”
}
}
Operadores
SELECT
request->>'headers' AS headers
FROM
tbl_log_integracao
WHERE request @> '{"rota": "https://us7.api.mailchimp.com/3.0/
lists"}' ;
SELECT log_integracao,
request->>'headers' AS headers,
request->'data' AS data
FROM tbl_log_integracao
WHERE request ? 'data';
Operadores
SELECT
request->>'headers' AS headers
FROM
tbl_log_integracao
WHERE request @> '{"rota": "https://us7.api.mailchimp.com/3.0/
lists"}' ;
SELECT log_integracao,
request->>'headers' AS headers,
request->'data' AS data
FROM tbl_log_integracao
WHERE request ? 'data';
Operadores
SELECT log_integracao,
request->>'headers' AS headers,
request->'data' AS data
FROM tbl_log_integracao
WHERE request ?| array['method'];
SELECT log_integracao,
request->>'headers' AS headers,
request->'data' AS data
FROM tbl_log_integracao
WHERE request ?& array['method','teste'];
Funções
Função Tipo Descrição
json_set Json/JsonB
Adiciona um elemento + valor em um
Json
row_to_json JsonB
Gera um json com rows de uma
consulta
array_to_json JsonB gera um json através de um array
jsonb_array_elements JsonB Resgata um valor de um array de json
jsonb_each JsonB
gera uma linha para cada campo do
json
jsonb_to_recordset JsonB Gera um recordset de um Json
Funções
select row_to_json(json) as json from (select
log_integracao,data_input from tbl_log_integracao) as json;
select jsonb_array_elements(response->'lists')->>'id' as ids,
jsonb_array_elements(response->'lists')->>'name' as names from
tbl_log_integracao where log_integracao = 4;
update tbl_log_integracao set request =
jsonb_set(request,’{data}’,'"2018-08-04"') where log_integracao = 4 ;
Funções
select * from jsonb_each((select request from tbl_log_integracao
where log_integracao = 4)) ;
select * from jsonb_each_text((select request from
tbl_log_integracao where log_integracao = 4)) ;
select * from jsonb_each_text((select request->'headers' from
tbl_log_integracao where log_integracao = 4)) ;
Funções
select key,value from
tbl_log_integracao,jsonb_each_text(tbl_log_integracao.request)
where log_integracao = 4 ;
select key,value from
tbl_log_integracao,jsonb_each_text(tbl_log_integracao.request) ;
select *from jsonb_to_recordset('[{"api": "mailchimp", "rota": "https://
us7.api.mailchimp.com/3.0/lists", "method": "GET"}]') as x(api text, rota
text, method text)
Perguntas ?
Obrigado pelo tempo e atenção de vocês.
telecontrol.com.br
waldir@telecontrol.com.br
waldir-pimentel
Waldir Pimentel

Mais conteúdo relacionado

Destaque

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Destaque (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Dados Tipo Json Entendendo como usar em situações reais no seu Sistema

  • 2. Waldir Pimentel Graduado em Sistemas de Informação. Especialista em Gestão de Negócios para Desenvolvimento Web. Programador há 15 anos. 10 anos usando Postgres. Gerente de TI - Telecontrol Networking. Palestrante telecontrol.com.br
  • 4. { "Dados tipo JSON": "Entendendo como usar em situações reais no seu Sistema" }
  • 5. JSON { "JSON": "(JavaScript Object Notation - Notação de Objetos JavaScript)”, "Definicao": “É uma formatação leve de troca de dados. Para seres humanos, é fácil de ler e escrever. Para máquinas, é fácil de interpretar e gerar.", "Ref.": “www.json.org" }
  • 6. Antes do 9.3 FUNCTION JSON_FIELD(search, field) BEGIN IF POSITION ($1 IN $2) = 0 THEN RETURN NULL; END IF; RETURN REGEXP_REPLACE($2, E'^.*?"'||$1||E'":s?"?([^,"]}]*)"?[,]} ].*$', E'1'); END;
  • 7. TYPES { "Version": { "9.2": { "TYPE": "JSON" }, "9.4": { "TYPE": ["JSON", "JSONB"] } } } { "JSON" : "Valida formato Json antes de salvar porém armazena no formato TEXTO", "JSONB": "Valida formato Json antes de salvar porém armazena no formato BINARIO" }
  • 8. Resquest & Response Parametrizações Logs JsonB Onde utilizamos !!! APIs JsonB Pesquisa de satisfação
  • 9. Resquest & Response pgconf=# insert into tbl_log_integracao2(request) values ('{"api": "mailchimp""method": "GET","rota": "https://us7.api.mailchimp.com/3.0/ lists","headers": {"Authorization": "apikey 23127a6581b23cb194d80b9c1f335612 us7”,"Content-Type": “application/json"}}') returning log_integracao ; ; { "api": "mailchimp" "method": "GET", "rota": "https://us7.api.mailchimp.com/3.0/lists", "headers": { "Authorization": "apikey 23127a6581b23cb194d80b9c1f335612-us7”, "Content-Type": "application/json" } } ERROR: invalid input syntax for type json LINE 1: insert into tbl_log_integracao(request) values ('{"api": "ma... ^ DETAIL: Expected "," or "}", but found ""method"". CONTEXT: JSON data, line 1: {"api": "mailchimp""method"...
  • 10. Resquest & Response pgconf=# insert into tbl_log_integracao(request) values ('{"api": "mailchimp","method": "GET","rota": "https://us7.api.mailchimp.com/3.0/ lists","headers": {"Authorization": "apikey 23127a6581b23cb194d80b9c1f33561 us7","Content-Type": "application/json"}}') returning log_integracao ; ; { "api": “mailchimp", "method": "GET", "rota": "https://us7.api.mailchimp.com/3.0/lists", "headers": { "Authorization": "apikey 23127a6581b23cb194d80b9c1f335612-us7”, "Content-Type": "application/json" } } log_integracao ---------------- 4 (1 row) INSERT 0 1
  • 11. Resquest & Response pgconf=# select *from tbl_log_integracao ; -[ RECORD 1 ]-- +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------- log_integracao | 2 request | {"api": "mailchimp", "rota": "https://us7.api.mailchimp.com/3.0/lists", "method": "GET", "headers": {"Content-Type": "application/json", "Authorization": "apikey 23127a6581b23cb194d80b9c1f335637-us7"}} response | data_input | 2018-07-23 22:58:19.284664
  • 12. Response { "lists": [ { "id": "408c5508c0", "web_id": 317607, "name": "Nova lista SEG 05_2018", "contact": { "company": "Seg International", "address1": "Av. Bartolomé Mitre 1400, Florida Oeste, Buenos Aires, Argentina", "address2": "", "city": "Buenos Aires", "state": "Buenos Aires", "zip": "B1604AKG", "country": "AR", "phone": "(011) 4761-7661" }, "permission_reminder": "Bienvenido a SEG International", "use_archive_bar": true, "campaign_defaults": { "from_name": "SEG International", "from_email": "info@seg.com.ar", "subject": "", "language": "en" }………
  • 13. Operadores Operador Tipo Descrição -> Json e JsonB Retorna valor json por uma chave ->> Json e JsonB Retorna valor como texto #> Json e JsonB Retorna valor json usando um caminho #>> Json e JsonB Retorna valor texto usando um caminho
  • 14. Operadores SELECT request, request->'api' AS api, request->'rota' AS rota, request->'method' AS method, request->'headers' AS headers, request->'headers'->'Content-Type' AS contentType, request->'headers'->'Authorization' AS Authorization FROM tbl_log_integracao ; SELECT request, request->>'api' AS api, request->>’rota' AS rota, request->>’method' AS method, request->>’headers' AS headers, request->'headers'->>'Content-Type' AS contentType, request->’headers'->>'Authorization' AS Authorization FROM tbl_log_integracao ;
  • 15. Operadores SELECT request->'api' AS OperadorChaveApi, pg_typeof(request->'api') AS TypeOperadorChaveApi, request->>'api' AS OperadorTextoApi, pg_typeof(request->>'api') AS TypeOperadorTextoapi, request->'headers' AS OperadorChaveHeaders, pg_typeof(request->'headers') AS TypeOperadorChaveHeaders, request->>'headers' AS OperadorTextoHeaders, pg_typeof(request->>'headers') AS TypeOperadorTextoHeaders FROM tbl_log_integracao ;
  • 16. Operadores SELECT request->>'api' as api, request->>'rota' as rota, request->>'method' as method, request->>'headers' as headers, request#>'{headers,Content-Type}' as contentType, request->'headers'->'Authorization' as Authorization FROM tbl_log_integracao ;
  • 17. Operadores Operador Tipo Descrição @> JsonB Se contém no JSON da esquerda o valor da direita <@ JsonB Se contém na direita valor da es querda ? JsonB Verifica se existe a chave dentro do Json ?| JsonB Verifica se alguma chave existe no Json ?& JsonB Verifica se todas as chaves existem no Json
  • 18. Indexes { "Indexes": { “Btree": “Usar em uma chave do json, ex: request->api. Pesquisas com =, like, ilike”, “GIN”:"Usar em uma coluna tipo jsonB, ex: response. Pesquisa com contém @>” } }
  • 19. Operadores SELECT request->>'headers' AS headers FROM tbl_log_integracao WHERE request @> '{"rota": "https://us7.api.mailchimp.com/3.0/ lists"}' ; SELECT log_integracao, request->>'headers' AS headers, request->'data' AS data FROM tbl_log_integracao WHERE request ? 'data';
  • 20. Operadores SELECT request->>'headers' AS headers FROM tbl_log_integracao WHERE request @> '{"rota": "https://us7.api.mailchimp.com/3.0/ lists"}' ; SELECT log_integracao, request->>'headers' AS headers, request->'data' AS data FROM tbl_log_integracao WHERE request ? 'data';
  • 21. Operadores SELECT log_integracao, request->>'headers' AS headers, request->'data' AS data FROM tbl_log_integracao WHERE request ?| array['method']; SELECT log_integracao, request->>'headers' AS headers, request->'data' AS data FROM tbl_log_integracao WHERE request ?& array['method','teste'];
  • 22. Funções Função Tipo Descrição json_set Json/JsonB Adiciona um elemento + valor em um Json row_to_json JsonB Gera um json com rows de uma consulta array_to_json JsonB gera um json através de um array jsonb_array_elements JsonB Resgata um valor de um array de json jsonb_each JsonB gera uma linha para cada campo do json jsonb_to_recordset JsonB Gera um recordset de um Json
  • 23. Funções select row_to_json(json) as json from (select log_integracao,data_input from tbl_log_integracao) as json; select jsonb_array_elements(response->'lists')->>'id' as ids, jsonb_array_elements(response->'lists')->>'name' as names from tbl_log_integracao where log_integracao = 4; update tbl_log_integracao set request = jsonb_set(request,’{data}’,'"2018-08-04"') where log_integracao = 4 ;
  • 24. Funções select * from jsonb_each((select request from tbl_log_integracao where log_integracao = 4)) ; select * from jsonb_each_text((select request from tbl_log_integracao where log_integracao = 4)) ; select * from jsonb_each_text((select request->'headers' from tbl_log_integracao where log_integracao = 4)) ;
  • 25. Funções select key,value from tbl_log_integracao,jsonb_each_text(tbl_log_integracao.request) where log_integracao = 4 ; select key,value from tbl_log_integracao,jsonb_each_text(tbl_log_integracao.request) ; select *from jsonb_to_recordset('[{"api": "mailchimp", "rota": "https:// us7.api.mailchimp.com/3.0/lists", "method": "GET"}]') as x(api text, rota text, method text)
  • 27. Obrigado pelo tempo e atenção de vocês. telecontrol.com.br waldir@telecontrol.com.br waldir-pimentel Waldir Pimentel