freelancing-god/thinking-sphinx — Issue #331: thinking sphinx generates invalid SQL
Author: antage
Created: 2012-02-01 09:50:58+00:00
State: open

Two simple AR-models in PostgreSQL:

```
class News < ActiveRecord::Base
has_one :news_info

define_index do
indexes news_info.title
indexes news_info.promo
indexes news_info.text
end
end

class NewsInfo < ActiveRecord::Base
belongs_to :news
# contains title, promo and text columns
end
```

`rake ts:config` generates following sql:

```
sql_query = SELECT "news"."id" * 1::INT8 + 0 AS "id" , "news"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 3780505231 AS "class_crc" FROM "news" WHERE ("news"."id" >= $start AND "news"."id" <= $end) GROUP BY "news"."id", , , , "news"."id"
```

Notice this fragment: `GROUP BY "news"."id", , , , "news"."id"`
Due to `, , , ,` PostgreSQL reports about error:

```
ERROR: index 'news_core': sql_range_query: ERROR: syntax error at or near ","
LINE 1: ... 1 AND "news"."id" <= 1024) GROUP BY "news"."id", , , , "new...
^
```