Home >Backend Development >Golang >How to Resolve 'sql: expected 1 destination arguments in Scan' Error in Golang QueryRow with JSONB Data?

How to Resolve 'sql: expected 1 destination arguments in Scan' Error in Golang QueryRow with JSONB Data?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-06 09:59:021112browse

How to Resolve

“sql: expected 1 destination arguments in Scan” Error in Golang QueryRow with JSONB Data

The issue arises when attempting to use db.QueryRow to retrieve data from a JSONB column and storing the results in multiple destination arguments. However, the query returns only one field, leading to the "expected 1 destination arguments in Scan" error.

To resolve this issue, there are several approaches:

  • Return Multiple Fields in the Query:
    Modify the query to return each field as separate columns, allowing for each value to be stored in its own destination argument:
err := db.QueryRow("SELECT data->>'id', data->>'type', data->>'title' FROM message WHERE data->>'id'="

The above is the detailed content of How to Resolve 'sql: expected 1 destination arguments in Scan' Error in Golang QueryRow with JSONB Data?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn