Quoting Integers

I got the impression that quoting integers in SQL queries is disapproving, but I recently found out that well-known structures like Django adhere to this practice. Is this really acceptable?

+6
sql
source share
3 answers

The question implies that you first put the bare values ​​in your SQL query. I think the most β€œacceptable” practice is to parameterize the query instead - so you don’t have to worry about such problems; Let the data access library handle it for you.

+8
source share

Quoting integers in SQL has only a slight performance limitation. Removing quotes is much less than converting an ASCII representation to a binary integer.

Therefore, I would say that this is quite acceptable, especially for the RAD framework.

0
source share

I'm not sure about all the SQL databases, but SQL Server implicitly converts the quoted number to int. For example, the following returns 166 in SQL Server 2000:

 select '500'/3 
0
source share

All Articles