Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
cargar json formateado en la tabla postgreSQL

Quiero cargar un archivo JSON formateado, en forma de

 { "EId":"104111", "Category":"(0)", "Mac":"ABV", "Path":"chemin2", "ID":"System.Byte" }

creando primero una tabla temporal con una columna json,

 create temporary table temp_json (values json); copy temp_json from '/path_to_the_file/test.json'; select values->>'EId' as EId, values->>'Category' as Category, values->>'Mac' as Mac, values->>'Path' as Path, values->>'ID' as ID from( select json_array_elements(values) as values from temp_json ) a;

pero muestra el siguiente mensaje:

 ERROR: invalid input syntax for type JSON DETAIL: The input string ended unexpectedly. CONTEXT: JSON data, line 1: { COPY temp_json, line 1, column values: "{"

una vez que borro todos los espacios en blanco, la instrucción pasa sin errores.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Suponiendo un archivo como este:

 { "EId":"104111", "Category":"(0)", "Mac":"ABV", "Path":"chemin2", "ID":"System.Byte" } { "EId":"104112", "Category":"(1)", "Mac":"CBV", "Path":"chemin3", "ID":"System.Byte" }

La tabla temporal recibirá texto no json:

 create temporary table temp_json (values text); \copy temp_json from '/path_to/input.json';

La tabla definitiva tendrá una columna json:

 create table t (obj jsonb);

Alguna manipulación de cadenas:

 insert into t (obj) select regexp_split_to_table( replace(v, $$"}{"$$, $$"}djue748wBc,l;09{"$$), 'djue748wBc,l;09' )::jsonb from ( select string_agg(values, '') as v from temp_json ) s; obj -------------------------------------------------------------------------------------------- {"ID": "System.Byte", "EId": "104111", "Mac": "ABV", "Path": "chemin2", "Category": "(0)"} {"ID": "System.Byte", "EId": "104112", "Mac": "CBV", "Path": "chemin3", "Category": "(1)"}
over 4 years ago · Santiago Trujillo Report

0

No creo que estés citando correctamente esto. Consulte los documentos sobre cotización y copia .

Ciertamente es posible,

 CREATE TEMPORARY TABLE foo AS SELECT $${ "EId":"104111", "Category":"(0)", "Mac":"ABV", "Path":"chemin2", "ID":"System.Byte" }$$::jsonb AS jsondata;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!