baronyan's blog

linux,macでruby、railsでの開発をしていく中で知ったこと、備忘的なことなどを書いていきます。

postgres

postgresqlでnbspを含む行を検出

where hoge like '%\xc2\xa0%' ついでにrubyでnbsp削除は .gsub(/[\u00A0]/, ' ')

ubuntu12.04(64bit)でpoltergeistを使う方法

前提条件:capybaraが使える状態(参考) まずphantomjsをインストールします。(参考ページ) cd /usr/local/share sudo wget https://phantomjs.googlecode.com/files/phantomjs-1.9.0-linux-x86_64.tar.bz2 sudo tar xjf phantomjs-1.9.0-linux-x86_64.ta…

postgresqlで文字列を置換してupdateする方法

update machines set ip = replace(ip, '192.168.0', '192.168.3') これでmachinesテーブルのipカラムの「192.168.0」が「192.168.3」に置き換わります。

postgresqlの検索条件に正規表現を使う方法

= の代わりに ~ を使います。 例 where tel ~ '^\d+-\d+-\d+$' これで電話番号の後ろにキャプション等が付いていないレコードのみ抽出できます。