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.

Fails to insert jsonb values in Postgres

See original GitHub issue

We have a table with a field of type jsonb, which becomes string in the generated type, but it doesn’t seem to work when inserting a string with the json format, the exception I get is:

Npgsql.PostgresException (0x80004005): 42804: column "test" is of type jsonb but expression is of type text
Exception data:
    Severity: ERROR
    SqlState: 42804
    MessageText: column "test" is of type jsonb but expression is of type text
    Hint: You will need to rewrite or cast the expression.
    Position: 97
    File: parse_target.c
    Line: 588
    Routine: transformAssignedExpr

when trying to insert """{"publisher": "test"}""". Would you be able to help with this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
MargaretKrutikovacommented, Oct 17, 2021

Oh, that’s genius 😄 I almost made it work with this new suggestion … will need to clean up the mess and open a PR in the beginning of the week. Yeah, I am enjoying the process, thanks for the help!

1reaction
JordanMarrcommented, Oct 16, 2021

The plot thickens!

It seems that we may need to check for the existence of the column metadata attribute in the InsertExpressionBuilder and UpdateExpressionBuilder when record properties are being added.

The nice thing is that the LinqExpressionVisitors.visitPropertySelector returns MemberInfo that should give us the attribute metadata for free. So if any metadata exists, it can be added to the InsertQuerySpec or UpdateQuerySpec in the order at which the columns were added.

Then the QueryContext insert and update methods should have enough info to create a Map of parameter type info to the BuildCommand methods.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Getting error when trying to insert JSON field in Postgres
I am getting below error: ERROR: syntax error at or near "{" LINE 1: ...nc_desc,user_id,container_path) ...
Read more >
Postgresql INSERT Issue (JSONB) - Questions
So the scenario is that I'm inserting a JSON object into a Postgresql table (to a JSONB column) for warehousing purposes.
Read more >
Inserting JSON into PostgreSQL: 3 Comprehensive Aspects
To work with JSON and PostgreSQL, you must first understand the following aspects of Inserting JSON into PostgreSQL:
Read more >
Insert Jsonb into Postgresql Database
Hi, i need to insert some data into a Postgresql Database. ... ERROR: column "data" is of type jsonb but expression is of...
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