pglite icon indicating copy to clipboard operation
pglite copied to clipboard

Correctly parse a top level json string as a value to a query param

Open samwillis opened this issue 1 year ago • 2 comments

See: https://discord.com/channels/933657521581858818/1318643604528431194

samwillis avatar Dec 17 '24 19:12 samwillis

I just ran into this issue and stumbled on the discord thread above. Adding this error message here just in case anyone else searches the github issues for this problem.

Uncaught error: invalid input syntax for type json

If you're trying to use the syncShapeToTable API the workaround is to supply map a mapColumns function that translates the top level json string into an object. Something like this:

"Hello world" -> "{ value: "Hello world"}

        mapColumns: (changes: any) => {
          const { value: newValues } = changes;
          return {
            value: {value: newValues.value},
          };
        },

Then you can map the object as needed in application code.

In my case, the jsonb column was named value so that's why value is a little overloaded in the example above. 😅

TheAndrewJackson avatar Mar 08 '25 19:03 TheAndrewJackson

This bug also breaks the useCopy option on the syncShapeToTable API. It throws this error message in combination with the one listed above.

Uncaught error: current transaction is aborted, commands ignored until end of transaction block

TheAndrewJackson avatar Mar 08 '25 19:03 TheAndrewJackson