SQL call formatting style

Bradley Baetz bbaetz at acm.org
Sat Mar 29 05:19:12 UTC 2003


On Wed, Mar 26, 2003 at 09:10:00AM +0000, Gervase Markham wrote:
> But, what's the advantage of
> qq{FOO
>    BAR}
> over
> "FOO
>  BAR"
> ? I find the latter easier to read.

well, generally we'd prefer '' (or q{}) because they don't inerpolate.
The main difference is that we can include quotes in there, without
extra escaping which is harder to read. Not for params (which use ?
placeholders), but more for literal strings. Compare:

'SELECT id
   FROM flags
  WHERE status=\'?\'
'

and

q{SELECT id
    FROM flags
   WHERE status='?'
 }

Now, we don't have many of those sorts of things (we tend to use 0/1 int
flags instead), but we do have some. Flags and tokens are the main
examples. (We don't want to use placeholders here, where the search
terms are constant. Mainly because using bind vars would preclude the
use of histograms - for example there are probably more ? flags than -
ones, so the access path could change, but also because if its always
constant it makes stuff clearer to read if the argument is right there
with the rest of the query)

It also looks a bit nicer in editors - you can distinguish it from
'regular' strings, for example based on syntax highlighting.

I'm not that attached, although it is sort of the dbi standard.

Bradley



More information about the developers mailing list