lua-users home
lua-l archive

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


> This little detail becomes "great" fun when you use numbers as integers in SQL statement:
> 
> local id = tonumber(query.id)  -- 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".

What is funny is that 'tonumber' follows the syntax given to it. If it
is returning a float, it is because 'query.id' has a float format (either
a point or an exponent). Anyway, the correct approach is to follow
Daniel's suggestion.

-- Roberto