Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

It seems as if there is a bug in the arel code of the adapter. Calling "Model.first" generates the following error:

ActiveRecord::StatementInvalid: ActiveRecord::ConnectionAdapters::SQLAnywhereException: Syntax error near '<' on line 1: SELECT TOP #<arel::nodes::limit:0x00000102a0bbf0> "mi_def".* FROM "mi_def"

You can get around it by calling "Model.first(1)", but that doesn't help when you have associations. Trying to access an associated model generates the same error.

asked 25 Apr '11, 23:35

Anth's gravatar image

accept rate: 100%

edited 26 Apr '11, 13:50

I fixed it myself by changing the following line in activerecord-sqlanywhere-adapter/lib/arel/visitors/sqlanywhere.rb

("TOP #{o.limit}" if o.limit),


(visit( if o.limit),

I will try to submit a patch when I get a chance.

permanent link

answered 26 Apr '11, 00:31

Anth's gravatar image

accept rate: 100%

edited 26 Apr '11, 00:50

On second thought, maybe not. The git project is read-only. Any idea on how to submit patches?

(26 Apr '11, 00:51) Anth

Thank you for fixing this. Please create a git patch, and email it to


(28 Apr '11, 11:46) Eric Farrar


this still appears to be broken. Why wasn't the gem updated? Is there a problem with this patch?

On another note when can we expect Rails 3.1 support?

permanent link

answered 11 Nov '11, 12:05

clst's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 25 Apr '11, 23:35

question was seen: 1,732 times

last updated: 11 Nov '11, 12:05