Johannes Gorset
Johannes Gorset

Reputation: 8785

Quoting integers

I've been under the impression that quoting integers in SQL queries is frowned upon, but I've recently learned that prominent frameworks like Django adheres to this practice. Is it in fact perfectly acceptable?

Upvotes: 6

Views: 1243

Answers (3)

Mark Ransom
Mark Ransom

Reputation: 308391

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

select '500'/3

Upvotes: 0

Andomar
Andomar

Reputation: 238166

Quoting integers in SQL has only a minor performance penalty. Removing the quotes is much less work than converting the ASCII representation to a binary integer.

So I'd say it's perfectly acceptable, especially for a RAD framework.

Upvotes: 0

Aaronaught
Aaronaught

Reputation: 122654

The question implies that you put naked values in your SQL query in the first place. I think the most "acceptable" practice would be to parameterize the query instead - that way you don't have to concern yourself with issues such as this; let the data access library handle it for you instead.

Upvotes: 9

Related Questions