Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6569399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:37:19+00:00 2026-05-25T14:37:19+00:00

I have a migration which is using execute to send raw SQL to the

  • 0

I have a migration which is using execute to send raw SQL to the Postgres backend.

class TestExecuteMethod < ActiveRecord::Migration
  def self.up
    execute ('SELECT 1;')
  end

  def self.down
  end
end

Instead of going to my database, it seems execute is going to the shell:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  TestExecuteMethod: migrating ==============================================

++ executing: SELECT 1;
sh: SELECT: command not found
++   [FAIL]
==  TestExecuteMethod: migrated (0.0041s) =====================================

** Invoke db:schema:dump (first_time)
** Invoke environment 
** Execute db:schema:dump

But, when I instead do

ActiveRecord::Base.connection.execute(sql)

It works as expected.

Why is this?

I’m using Rails 3.0.9 and the pg gem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:37:19+00:00Added an answer on May 25, 2026 at 2:37 pm

    Add this to your migration:

    def self.trace_execute(io=$stderr, &block)
      set_trace_func proc {|event, file, line, id, binding, classname|
        io.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname if id.to_s == 'execute'
      }
      # trace the passed block
      yield
    
    ensure
      # disable (note: the disable call is the last thing traced)
      set_trace_func nil
    end
    

    Then wrap your execute call in a block like this:

    trace_execute { execute ('SELECT 1;') }
    

    and paste the first few lines of trace output. I suspect something is intercepting the execute call before the db adapter can receive it.

    Usually I’d recommend using something like

    puts method(:execute).inspect
    

    but that probably won’t work in this case because method_missing is involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple migration which was created using the generator class AddEmailToUsers
I have a migration that runs an SQL script to create a new Postgres
I am using Jruby and rails 2.2.2. My problem is I have a migration
I have an ExpenseType object that I have created with the following migration: class
I have a column with the type of Varchar in my Postgres database which
Background: Filemaker Pro 10+ have gained functionality to send emails using SendMail via SMTP.
I have a bdb database which I have been using on my XP box.
I have an open source Java database migration tool ( http://www.liquibase.org ) which I
I have the following Rails migration which works perfectly (irrelevant pieces removed): create_table :comments
I have been working with a project which is using grails / hibernate with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.