-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
IDocumentOperations.QueueSqlCommand to insert into jsonb-column #2422
Comments
Use Your code changes as below: const string Sql = "insert into my_table (data) values (?::jsonb);";
string json = JsonSerializer.Serialize(@event.Data);
operations.QueueSqlCommand(Sql, json); |
Fantastic 👍🏻 Thank you! In Execute custom SQL in session a hint could be added that Postgres casting operator can be appended to parameters and that these casts aren't changed / removed by Marten. Then it would be ideal. Something like
If that sounds good, I can do a PR for this. |
@gfoidl Sure, go ahead, we are happy to take a PR! |
@gfoidl Quick note, the use case which you outlined is not a typical one which users would use especially a custom table with |
Yep, I know. Normally the document store features are sufficient. I came accross this issue while playing around with the outbox pattern (and wanted to have the jsonb column, not a plain string / text column). |
Got you! |
E.g.
Creates a table with a jsonb-column.
fails with
Trying to insert the JSON as string like
fails with
Is there any way to insert JSON into a jsonb-column via IDocumentOperations?
If not, then I believe the problem results from
marten/src/Marten/Internal/Operations/ExecuteSqlStorageOperation.cs
Line 40 in 56fb16e
string
, so it tries to insert via TextHandler.If this gets changed to
then the object could be used a parameter directly, and NpgSql would care about serialization and the insert to the jsonb-column.
Could this have any downsides? Is there possibly a better way by getting the actual underlying db-column-type and set the
NpgsqlDbType
based on that?A different approach could be to pass the DB-types as arguments to
QueueSqlCommand
(additional overload).The text was updated successfully, but these errors were encountered: