Skip to content

Numeric converted to float instead of string #66

@martinoshub

Description

@martinoshub

Hi guys. Please tell me that there's a way without altering your code to make sure that when fetching a row from the database, a Numeric type gets converted to string instead of float? Choosing to make float the default type means there's potential data loss and no way to recover. Whereas with a string type I could always convert it to float if I wanted to.

Internal/PgSqlResultIterator.php

        'N' => match ($oid) { // Numeric
            700, 701, 1700 => (float) $value, // float4, float8, and numeric to float
            790 => $value, // money includes currency symbol as string
            default => (int) $value, // All other numeric types cast to an integer
        },

It would be great to have a way to change this behavior while setting up the class so that numerics are returned as a string. Thanks so much. And thank you for this wonderful library by the way, I really love Amphp with fibers and it's great that there's a Postgres lib for it.

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