6 months ago

Bigint column is treated as int only on one table

Posted 6 months ago by dpaladin

I have this table

CREATE TABLE ventas_temporal_plazos
  venta_temporal_id bigint NOT NULL,
  tipo_plazo_id bigint,
  quincenas_plazo integer,
  incentivo numeric(12,4),
  id bigint NOT NULL,
  CONSTRAINT pk_ventas_temporal_plazos PRIMARY KEY (id)

with 2 bigint columns.

My model can be as simple as

class VentaTemporalPlazo extends Model
    protected $table = 'ventas_temporal_plazos';

When i do this

        return \App\Models\PuntoVenta\VentaTemporalPlazo::first();

i get

        "venta_temporal_id": "10115505988812",
        "tipo_plazo_id": "82",
        "quincenas": 8,
        "incentivo": "0.0000",
        "id": 2147483647

Notice how the 'id' field tries to be integer and its truncated to the max 32 bit integer; while the other 2 get converted to string.

I have a lot of tables using bigint, having them as primary key too, but only happens on this one.

I tried dropping the table and recreating it, but fails anyway. I'm using PostgreSQL, Laravel 5.6, and while my PHP version is 32 bits, i at least expect the same behaviour for all bigint columns.

Please sign in or create an account to participate in this conversation.