-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempting to execute a sql file with \set ...
raises errors
#550
Comments
The sequence Does the file |
I did elaborate this answer directly on Mastodon, sorry about the duplication:
In other words, sentences starting with Maybe the documentation should be more clear about it: The same would happen with other DB = PG.connect(dbname: "mydbname")
r = DB.exec('\dt')
Traceback (most recent call last):
2: from (irb):9
1: from (irb):9:in `exec'
PG::SyntaxError (ERROR: syntax error at or near "\") If you want to accomplish the same as DB = PG.connect(dbname: "mydbname")
r = DB.exec("SELECT tablename FROM pg_catalog.pg_tables where schemaname='public';")
r.to_a
# => => [{"tablename"=>"active_storage_blobs"}, {"tablename"=>"active_admin_comments"} .. ] Hope this helps. |
I was able to get it to work by removing the line and moving the error checking flag to the
Leaving this note to let others who might run into the same issue.
Yep, it works fine then. I guess it doesn't make sense for the Like: "Note: Not all syntax in However, I'm not sure how often people might run into something like this, maybe shelve the idea until/unless it comes up again? |
I am trying to execute a SQL file programmatically through the
pg
gem and I ran into this issue where I cannot give it a file with\set ON_ERROR_STOP true
.Expected
That I can execute a valid SQL file with
pg
gem somehowActual
This code:
Causes this error:
Maybe there's a better or different way to execute a SQL file with
pg
other than aConnection
object. If so, could you let me know?If there isn't a better way to do this I'm curious if this would be considered a bug?
Extra Context
I have a file that looks like this:
I've got a workflow where want to apply my schema and this seed file. I can do this on the command line:
However, I'm running into an issue where I'm trying to truncate the database between test runs and re-seed the data. I'm doing it like this in a
spec_helper.rb
https://gist.github.com/schneems/21132fb03291266ab28bbfe723f75a99This is the relevant code:
If I remove that gsub then I get an error from the pg gem:
I'm using the latest version of PG and I'm on Rails 3.1.4:
The text was updated successfully, but these errors were encountered: