https://slingdata.io logo
Hi, I'm encountering a precision loss
# sling-help
j
Hi, I'm encountering a precision loss when transferring decimal values from SQL Server to Postgres through Sling. For example, the value 0.0270 (decimal(6,5)) in a rate field is becoming 0 when copied to Postgres. Sling assigned the target field a numeric(6,5) type.
Copy code
replication_config = {
    "source": "SQLSERVER_SOURCE",
    "target": "POSTGRES_TARGET",
    "defaults": {
        "mode": "full-refresh",
        "object": "{stream_schema}_{stream_table}",
        "target_options": {
            "column_casing": "lower",
        },
    },
  "streams"{
    "SQLSERVER_SOURCE.dbo.ptax_rates": {
            "object": "iscs.ptax_rates",
            "mode": "full-refresh",
            "target_options": {
                "isolation_level": "read_committed",
                "column_casing": "lower",
            },
        },
f
Could you share your trace level log? env var
DEBUG=TRACE
. Remove sensitive info.
j
let me try that.
still loading it as 0
@flarco
Also the target field type actually becomes numeric(18) not numeric(6,5) as I misspoke above.
f
so the quick bandaid is to define those columns as `float`:
Copy code
replication_config = {
    "source": "SQLSERVER_SOURCE",
    "target": "POSTGRES_TARGET",
    "defaults": {
        "mode": "full-refresh",
        "object": "{stream_schema}_{stream_table}",
        "target_options": {
            "column_casing": "lower",
        },
    },
  "streams"{
    "SQLSERVER_SOURCE.dbo.ptax_rates": {
            "object": "iscs.ptax_rates",
            "mode": "full-refresh",
            "target_options": {
                "isolation_level": "read_committed",
                "column_casing": "lower",
            },
            "columns": {"ptax_rate":"float", "assess_rate": "float"}
        },
That should "override" the source type and should load correctly with
double precision
. You can put
string
as well, and then cast it back as decimal in Yellowbrick. The PG decimal type mapping is [hard-coded](https://github.com/slingdata-io/sling-cli/blob/main/core/dbio/templates/types_general_to_native.tsv) to
numeric
without decimal/precision, so there is no way to override that.
Let me think of a long term solution. I think for example, adding an option to treat decimal as float/string in [column typing](https://docs.slingdata.io/concepts/replication/columns#column-typing), so it does for all decimal cols, so you don't have to specify manually.
j
That worked!
f
Glad to hear it
j
Thank you so much. I'm really enjoying Sling!