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

Mary-Kate Olsen
Release: 2024-11-06 09:59:02
Original
992 people have browsed it

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'="
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!