![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
This is normaol behavior. I belive that I have found a bug - or maybe it was done on purpose. Have a look at this query: SELECT integer_field FROM bugtable WHERE (CASE WHEN '' <> '' THEN integer_field = '' ELSE integer_field = 0 END); Result: ERROR: invalid input syntax for integer: "" Here CASE have int type and you are trying to cast '' to int. Error. Well, I see that you have not run this query: In this case the query is |
| SELECT text_field FROM bugtable WHERE (CASE WHEN '' <> '' THEN text_field = '' ELSE text_field = '1' END); Result: 1 rows fetched (0,02 sec) Here CASE have text type. Everything is fine. Yes, becouse "CASE WHEN '' <> ''" is send false and is using "text_field |
#2
| |||
| |||
|
|
On Friday 19 December 2003 09:02, Marek Lewczuk wrote: But until it's evaluated ''<>'' it doesn't know it is false. When building the CASE expression, it's trying to map types to each elements and notes that '' is not an int. Only after this stage will it actually try to evaluate the expression. |
#3
| |||
| |||
|
|
Because that's a syntax check, which does NOT evaluate any of the expressions, only the types of them. Even if it will not be executed ever, it is still wrong, and it should generate an error, because it means a mistake on your side which potentially could leave to results you didn't expect if executed as is. If it would not generate error in these cases, you would scream when you by mistake write a wrong query and it doesn't give you the right errors. Say thanks to the parser that it catches your errors and doesn't let you do detective work to find out why your queries are not working as you expect them to work. |
|
Cheers, Csaba. |
#4
| |||
| |||
|
|
Alexander Litvinov wrote: This is normaol behavior. I belive that I have found a bug - or maybe it was done on purpose. Have a look at this query: SELECT integer_field FROM bugtable WHERE (CASE WHEN '' <> '' THEN integer_field = '' ELSE integer_field = 0 END); Result: ERROR: invalid input syntax for integer: "" Here CASE have int type and you are trying to cast '' to int. Error. Well, I see that you have not run this query: In this case the query is trying to make integer_field = '' --> but it shouldn't, becouse "CASE WHEN '' <> ''" is false, so "ELSE integer_field = 0" should be used. |
#5
| |||
| |||
|
|
Well, I must say that it is wird action... Why to check both elements of CASE expression, if we know for sure that only one will be executed ? |
#6
| |||
| |||
|
|
I belive that I have found a bug - or maybe it was done on purpose. Have a look at this query: SELECT integer_field FROM bugtable WHERE (CASE WHEN '' <> '' THEN integer_field =3D '' ELSE integer_field =3D 0 END); Result: ERROR: invalid input syntax for integer: "" |
| SELECT text_field FROM bugtable WHERE (CASE WHEN '' <> '' THEN text_field =3D '' ELSE text_field =3D '1' END); Result: 1 rows fetched (0,02 sec) |
#7
| |||
| |||
|
|
Well, I must say that it is wird action... Why to check both elements of CASE expression, if we know for sure that only one will be executed ? |
![]() |
| Thread Tools | |
| Display Modes | |
| |