How do I stop these PG::ProtocolViolation errors?

bind message supplies 0 parameters
rails prepared_statements
exec_query
exec_query params rails
routine: 'exec_bind_message
twilio error codes

My method is:

class Survey < ActiveRecord::Base
  def create_matching_batteries
    unless inactive?
      update_column :battery_id, nil unless battery
      @battery = Battery.where(:review_id => review.id, :question_id => question.id).first_or_create
      @battery.surveys << self
    end
  end
end

When I run @survey.create_matching_batteries, I get this:

Survey Load (5.2ms)  SELECT "surveys".* FROM "surveys" WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1 ORDER BY "surveys"."id" ASC LIMIT 1  [["competitor_id", 248], ["id", 15183]]
D, [2014-01-21T22:28:08.830446 #3392] DEBUG -- :   Survey Load (5.2ms)  SELECT "surveys".* FROM "surveys" WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1 ORDER BY "surveys"."id" ASC LIMIT 1  [["competitor_id", 248], ["id", 15183]]
PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1
: SELECT  "surveys".* FROM "surveys"  WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1  ORDER BY "surveys"."id" ASC LIMIT 1
E, [2014-01-21T22:28:08.830528 #3392] ERROR -- : PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1
: SELECT  "surveys".* FROM "surveys"  WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1  ORDER BY "surveys"."id" ASC LIMIT 1
   (0.3ms)  ROLLBACK
D, [2014-01-21T22:28:08.833655 #3392] DEBUG -- :    (0.3ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 2 parameters, but prepared statement "a15" requires 1
: SELECT  "surveys".* FROM "surveys"  WHERE "surveys"."competitor_id" = $1 AND "surveys"."id" = $1  ORDER BY "surveys"."id" ASC LIMIT 1
from /Users/steven/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:786:in `get_last_result'

In "Railspeak" not "Postgrespeak", what does ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: bind message supplies 2 parameters, but prepared statement "a15" requires 1 mean? And how can it help me to debug my method?

My environment:

$ rails -v
Rails 4.0.2
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
$ psql --version
psql (PostgreSQL) 9.3.1

Disable Prepared Statements

production:
  adapter: postgresql
  prepared_statements: false

checkout http://edgeguides.rubyonrails.org/configuring.html

PG::ProtocolViolation: ERROR: bind message supplies 0 , This issue is related to: #12753 #18469 #17983 #17770 Test case: PG:: ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared So to avoid that we should just avoid using Arel whenever possible? The BindParam needs to know about neither of these things, so it's been changed to stop being a subclass of SqlLiteral I could also see an alternative implementation using format strings if for some reason blocks cause a problem.

I experienced the same problem, but after counter checking my code, I found out that I had used the same variables in two different fields that is, I had written fieldA=$2 and also fieldB=$2. After correction everything worked fine.

ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR , ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: bind I'm going to close as a duplicate of #24893, so we can keep all of this� Choose the command Internet Options from the bottom of the Tools button menu. Click the Advanced tab in the Internet Options dialog box. You see three items to check in the list, all found beneath the Browsing heading. Place a check mark by the item Disable Script Debugging (Internet Explorer).

My problem was I used quotes around variable

quiz_subject = subject_id WHERE subject_name = '$1';

I removed those quotes

quiz_subject = subject_id WHERE subject_name = $1;

1773133 – Foreman-rake facts:cleanup batch/rolling support, ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: invalid message format /usr/share/foreman/lib/tasks/facts.rake:14:in `block (2 levels) in <top Moving this bug to POST for triage into Satellite 6 since the upstream issue� How can I fix exception_access_violation error? Usually, it shows up when I play a game, but yesterday I received the same message on Facebook. I’m using Windows 10. Please help! EXCEPTION_ACCESS_VIOLATION is a Windows-specific error[ref en-1] message, which may strike

1758250 – Unable to sync the contents due to an error, Bug 1758250 - Unable to sync the contents due to an error - PG:: ProtocolViolation: ERROR: invalid message format. Summary: Unable to sync the contents due� So, if you want to get rid of the DPC Watchdog Violation error, you have to do it in Windows Safe Mode. How To Access Safe Mode In Windows 7 To access Safe Mode in Windows 7, press F8 immediately after your PC is restarted or powered on.

Error and Warning Dictionary, Explore the full list of all possible Twilio REST API error codes. HTTP protocol violation. 11210 Invalid page size, it must be between 1 and 25 if specified. 19036 Message Redaction Incompatible Configuration: Long code STOP filtering. Tech support scams are an industry-wide issue where scammers trick you into paying for unnecessary technical support services. You can help protect yourself from scammers by verifying that the contact is a Microsoft Agent or Microsoft Employee and that the phone number is an official Microsoft global customer service number.

Firefox has experienced a network protocol violation that cannot be , Firefox has experienced a network protocol violation that cannot be repaired. The page you are trying to view cannot be shown because an error in the network protocol was As a test, disable the Norton main program(right-click its icon). To stop pop-ups on a Windows 10 computer, you can edit Windows' notification settings. Every major internet browser allows you to stop pop-ups with a browser extension, but Microsoft's Edge browser

Comments
  • In "postgresspeak" (this is tagged postgresql, so you should really expect that): You repeat the same bind parameter placeholder $1 twice, instead of using separate placeholders $1 and $2. Look at the generated query text. As for why that happens, I'm blissfully unaware of the guts of how Rails works, and will let someone else deal with that.
  • In my case, the problem was using the activerecord_any_of gem after upgrading to Rails 4.2. It was now generating invalid PG SQL (making queries with $1, $2 etc. but was not specifying their values at the end of the query). I simply removed that Ruby gem and used Arel table queries, and all is fine. Bottom-line: I don't think your answer is a good way of going about the problem.