Returning Invalid syntax for type json on arrays
See original GitHub issueWhen your column is type json and you try and insert a JSON array, you get the following error:
{ [error: invalid input syntax for type json]
length: 154,
name: 'error',
severity: 'ERROR',
code: '22P02',
detail: 'Expected string or "}", but found "1".',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: 'JSON data, line 1: {1...',
file: 'json.c',
line: '665',
routine: 'report_parse_error' }
For example, this works in PSQL:
insert into my_table ( data ) values ( '[1,2,3]' );
But this returns an error in node-pg:
client.query('insert into my_table ( data ) values ( $1 )', [ [1,2,3] ], function( error ){
/* ERROR */
});
Issue Analytics
- State:
- Created 10 years ago
- Reactions:5
- Comments:28 (10 by maintainers)
Top Results From Across the Web
Returning Invalid syntax for type json on arrays #442
Just because pg doesn't know the column type in advance does not mean you should convert to the syntax of column type "array"....
Read more >Update of value in array of jsonb returns error"invalid input ...
Until now I always get the following error: invalid input syntax for type json DETAIL: Token "c66a4353" is invalid. CONTEXT: JSON data, line...
Read more >Returning Invalid syntax for type json on arrays - Bountysource
When your column is type json and you try and insert a JSON array, you get the following error: { [error: invalid input...
Read more >JSON.stringify() - JavaScript - MDN Web Docs
If replacer is an array, all elements in this array that are not strings or numbers (either primitives or wrapper objects), including Symbol ......
Read more >JSON Syntax - W3Schools
JSON Values. In JSON, values must be one of the following data types: a string; a number; an object; an array; a boolean;...
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
We convert javascript arrays into postgres arrays. If you stringify your input array it should work:
We don’t now the column type in advance so we can’t do a auto conversions of the array.
Would it make sense for
node-postgres
to intercept this error and augment it with something likeAre you inserting an array into a JSON column? See <link to docs>
? Helpful error messages make for a nice developer experience.