Database rows scan + unknown number of columns + JSON

Searching on GO documentation;

https://golang.org/pkg/database/sql/#ColumnType.ScanType

It says “If a driver does not support this property ScanType will return the type of an empty interface.”

But this is the only way I can get my code working with SQL Server, I tried MANY times “denisenkom/go-mssqldb” library but it defiantly doesn’t work, tried all kinds of connection strings but nothing works.

You could do the JSON conversion in the database. See: https://docs.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server

Then use QueryRow and Scan into a []byte which you then write directly to the output (no need to marshal as the DB will return JSON).

I can’t test this because I don’t have a SQL Server to play with.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.