lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

We switched from Lua 5.2 to Lua 5.3 and suddenly a seemingly small change in Lua's number formatting is hitting us really hard:

Before 5.2, a number value of 41.0 would produce a string of '41'.  After 5.3, it produces '41.0':

Lua 5.2.3  Copyright (C) 1994-2013, PUC-Rio
> a = 41.0
> print(a)

Lua 5.3.2  Copyright (C) 1994-2015, PUC-Rio
> a = 41.0
> print(a)

This little detail becomes "great" fun when you use numbers as integers in SQL statement:

local id = tonumber(  -- Get the id from a string in a webform
local res = db:execParams('select * from foo where id = $1::integer', id)

In PostgreSQL this results in an error like "Invalid input syntax for type integer: 41.0".

I will find a way to deal with this (probably in the luapgsql interface), for now I just wanted to share the fun ;)