Bulk insert with JSON column type
Opened this issue · 0 comments
webdpro commented
Hi,
I have a script that uses a bulk insert using a t set.
Basically, what we do is loop over an excel spreadsheet, create an array of all the object we wish to insert and then pass it over to pgformt, if there is no entry in the field we pass over an empty array so the variable is set to [] if there are no values.
The query is
format(`update attendee_data as t set
fname = c.attendee_fname,
lname = c.attendee_lname,
title = c.attendee_title,
email = c.attendee_email,
phone = c.attendee_phone,
company = c.attendee_company,
description = c.attendee_des,
links = CAST (c.attendee_links AS JSON),
grouplistid = c.attendee_groups,
attendeeonly = c.attendee_atonly
from (values
%L
) as c(attendee_fname,attendee_lname,attendee_title,attendee_email,attendee_phone,attendee_company,attendee_des,attendee_links,attendee_groups,attendee_atonly,attendee_id)
where CAST (c.attendee_id AS bigint) = CAST (t.sid AS bigint) AND aid = ${req.session.AccountID} AND cid= ${req.session.cID}`, attendeeUpdate, []));
This normally works great, however one of the columns is of type JSON. When trying to run the above code it throws and error
error: syntax error at or near ","
Is there a way to have the bulk insert work when there is a column that may be an array?
I saw a similar question posted on here but it does not look like there was ever a resolution to it, especially for a bulk insert.
Thanks!