Skip to content

How do I use template directories to seed an entire row, not just a JSON column? #3548

Closed Answered by giautm
leojweda asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the json_array_elements to parse the JSON string from variable, then insert into your table. This is batch insert so it should faster than multiple insert statements.

INSERT INTO employees (name, skills)
SELECT (json_data->>'name'), (json_data->'skills')::jsonb
FROM json_array_elements('[
  {"name": "Alice", "skills": ["Java", "SQL"]},
  {"name": "Bob", "skills": ["Python", "Go"]},
  {"name": "Charlie", "skills": ["C++", "Rust"]}
]') AS json_data;

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@leojweda
Comment options

@giautm
Comment options

giautm Jul 7, 2025
Collaborator

Answer selected by leojweda
@giautm
Comment options

giautm Jul 7, 2025
Collaborator

@leojweda
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants