On 1/20/2016 11:31 AM, Rob wrote:
I will try to keep it try separated...
As the one who sent you here from WEB400, I feel some responsibility for
adding to your frustration.
When you are asking about the database, I think this is the best list.
So your question: 'is does DB2 casting to be trusted....' fits here, and
the answer is 'Yes, of course' it is to be trusted. The place to go in
the manual is 'Casting between data types.'
http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzcastdt.htm
Both CHAR and VARCHAR can be cast to smallint (for example).
I am not trying to stuff strings into numerical fields.
Actually, that is EXACTLY what you are trying to do. The database
expects a smallint (for example) and you are presenting a string. Our
human eyes see the digits and think 'number' but because the code has it
enclosed within quotes, it is a string literal.
I know all strings must be encompassed in single quotes.
And I certainly could type check each value and decide
if the single quotes were necessary.
But is the time used to type check in PHP if DB2
stores a numeric value in a string faster than the
if type check is numeric?
There are several ways to look at this.
There is time spent to type check the destination column.
There is time spent for DB2 to do the implicit CAST from string to
[numeric].
Which takes longer? I'm sure that depends on your environment. If I
were concerned, I'd model it both ways and INSERT a million rows or so.
If it turned out that there was a 5 second difference between the two
methods, would you change the code? If it turned out there were 2 hours
difference? Would you change the code if your actual application always
finished in less than one seconds, regardless of the timing tests over a
million rows?
As an Amazon Associate we earn from qualifying purchases.