# SQL Parser in Ruby

**URL:** <https://www.ruby-forum.com/t/sql-parser-in-ruby/99607>\
**Category:** Ruby\
**Created:** [July 24, 2006, 2:10pm UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607 "2006-07-24T14:10:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicwilliams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicwilliams](https://www.ruby-forum.com/u/nicwilliams)\
**Post date:** [July 24, 2006, 2:10pm UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607/1 "2006-07-24T14:10:10Z")

</div>

Has anyone taken the time to bang together an SQL parser for Ruby?

Cheers  
Nic

---

<div class="post-metadata">

**Author:** ![nicwilliams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicwilliams](https://www.ruby-forum.com/u/nicwilliams)\
**Post date:** [July 24, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607/2 "2006-07-24T17:43:11Z")

</div>

I imagine it wouldn’t be too difficult, but what good would an SQL92  
parser be?

---

<div class="post-metadata">

**Author:** ![nicwilliams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicwilliams](https://www.ruby-forum.com/u/nicwilliams)\
**Post date:** [July 25, 2006, 9:32am UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607/3 "2006-07-25T09:32:37Z")

</div>

Matthew H. wrote:

> I imagine it wouldn’t be too difficult, but what good would an SQL92  
> parser be?

I wanted it for the subset of grammar for create/update/delete  
tables/indexes etc - the stuff that some dbs store in data dictionary  
tables, but MySQL doesn’t. If the database generation sql was available,  
then the data dictionary information could be reengineered.

Cheers  
Nic

---

<div class="post-metadata">

**Author:** ![nicwilliams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicwilliams](https://www.ruby-forum.com/u/nicwilliams)\
**Post date:** [July 25, 2006, 1:30pm UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607/4 "2006-07-25T13:30:44Z")

</div>

I believe that there is a feature in Ruby on Rails, which belongs to  
ActiveRecord, that allows you to export existing DB structure in the  
Ruby upgrade script, which in turn generates SQL.  
May be this will solve Your issue.

I hope that I have understood your problem correct.

Dmirty

---

<div class="post-metadata">

**Author:** ![nicwilliams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicwilliams](https://www.ruby-forum.com/u/nicwilliams)\
**Post date:** [July 25, 2006, 1:33pm UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607/5 "2006-07-25T13:33:10Z")

</div>

Dmitry B. wrote:

> I believe that there is a feature in Ruby on Rails, which belongs to  
> ActiveRecord, that allows you to export existing DB structure in the  
> Ruby upgrade script, which in turn generates SQL.  
> May be this will solve Your issue.

It certainly should do something like that,shouldn’t it - given it  
reflectively determines the table schema at runtime.

I’ll go hunt for the code.

Thanks for the reminder.

Cheers  
Nic

---

<div class="post-metadata">

**Author:** ![nicwilliams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicwilliams](https://www.ruby-forum.com/u/nicwilliams)\
**Post date:** [June 6, 2008, 3:09am UTC](https://www.ruby-forum.com/t/sql-parser-in-ruby/99607/6 "2008-06-06T03:09:12Z")

</div>

Dr Nic wrote:

> Dmitry B. wrote:
> 
> > I believe that there is a feature in Ruby on Rails, which belongs to  
> > ActiveRecord, that allows you to export existing DB structure in the  
> > Ruby upgrade script, which in turn generates SQL.  
> > May be this will solve Your issue.
> 
> It certainly should do something like that,shouldn’t it - given it  
> reflectively determines the table schema at runtime.
> 
> I’ll go hunt for the code.
> 
> Thanks for the reminder.
> 
> Cheers  
> Nic

Hi,  
im a newbie and want to know if this sql parser in ruby is already out  
there?

thanks.
