question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to write to JSONB column

See original GitHub issue

Hi! Having the same issue as #432.

Can not insert value to a table with jsonb column (tried json also). Insert code looks like this:

await _db.RequestLogs.InsertAsync(() =>
                new RequestLog
                {
                    RequestBody = JsonConvert.SerializeObject(requestBody),
                });

pg logs:

2019-01-13 17:44:35.723 MSK [16200] ERROR:  42804: column "request_body" is of type jsonb but expression is of type text at character 129
2019-01-13 17:44:35.723 MSK [16200] STATEMENT:  INSERT INTO clear_junction.request_log
	(
		request_body
	)
	VALUES
	(
		$1,
	)

Interesting, that it is ok to insert with constant:

await _db.RequestLogs.InsertAsync(() =>
                new RequestLog
                {
                    RequestBody = "{""Body"": ""body value""}",
                });

linq2db version: 2.6.1 Database Server: PostgreSQL 11.1 Database Provider: Npgsql 4.0.4 Operating system: Windows 10 Framework version: .NET Core 2.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
MaceWinducommented, Jan 13, 2019

Actually it should work with strings. Make sure your column attribute has DataType = DataType.BinaryJson property

1reaction
MaceWinducommented, Jan 13, 2019

Also if you use T4 to generate your mappings, set GenerateDataTypes=true; so DataType property will be generated for you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble storing JSON Object into JSONB column type in ...
I have a jsonb column type in my model Place : t.jsonb :location. I have the maps API returning an object of this...
Read more >
pgadmin: can't insert jsonb[] values with strings
I have jsonb[] column and it allows me to insert some nested arrays, but only with number values like {{1,2,3}, {4,5,6}, {7,8,9}} ....
Read more >
Can't insert into JSONB column from string - PostgreSQL
I have the following classs defined: public class JobTask { [AutoId] public Guid Id { get; set; } public int Type { get;...
Read more >
Documentation: 15: 8.14. JSON Types
The json data type stores an exact copy of the input text, which processing functions must reparse on each execution; while jsonb data...
Read more >
RHEL7 Postgres doesn't support jsonb - waiverdb
Unfortunately it's not as simple as just switching it from JSONB to the older JSON column type. The JSON column type does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found