# Rails generates query with reserved word for field name

**URL:** <https://www.ruby-forum.com/t/rails-generates-query-with-reserved-word-for-field-name/56114>\
**Category:** Rails\
**Created:** [March 28, 2006, 11:05am UTC](https://www.ruby-forum.com/t/rails-generates-query-with-reserved-word-for-field-name/56114 "2006-03-28T11:05:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [March 28, 2006, 11:05am UTC](https://www.ruby-forum.com/t/rails-generates-query-with-reserved-word-for-field-name/56114/1 "2006-03-28T11:05:33Z")

</div>

For some reason, rails is generating this SQL:

SELECT FIRST 1 \* FROM questions WHERE (parent\_id IS NULL) ORDER BY  
position DESC

1. There is no column named position referenced in my code.

2. POSITION is a reserved word in SQL92. It is the name of a string  
function that returns the offset of one string within another. I  
believe that this is a bug in Rails. Either position should be quoted  
or the property it is trying to use should be renamed since no SQL92  
compliant database would honor this query (DB2, Oracle, postgres,  
firebird, etc).

I have scanned all files in my project for the word “position”, and the  
only places it appears are in reference to HTML element positions.

Here is the Questions code:

class Question \< ActiveRecord::Base  
require ‘presentations’  
require ‘question’

include UUIDHelper

has\_many :answers, :order =\> :seq  
belongs\_to :presentation, :class\_name =\> “Presentations”, :foreign\_key  
=\> :presentation\_id  
belongs\_to :parent, :class\_name =\> “Quiz”  
acts\_as\_list :scope =\> :parent\_id

# TODO: auto-increment for seq

end

create table questions  
(  
ID char(36) not null primary key,  
PARENT\_ID char(36) not null,  
presentation\_id char(36) not null,  
seq integer not null,

foreign key (PARENT\_ID) references quizzes(ID),  
foreign key (presentation\_id) references presentations(ID)  
);  
create unique ascending index quest\_seq on questions (PARENT\_ID,SEQ);

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [March 28, 2006, 11:17am UTC](https://www.ruby-forum.com/t/rails-generates-query-with-reserved-word-for-field-name/56114/2 "2006-03-28T11:17:22Z")

</div>

David J. wrote:

> For some reason, rails is generating this SQL:
> 
> SELECT FIRST 1 \* FROM questions WHERE (parent\_id IS NULL) ORDER BY  
> position DESC
> 
> 1. There is no column named position referenced in my code.  
> position is used for acts\_as\_list for ordering list members. You’re  
> right, though, it should be quoted. Don’t know if that helps at all…
