# Correctly Style of SQL Formatting in Ruby Cude

**URL:** <https://www.ruby-forum.com/t/correctly-style-of-sql-formatting-in-ruby-cude/168438>\
**Category:** Ruby\
**Created:** [May 20, 2009, 8:08pm UTC](https://www.ruby-forum.com/t/correctly-style-of-sql-formatting-in-ruby-cude/168438 "2009-05-20T20:08:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rilindo\_foster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/46a35a/32.png) [@rilindo\_foster](https://www.ruby-forum.com/u/rilindo_foster)\
**Post date:** [May 20, 2009, 8:08pm UTC](https://www.ruby-forum.com/t/correctly-style-of-sql-formatting-in-ruby-cude/168438/1 "2009-05-20T20:08:02Z")

</div>

## Is there a correct style of putting in SQL statements in Ruby? My SQL statements tend to go around 200-400 columns, which looks _very_ ugly.

Rilindo F.  
AOL Instant Messenger: rilindo  
Google Talk: removed\_email\_address@domain.invalid  
Web S.: [http://www.monzell.com](http://www.monzell.com)  
Primary: removed\_email\_address@domain.invalid  
Secondary: removed\_email\_address@domain.invalid  
"Rich bachelors should be heavily taxed. It is not fair that some men  
should be happier than others. – Oscar Wilde

---

<div class="post-metadata">

**Author:** ![rilindo\_foster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/46a35a/32.png) [@rilindo\_foster](https://www.ruby-forum.com/u/rilindo_foster)\
**Post date:** [May 20, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/correctly-style-of-sql-formatting-in-ruby-cude/168438/2 "2009-05-20T20:56:02Z")

</div>

rilindo foster wrote:

> Is there a correct style of putting in SQL statements in Ruby? My SQL  
> statements tend to go around 200-400 columns, which looks _very_ ugly.

A\> use ActiveRecord, or one of the other SQL generators

B\> this:

```
 SELECT FROM users
  WHERE is_premier = 1
    AND charge_at > NOW()

```

Notice that all SQL keywords are in UPCASE, just for emphasis, and  
there’s a  
vertical gutter in the 6th relative column. The SQL books advocate that  
gutter,  
I think.

Also, if you have 200-400 column strings, you need to get more DRY. That  
leads  
back to ActiveRecord…

---

<div class="post-metadata">

**Author:** ![rilindo\_foster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/46a35a/32.png) [@rilindo\_foster](https://www.ruby-forum.com/u/rilindo_foster)\
**Post date:** [May 21, 2009, 8:15pm UTC](https://www.ruby-forum.com/t/correctly-style-of-sql-formatting-in-ruby-cude/168438/3 "2009-05-21T20:15:38Z")

</div>

Active Record looks interest. I’ll need to look into that. Thanks!

In other news, this question made it to the top of Google’s search  
results. . . and I just noticed that I mis-spelled “code”. 😑

On Wed, May 20, 2009 at 2:55 PM, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> WHERE is_premier = 1
> AND charge_at > NOW()
> 
> ```
> 
> Notice that all SQL keywords are in UPCASE, just for emphasis, and there’s a  
> vertical gutter in the 6th relative column. The SQL books advocate that  
> gutter, I think.
> 
> Also, if you have 200-400 column strings, you need to get more DRY. That  
> leads back to ActiveRecord…

–  
Rilindo F.  
AOL Instant Messenger: rilindo  
Google Talk: removed\_email\_address@domain.invalid  
Web S.: [http://www.monzell.com](http://www.monzell.com)  
Primary: removed\_email\_address@domain.invalid  
Secondary: removed\_email\_address@domain.invalid  
"Rich bachelors should be heavily taxed. It is not fair that some men  
should be happier than others. – Oscar Wilde
