I've read the article "How can I import a JSON file into PostgreSQL?" I've been trying to create a table from Query Tool, but I keep getting an error message and I am a bit lost why I get the syntax error in where other people don't... (I tried to ask a question in the post above, but I'm too new to make a comment on others' post.)
I'd appreciate it if anyone can give me a hint on how to fix this.
The query I use
with customer_json (doc) as (
values
('[
{
"consecutive":"1",
"ticket":"#7457512",
"category":"Temp>Support>Rule",
"question":"Can I ask another question?",
"answer":"answer1 yes, but only if it''s related?",
"url":"https://tools.team.com/inbox/ticket/7457512",
"note":"テスト",
},
{
"consecutive":"2",
"ticket":"#4408539-2",
"category":"Automation>WF / List",
"question":\"not equal\" vs \"not contain\",
"answer":"answer2 filter not any vs not all of them",
"url":"https://tools.team.com/inbox/ticket/4408539",
"note":"-",
},
{
"consecutive":"3",
"ticket":"#4204223-2",
"category":"Temp>Investigation>JIRA / Temp>Investigation>Sharing",
"question":"Thank you for sharing. Will start investigation with related teams",
"answer":"answer3 will let you know asap",
"url":"https://tools.team.com/inbox/ticket/4204223",
"note":"#7457512",
},
{
"consecutive":"4",
"ticket":"#4223184",
"category":"Temp>Close>Bug",
"question":"[NOT fixed] When the bug won''t be fixed for a while",
"answer":"answer4 apologies about the bug with the filter",
"url":"https://tools.team.com/inbox/ticket/4223184",
"note":"-",
},
{
"consecutive":"5",
"ticket":"#6462310",
"category":"Form / Forum",
"question":"[TempSQL>Upgade/Additional] How to conduct a questionaire / customer survey",
"answer":"answer5 \r\nNew line",
"url":"https://tools.team.com/inbox/ticket/6462310",
"note":"#7457512",
},
{
"consecutive":"6",
"ticket":"#4321892",
"category":"Automation>WF",
"question":"*confirming *",
"answer":"answer6 あいうえお",
"url":"https://tools.team.com/inbox/ticket/4321892",
"note":"-",
}
]'::json)
)
insert into customer (consecutive, ticket, category, question, answer, url, note)
select p.*
from customer_json l
cross join lateral json_populate_recordset(null::customer, doc) as p
on conflict (id) do update
set consecutive = excluded.consecutive,
ticket = excluded.ticket,
category = excluded.category,
question = excluded.question,
answer = excluded.answer,
url = excluded.url,
note = excluded.note;
The response / error message
ERROR: invalid input syntax for type json LINE 3: ('[ ^ DETAIL: Expected string, but found "}". CONTEXT: JSON data, line 8: ...inbox/ticket/7457512", "note":"テスト", }... SQL state: 22P02 Character: 47
Others For some reason, I'd like to paste a JSON-formatted table into the query tool.
My original data is created as an Excel file, so I use formulas to format the table as a JSON style.