-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jsonb example #108
Comments
Edge caseWith the following lines, notice the const [inserted_row] = await postgres`
INSERT INTO "tests_json" (
"data"
) VALUES (
${JSON.stringify({ foo: { bar: true } })}
) RETURNING *;
`;
console.log({ inserted_row });
+ const nested_path = 'bar';
const [updated_row] = await postgres`
UPDATE "tests_json"
+ SET "data" = jsonb_set(data, '{foo, ${nested_path}}', ${false}, true)
WHERE id = ${inserted_row.id}
RETURNING *;
`;
console.log({ updated_row }); This gives the following error
Which is related to #36 (comment) Fix const nested_path = 'bar';
const [updated_row] = await postgres`
UPDATE "tests_json"
+ SET "data" = jsonb_set(data, array_append(ARRAY['foo'], ${nested_path}), ${false}, true)
WHERE id = ${inserted_row.id}
RETURNING *;
`;
console.log({ updated_row }); Result
|
If you're using json you should use You can also do |
This seems to be the correct formatting for
Thank you :) |
Not really an issue, just surprised that it just works, might be helpful to some 💯
v3 alt
sql.json
helper is missing in the docs #342The text was updated successfully, but these errors were encountered: