Note.where("content REGEXP ?", 'hoge')
のようなコードを、rails c
で実行して、配列が返ってくるようにしたかったのですが、
どうもうまく動きません。
出力されるSQLは問題なさそうですし、実際データベースに対してそのSQLを実行してみると、数件の当該するレコードがヒットします。
どうしたらよいでしょうか。
# # データベース:SQLite3 $ rails -v Rails 5.2.0 $ gem list | grep active activerecord (5.2.0) [13] pry(main)> Note.all ... #<Note:0x000055701e73c740 id: 9, title: "dev", content: "hogefuga", user_id: 3, created_at: Sat, 28 Jul 2018 23:27:58 UTC +00:00, updated_at: Sat, 28 Jul 2018 23:27:58 UTC +00:00>, #<Note:0x000055701e73c560 id: 10, title: "dev_", content: "hogehoge", user_id: 3, created_at: Sat, 28 Jul 2018 23:28:21 UTC +00:00, updated_at: Sat, 28 Jul 2018 23:28:21 UTC +00:00>] # 一見出来ているように見える [14] pry(main)> Note.where("content REGEXP ?", 'hoge') Note Load (0.3ms) SELECT "notes".* FROM "notes" WHERE (content REGEXP 'hoge') Note Load (0.3ms) SELECT "notes".* FROM "notes" WHERE (content REGEXP 'hoge') LIMIT ? [["LIMIT", 11]] => #<Note::ActiveRecord_Relation:0x3ff536212788> # しかし取得できていない [15] pry(main)> Note.where("content REGEXP ?", 'hoge')[0] Note Load (0.3ms) SELECT "notes".* FROM "notes" WHERE (content REGEXP 'hoge') ActiveRecord::StatementInvalid: SQLite3::SQLException: no such function: REGEXP: SELECT "notes".* FROM "notes" WHERE (content REGEXP 'hoge') from /home/yuis/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `initialize'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。