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 already have a pull request which adds support for json type: #168 . Did you try that yet? I'm asking that because initial jsonb support would be almost the same code.
If json support added by this pr is working ok, jsonb support would be easy to do.
Please, give it a try and let me know if it works ok for you.
No I havent tried your json implementation yet. I am currently using Json.net to serialize and deserialize to/from text and using linq to json for querying (migrating from another db). I currently in need of the indexing capabilities provided by the jsonb and hstore types to shift that work to the db.
Ill try saving the serialized output as json instead of text
@roji, @franciscojunior - I gave the jsonb funtionality a test and it works great so far! I'm able to write jsonb data as well as query using the jsonb functions.
As an aside, I prefer using Dapper for data access and had to write an implementation of the ICustomQueryParamter interface in order to set the correct NpgsqlParameter data type. Here's that code in case it's useful to others:
public class JsonbString : Dapper.SqlMapper.ICustomQueryParameter
{
private string _json;
public JsonbString(string json)
{
_json = json;
}
public void AddParameter(System.Data.IDbCommand command, string name)
{
var param = (NpgsqlParameter)command.CreateParameter();
param.ParameterName = name;
param.Value = _json;
param.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
command.Parameters.Add(param);
}
}
...
class MyDto
{
JsonbString data { get; set; }
}
...
conn.Execute("INSERT INTO jsonb_table(data) VALUES(:data)", myDto);
Reacted by Andrii Kozhyn, Julian May, Philip Holly, Duncan Roosma and Alex Burck
Hi. It is mapped as a Dictionary<string, string> so as long as you have configured the server for hstore support (see Postgresql docs), it should work out of the box work with the latest master branch.
@jmwright in 2.2 we only support hstore as a text value, not as a dictionary of strings. So it's your responsibility to construct a valid hstore string from whatever data you have, and to parse the results.
In v3.0 (our master branch), our next major version, hstore is supported as a dictionary of string key-value pairs, like @Emill mentioned above. However, that version isn't stable yet, so for now you'll have to make do...
Activity
franciscojunior commentedon May 25, 2014
I already have a pull request which adds support for json type: #168 . Did you try that yet? I'm asking that because initial jsonb support would be almost the same code.
If json support added by this pr is working ok, jsonb support would be easy to do.
Please, give it a try and let me know if it works ok for you.
namtih58 commentedon May 27, 2014
No I havent tried your json implementation yet. I am currently using Json.net to serialize and deserialize to/from text and using linq to json for querying (migrating from another db). I currently in need of the indexing capabilities provided by the jsonb and hstore types to shift that work to the db.
Ill try saving the serialized output as json instead of text
roji commentedon Jun 21, 2014
I've just merged @franciscojunior's json support into master, and added support for hstore and the new jsonb type (pg9.4beta1) as well.
@namtih58, can you please grab the latest master build at build.npgsql.org (http://build.npgsql.org/viewLog.html?buildId=1348&buildTypeId=npgsql_all&tab=artifacts) and confirm that it works for you?
kppullin commentedon Jul 10, 2014
@roji, @franciscojunior - I gave the jsonb funtionality a test and it works great so far! I'm able to write jsonb data as well as query using the jsonb functions.
As an aside, I prefer using
Dapperfor data access and had to write an implementation of theICustomQueryParamterinterface in order to set the correct NpgsqlParameter data type. Here's that code in case it's useful to others:roji commentedon Jul 10, 2014
Great @kppullin, thanks for testing and the Dapper proposal, I'm also a pretty big fan of Dapper.
[-]Surport Hstore and Jsonb[/-][+]Support Hstore and Jsonb[/+]jmwright commentedon Mar 27, 2015
Is there an example anywhere of how to use Hstore?
Emill commentedon Mar 27, 2015
Hi. It is mapped as a Dictionary<string, string> so as long as you have configured the server for hstore support (see Postgresql docs), it should work out of the box work with the latest master branch.
jmwright commentedon Mar 27, 2015
Thanks for the reply.
I keep getting an unexpected end of string error when I try the following.
The following dictionary is filled with key/value pairs.
PostgresDAL.CreateConnection is just the following.
Here's the exception I get.
Any thoughts on what I'm doing wrong?
roji commentedon Mar 28, 2015
@jmwright, what version of Npgsql are you using?
jmwright commentedon Mar 28, 2015
@roji - 2.2.5 from NuGet
roji commentedon Mar 28, 2015
@jmwright in 2.2 we only support hstore as a text value, not as a dictionary of strings. So it's your responsibility to construct a valid hstore string from whatever data you have, and to parse the results.
In v3.0 (our master branch), our next major version, hstore is supported as a dictionary of string key-value pairs, like @Emill mentioned above. However, that version isn't stable yet, so for now you'll have to make do...
jmwright commentedon Mar 28, 2015
OK, thanks. I'll switch to using a string.
chaliy commentedon Jan 8, 2016
There is easier way to insert json(and probably jsonb) values:
dukecheng commentedon Oct 9, 2016
@chaliy thanks, your code is worked.
makcakaya commentedon Oct 19, 2016
@chaliy Thanks! It works with Dapper too (I don't know if there is or not any reason not to do so but still :))