postgresで、あるカラムのあるデータが存在するか確認したいです。
(データベースの名前はreal_dateで、テーブル名はdata。今回は、linkというカラムにhttps://hogehogeというカラムが「存在しない」ことを確認したい。言語はruby)
以下のようにやると期待通りの出力が出ましたが、
require 'pg' connection = PG::connect(:dbname => "real_date") data = connection.exec("select count(*) from data where link ='https://hogehoge';") data.each do |d| if d["count"] == "0" puts "data is not exist" else puts "data is exist" end end #=> data is not exist
以下のようにやるとdata is existになってしまいます。
require 'pg' connection = PG::connect(:dbname => "real_date") data = connection.exec("select * from data where link ='https://hogehoge';") if data puts "data is exist" else puts "data is not exist" end #=>data is exist
dataを出力したら以下のようになったのですが、この出力結果はなんですか?
puts data #=><PG::Result:0x00007fcd1b0e8860>
また、select * from data where link ='https://hogehoge';で存在確認する方法はありますか?