You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently trying to get NHibernate to work with JSON data type. I am currently getting stuck on ERROR: 42804: column "post" is of type json but expression is of type text - I have used Npgsql directly and it works just fine. I am thinking that step one might be to add Json to NpgsqlDbType but after that I am not 100% sure where to go.
Ok, I traced it down to 'UseCast'. NHibernate is setting the NpgsqlParameter in some fashion that is turning UseCast = true and is setting it to text (as it has been instructed to do). What I would love here is a way to tell it that NpgsqlDbType is Json and I wonder if that wouldn't fix my problems right up.
If you want to provide a custom converter in text format and/or binary format, you can do so by specifying your custom converters when calling AddType. You may have a look at current converters like:
Sure! I'll play with it and will let you know what I get.
I'll use this issue to create documentation about how to add custom types support to Npgsql. I think this will help a lot of developers who work with Npgsql. :)
Hi, @drusellers ! I'm really sorry I didn't check this issue yet. :(
I was working with some other issues related to Npgsql releases.
As things seem to be going ok now, I can work on this issue too. Give me some time while I write some documentation about how to add a custom type. I'll use json type as the example.
No worries. I have a work around. Just not sure how best to help. -d
On Sat, Mar 29, 2014 at 5:29 PM, Francisco Figueiredo Jr. [email protected] wrote:
Hi, @drusellers ! I'm really sorry I didn't check this issue yet. :(
I was working with some other issues related to Npgsql releases.
As things seem to be going ok now, I can work on this issue too. Give me some time while I write some documentation about how to add a custom type. I'll use json type as the example.
Sorry for making you wait :(
Reply to this email directly or view it on GitHub: #168 (comment)
I believe it to ultimately be a 'Npgsql' issue - because its trying to do a cast in the sql to 'text' when the column is 'json' - in order to get past it I had to do the following 'hack' to make it work, for more details see above.
var parameter = cmd.Parameters[index];
parameter.Value = value;
var field = typeof (NpgsqlParameter).GetField("useCast", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(parameter, false);
I don't know OrmLite enough to say where - I did mine with NHibernate and put it in an IUserType - but the gist is you'll need to get access to the NpgsqlParameter that is handling the JSON column type.
I found the place where to put it in OrmLite and it works. I also found out you can do the same in Npgsql and "turn off" casting but the hack on the ORM is a better place I would think.
Hi, all!
I'm working to add support for json datatype. I'll also use this opportunity to add documentation to Npgsql about how to add datatypes so others can be easily added in the future.
Sorry for taking so long. I hope to get something about it by the weekend.
Just created a pull request which adds support for json datatype.
@drusellers , you will now be able to set the NpgsqlDbType to Json.
For while, the only way to get json support is to set the NpgsqlDbType. As json datatype looks just like string, Npgsql won't be able to tell the difference between a text and json if you simply set the parameter value.
Regarding your changes to omit the parameter cast (which is also another possible solution) I'm working on this support too. See #146 and #125
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/168#issuecomment-40763712
.
Activity
drusellers commentedon Feb 26, 2014
Ok, I traced it down to 'UseCast'. NHibernate is setting the NpgsqlParameter in some fashion that is turning
UseCast = trueand is setting it to text (as it has been instructed to do). What I would love here is a way to tell it thatNpgsqlDbTypeisJsonand I wonder if that wouldn't fix my problems right up.drusellers commentedon Feb 26, 2014
I have worked around the issue with the following horrible code.
franciscojunior commentedon Feb 26, 2014
Hi, @drusellers !
Indeed, Npgsql needs a better way to handle type casting. I even created an issue about that: #125 .
In order to add json datatype support, besides adding NpgsqlDbType, you will need to add a line to PrepareDefaultTypesMap method in NpgsqlTypesHelper:
If you want to provide a custom converter in text format and/or binary format, you can do so by specifying your custom converters when calling AddType. You may have a look at current converters like:
We can work together on this issue to add it.
drusellers commentedon Mar 2, 2014
I would definitely appreciate any help you can provide on the topic.
franciscojunior commentedon Mar 5, 2014
Sure! I'll play with it and will let you know what I get.
I'll use this issue to create documentation about how to add custom types support to Npgsql. I think this will help a lot of developers who work with Npgsql. :)
drusellers commentedon Mar 29, 2014
@franciscojunior what's the best way for me to help?
franciscojunior commentedon Mar 29, 2014
Hi, @drusellers ! I'm really sorry I didn't check this issue yet. :(
I was working with some other issues related to Npgsql releases.
As things seem to be going ok now, I can work on this issue too. Give me some time while I write some documentation about how to add a custom type. I'll use json type as the example.
Sorry for making you wait :(
drusellers commentedon Mar 30, 2014
No worries. I have a work around. Just not sure how best to help. -d
On Sat, Mar 29, 2014 at 5:29 PM, Francisco Figueiredo Jr.
[email protected] wrote:
franciscojunior commentedon Mar 30, 2014
Great! I'm glad to know I'm not giving you too much trouble :) Thanks for your comprehension.
squidge commentedon Apr 15, 2014
Hello,
I have been getting the same issue "ERROR: 42804: column "x" is of type json but expression is of type text"
Is this a Npgsql issue or OrmLite which is what I am using in this case.
Many thanks
drusellers commentedon Apr 15, 2014
I believe it to ultimately be a 'Npgsql' issue - because its trying to do a cast in the sql to 'text' when the column is 'json' - in order to get past it I had to do the following 'hack' to make it work, for more details see above.
squidge commentedon Apr 15, 2014
I see, I'll try your hack then while a fix is put in place..
Many thanks
squidge commentedon Apr 16, 2014
@drusellers so where exactly did you put this code?
drusellers commentedon Apr 16, 2014
I don't know OrmLite enough to say where - I did mine with NHibernate and put it in an
IUserType- but the gist is you'll need to get access to the NpgsqlParameter that is handling the JSON column type.squidge commentedon Apr 17, 2014
I found the place where to put it in OrmLite and it works. I also found out you can do the same in Npgsql and "turn off" casting but the hack on the ORM is a better place I would think.
Thanks for your help
franciscojunior commentedon Apr 17, 2014
Hi, all!
I'm working to add support for json datatype. I'll also use this opportunity to add documentation to Npgsql about how to add datatypes so others can be easily added in the future.
Sorry for taking so long. I hope to get something about it by the weekend.
franciscojunior commentedon Apr 17, 2014
Just created a pull request which adds support for json datatype.
@drusellers , you will now be able to set the NpgsqlDbType to Json.
For while, the only way to get json support is to set the NpgsqlDbType. As json datatype looks just like string, Npgsql won't be able to tell the difference between a text and json if you simply set the parameter value.
Regarding your changes to omit the parameter cast (which is also another possible solution) I'm working on this support too. See #146 and #125
franciscojunior commentedon Apr 17, 2014
I also added a wiki page which explains how to add custom datatypes to Npgsql. It is very basic at this moment, but I'll fill it with more details. Please, check it out and let me know what you think.
https://github.com/npgsql/Npgsql/wiki/How-to-add-a-custom-type-to-Npgsql
drusellers commentedon Apr 17, 2014
👍 AWESOME
On Thu, Apr 17, 2014 at 4:14 PM, Francisco Figueiredo Jr. <
[email protected]> wrote:
franciscojunior commentedon Jun 27, 2014
@drusellers , we added support for json and jsonb and hstore as well. See #242 (comment) for more information.
Would you mind to check latest master branch and test if it is working for you now?
Thanks in advance.
roji commentedon Jul 17, 2014
I'm going to go ahead and close this, if any issue is found with JSON support please reopen.
drusellers commentedon Nov 7, 2014
👍 everything looks good