postgresql - What is the difference between keeping column on left of = in sql -


i reading else sql , code this

there view called user_v column path array

select * user_v 'user_type'=path[2] 

can't use

path[2] = 'user_type'

this precaution taken programmers in languages assignment , comparison can confused, such c or php, following statement looks innocent:

 if ( $foo = 1 ) 

but assigning 1 $foo, , if evaluate true (in php, @ least, 1 true). meant if ( $foo == 1 ).

if reverse arguments, error becomes obvious sooner:

if ( 1 = $foo ) # syntax error if ( 1 == $foo ) # desired behaviour 

this known "yoda coding", , in the coding standards of wordpress, example.

see also: why put constant before variable in comparison?

in sql, there less chance of such muddle, since although = can mean either assignment or comparison, there situations typo select wrong meaning.

however, if coding standards every other language used project mandate it, make sense reinforce habit using in sql, since can't think of specific reason not write way.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -