Skip to content

Inconsistent Behavior in go-sqlcmd: Missing Column Headers When No Results Are Returned Compared to ODBC SQLCMD #556

@AndreaPQ

Description

@AndreaPQ

Description

When executing a query that returns no results, go-sqlcmd does not include the column headers in the output, unlike the ODBC-based SQLCMD.EXE. This discrepancy can cause compatibility issues for tools or scripts expecting consistent output.

Steps to Reproduce

  1. Create the following table:
CREATE TABLE [dbo].[Point](
    [PointId] [int] NOT NULL,
    [SessionId] [int] NULL,
    [Longitude] [float] NOT NULL,
    [Latitude] [float] NOT NULL,
 CONSTRAINT [PK_Point] PRIMARY KEY CLUSTERED 
 (
     [PointId] ASC
 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
 ) ON [PRIMARY]
 GO
  1. Execute the following query using go-sqlcmd (version 1.8.1):
sqlCmd.exe -S serverName -d dbname -U username -P password -Q "SELECT TOP 10 * FROM dbo.Point WHERE 1=0" -s";" -W
  1. Execute the same query using the ODBC sqlcmd (version 15.0.4410):
sqlCmd.exe -S serverName -d dbname -U username -P password -Q "SELECT TOP 10 * FROM dbo.Point WHERE 1=0" -s";" -W

Observed Behavior

go-sqlcmd Output:


(0 rows affected)

ODBC sqlcmd Output:

PointId;SessionId;Longitude;Latitude
-------;---------;---------;--------

(Righe interessate: 0)

Expected Behavior

When no rows are returned, go-sqlcmd should still include the column headers in the output, similar to the behavior of the ODBC sqlcmd.

Additional Information

This issue primarily affects the usability of go-sqlcmd in scenarios where scripts or applications rely on column headers to process query output, even when no rows are returned.

Request

Please investigate this behavior and align the output of go-sqlcmd with the ODBC-based sqlcmd when no results are returned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions