Insert array into a JSON column
See original GitHub issueThis query fails
var q = adapter.query('INSERT INTO tbl_data (id, data) VALUES ($1, $2)', [ 1, ['a', 'b'] ] );
with
error: undefined
at Connection.parseE (/home/user/dev/node_modules/pg.js/lib/connection.js:534:11)
at Connection.parseMessage (/home/user/dev/node_modules/pg.js/lib/connection.js:361:17)
at Socket.<anonymous> (/home/user/dev/node_modules/pg.js/lib/connection.js:105:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
The table is defined as
CREATE TABLE tbl_data
(
id bigserial NOT NULL,
data json,
CONSTRAINT "PK_data" PRIMARY KEY (id)
)
(Note: the table is for tests only, and it illustrate the problem I am having in my project.)
Also, see #864
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Adding a new array element to a JSON object - Stack Overflow
In my case, my JSON object didn't have any existing Array in it, so I had to create array element first and then...
Read more >INSERT array elements from JSON object as table rows
Something like this: INSERT INTO tbl (id, type) -- spell out actual column names! SELECT 1708, json_array_elements_text('{"id":1708, ...
Read more >16.20 - Examples: Inserting Values into a JSON Column
The example creates a table with a JSON column, allocates and initializes a JSON instance using the JSON constructor, then inserts the JSON...
Read more >MySQL 8.0 Reference Manual :: 11.5 The JSON Data Type
A JSON array contains a list of values separated by commas and enclosed ... Attempting to insert a value into a JSON column...
Read more >Inserting into a JSON column in mysql - Laracasts
I have a table defined that has 2 JSON columns and the rest strings. How do I insert key values from an associative...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The only solution I can think of is to execute the query like this :
Which seems to work.
Alright, closing this, now. It was a
-
character on a different line that causedNaN
to be sent (i.e.-{}
) This is not pg’s fault.