[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A 5.3 change is biting us hard...
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 10 Feb 2016 15:05:52 -0200
> 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