Skip to content

Inconsistent Float Formatting Between go-sqlcmd and ODBC SQLCMD Versions #555

Open
@AndreaPQ

Description

@AndreaPQ

Description
In Windows OS the go-sqlcmd application produces a different output format for FLOAT data types compared to the ODBC-based SQLCMD.EXE when executing the same SQL query. This discrepancy can cause issues for applications and scripts that rely on consistent float formatting.

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

INSERT INTO [dbo].[Point] ([PointId], [SessionId], [Longitude], [Latitude]) VALUES 
  (1, 3, 788991.19988463481, 4713347.3103808956),
  (2, 3, 789288.40771771886, 4712632.075629076),
  (3, 3, 788569.36558582436, 4714608.0418091472);
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" -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" -s";" -W

Observed Behavior

go-sqlcmd Output:

PointId;SessionId;Longitude;Latitude
-------;---------;---------;--------
1;3;788991.1998846348;4.713347310380896e+06
2;3;789288.4077177189;4.712632075629076e+06
3;3;788569.3655858244;4.714608041809147e+06

ODBC SQLCMD Output:

PointId;SessionId;Longitude;Latitude
-------;---------;---------;--------
1;3;788991.19988463481;4713347.3103808956
2;3;789288.40771771886;4712632.075629076
3;3;788569.36558582436;4714608.0418091472

Expected Behavior

The float formatting in the output of go-sqlcmd should align with the behavior of the ODBC SQLCMD to maintain compatibility and consistency across different SQLCMD implementations.

Environment

  • go-sqlcmd version: 1.8.1
  • ODBC sqlcmd version: 15.0.4410
  • Database Server: SQL Server 2019, SQL Server 2022
  • Operating System: Windows 11, Windows server

Additional Information

This issue primarily affects the formatting of float numbers. For example:

  • In go-sqlcmd, 4.713347310380896e+06
  • In ODBC sqlcmd, 4713347.3103808956

The scientific notation output from go-sqlcmd is less intuitive and might require additional parsing in downstream applications.

Request

Please investigate this behavior and consider aligning the float formatting of go-sqlcmd with the output of the ODBC-based SQLCMD.EXE.

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