9

hstore 属性でクエリ結果を並べ替えるにはどうすればよいですか?

@items = Item.includes(:product).order('products.properties @> hstore("platform")')

原因

PG::Error: ERROR:  column "platform" does not exist
LINE 1: ...oduct_id"  ORDER BY products.properties @> hstore("platform"...

platformプロパティ列に格納される hstore キーで、hstore タイプです。

4

1 に答える 1

17

二重引用符は、PostgreSQL (および標準に従うその他のデータベース) で識別子 (テーブル名や列名など) を引用するために使用されます。だからあなたが言うとき:

hstore("platform")

PostgreSQL は"platform"引用符で囲まれた列名と見なし、platform列がないため、エラーが発生します。

標準 SQL の文字列は一重引用符で囲まれています。

.order("products.properties @> hstore('platform')")

これはおそらくまだ失敗しますが、あまり意味がなく、ここでhstore('platform')使用することもできません。意味@>a @> b

hstore には hstorea が含まれていますかb

hstore'platform'内のキーの値をソートしようとしている場合は、次のようにキーを検索するために使用する必要があります。properties->'platform'

.order("products.properties -> 'platform'")
于 2013-04-29T18:11:03.683 に答える