user2382627
user2382627

Reputation:

Save jsonb in postgres database

I have a table in Postgres with a jsonb column. I'm using Entity Framework to upsert data on this table, but I'm always getting the error

Input string was not in a correct format

because of the jsonb column.

This is an example of a query I generate:

INSERT INTO example_table (id, name, details) 
VALUES (1, 'john','{\r\n  \"age\": \"17\"\r\n}') 
ON CONFLICT (name) DO NOTHING

This is the command I'm trying to execute:

_context.ExecuteSqlRaw("INSERT INTO example_table (id, name, details) VALUES (1, 'john','{\r\n  \"age\": \"17\"\r\n}') ON CONFLICT (name) DO NOTHING");

If I remove the json the query is executed perfectly.

What am I doing wrong?

Upvotes: 0

Views: 501

Answers (1)

Ramin Faracov
Ramin Faracov

Reputation: 3303

Json and Jsonb doesn't support \n, \r symbols. Use this:

INSERT INTO example_table (id, name, details) 
VALUES 
(1, 'john','{"age":"17"}') 
ON CONFLICT (name) DO NOTHING 

Upvotes: 0

Related Questions