Tagged Questions
1
vote
0answers
35 views
Rails: Update a column with the value of a column in another table
I have basically the following code:
ModelA.join(:modelB).update_all('modelA.column = modelB.column')
That fails with:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing ...
0
votes
1answer
17 views
Compare only the times of two timestamps in postgres
In PostgreSQL, I need a way to determine if the current time is within the hours of operation of a certain model with an opens_at and closes_at timestamp. What would be a valid Postgres way of doing ...
0
votes
3answers
148 views
how to set up postgres database for local rails project
I recently got a new machine and would now like to work on my projects from github. I'm curious as to how to properly set up the postgres database on my local machine. I have postgresql, pgadmin3 and ...
0
votes
1answer
62 views
Rails: rake db:create:all (could not connect to server) psql works fine
I've looked here and here but still can't solve my problem.
I have my setup working perfectly on my normal linux but when I tried to recreate it on my mac postgres won't work with rails. After ...
1
vote
1answer
47 views
PG:ConnectBad Rails 4 Postgresql
I know it seems like this question has been asked a hundred times but this time I think it is different.
When I restart my mac and run rails s, the site works fine.
➜ BankingApp git:(master) ✗ ...
1
vote
1answer
46 views
PostgreSQL: Need to perform Row operation
I'm new with PostgreSQL. I would like to perform a row operation on my table.
For example consider this table output :
Record | Accesories | Used
Joy | Laptop | 500
Joy | Android ...
0
votes
1answer
36 views
Grouping in Ruby on Rails using PostGres
I have the following line of code which works in sqlite, but in PostGres doesn't:
@income_by_category = SoldCategory.group(:category_name).having("branch_id=?", @branch_id).sum(:total).to_a
It's ...
2
votes
3answers
203 views
Using postgres arrays in Rails 4, how do I return an array of all the unique items in the array?
My migration looks like this:
create table :posts do |t|
t.string :tags, array: true, default: []
end
How can I get an array of all the unique tags stored under tags in all posts?
5
votes
2answers
518 views
Enabling Tiger Geocoder in postgis version 2.1
I have used homebrew to update to the most recent version of postgis. (2.1)
brew unlink postgis
brew install postgis
I then have created a migration to alter the postgis extension to 2.1
rails g ...
1
vote
1answer
62 views
Paginating joined results with calculated columns
We are calculating statistics for our client. Statistics are calculated for each SpecialtyLevel, and each statistic can have a number of error flags (not to be confused with validation errors). Here ...
0
votes
1answer
36 views
Postgre SQL incorrect syntaxt near If
I'm trying to create function but it's having error at If statement don't know what's the problem with it.
CREATE FUNCTION uspgetcountrylistwithpagenumber(IN "PageNumber" integer, IN "PageSize" ...
1
vote
1answer
62 views
Postgres: average user response time from interaction with a bot
I have a table that stores all messages between users and a bot (basically a state machine), and I'm trying to find all pairs of message/response from this table, in order to calculate each user's ...
2
votes
1answer
107 views
Rails - Generate email address when one doesn't exist with Omniauth integration
I am working with omniauth with Rails and trying to get twitter, facebook and google hooked up for authentication but keep running into this error:
PG::Error: ERROR: duplicate key value violates ...
0
votes
1answer
395 views
Querying a PostgreSQL multi-dimensional array data type in Rails 4
I am using a PostgreSQL multi-dimensional array to mimic an array of hashes, and I am looking for a way to locate a record by a key-value pair in that array like e.g ["key1","value1"]. An example ...
1
vote
4answers
308 views
Rails multitenant architecture, scoping access to multiple tenants
We have a single-tenant database architecture at the moment with MySQL running upward of 100 databases. We switch database connection on subdomain using the Apartment gem and all is dandy!
However, ...
1
vote
1answer
1k views
Connection refused (PGError) (postgresql and rails)
I keep getting this error when i try to run my localhost using "$rails s":
(Mac OSX 10.8.3)
(ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0])
(Rails 3.2.11)
(psql (PostgreSQL) ...
0
votes
1answer
125 views
How do I .group and .sum in a rails model using Postgres?
I have a functioning method in my development environment (SQLite) that looks this:
def self.ytd
Production.find(
:all,
conditions: ["year == ?", Time.now.year],
select: "carrier_id, ...
1
vote
1answer
137 views
What is a straightforward way to connect to Postgres.app with dbext (in Vim)?
When I try to connect to my Postgres.app db using dbext, I get the following error:
dbext:PostgreSQL requires a '$HOME/.pgpass' file in order to authenticate. This file is
missing. The binary ...
0
votes
1answer
318 views
Import data from text file into PostgreSQL. “Postgres_Copy” Gem
I am using PostgreSQL with ruby and rails app and have Postgres_copy gem installed
https://github.com/diogob/postgres-copy
I have hotels table and want to import text file using function pg_copy_from ...
2
votes
1answer
6k views
Resetting password of PostgreSQL on ubuntu [closed]
i am using Ubuntu.some days before i installed Postgresql database for ruby on rails.i created a superuser for database server and i forgot the password of postgresql superuser.can any one please help ...
0
votes
1answer
98 views
Selecting all rows where an array intersects in postgresql
Currently I'm trying, in a rails 3 application, to select all objects where two arrays have some overlap.
I've tried the following:
Contact.where("possible_unique_keys && ?" ...
0
votes
1answer
304 views
Heroku rake db:migrate aborted with 'PG::Error:'
I'm trying to run my app on Heroku, and I can't get past the 'rake db:migrate' command.
I keep getting this error:
rake aborted!
An error has occurred, this and all later migrations canceled:
...
0
votes
1answer
239 views
Get all data from all tables (Postgresql)
data = Program.joins(:program_schedules, :channel).
where(
"program_schedules.start" => options[:time_range],
"programs.ptype" => "movie",
...
6
votes
4answers
8k views
Postgresql adapter (pg): could not connect to server
I get this error every this I run my Rails app (It cannot connect to my local Postgresql)
/Users/leonardo/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.11/lib/
...
2
votes
2answers
192 views
How to manage the wals dir on a PostgreSQL replication server?
I have two PostgreSQL 9 servers running on Amazon EC2. One is the master, the other is a replication server in standby.
The replication server is continuing to fail as the hard drive fills up. It ...
5
votes
4answers
3k views
Millisecond resolution of DateTime in Ruby
I have a string like 2012-01-01T01:02:03.456 that I am storing in a Postgres database TIMESTAMP using ActiveRecord.
Unfortunately, Ruby seems to chop off the milliseconds:
ruby-1.9.3-rc1 :078 > ...
0
votes
2answers
210 views
PostgreSQL query returning multiple rows instead of one
I have two tables: user and projects, with a one-to-many relationship between two.
projects table has field status with project statuses of the user.
status can be one of:
launched, confirm, ...
1
vote
2answers
213 views
Get “latest” row after GROUP BY over multiple tables
I'd preferably like to first query listed below and just group by stories.id, but I get the following error:
ERROR: column "u.first_name" must appear in the GROUP BY clause or be used in an ...
0
votes
1answer
312 views
Trying to get postres and postgis running in rails app
I am completely new to Postgresql, Postgis, and SQL and have a little bit of rails knowledge. I am trying to get an existing app going on my local and am currently receiving the following messages ...
1
vote
1answer
137 views
Grouping a timestamp field by date in Ruby On Rails / PostgreSQL
I am trying to convert the following bit of code to work with PostgreSQL.
After doing some digging around I realized that PostgreSQL is much stricter (in a good way) with the GROUP BY than MySQL but ...
2
votes
2answers
2k views
How to solve privileges issues when restore PostgreSQL Database
I have dumped a clean, no owner backup for Postgres Database with the command
pg_dump sample_database -O -c -U
Later, when I restore the database with
psql -d sample_database -U app_name
However, ...
1
vote
1answer
225 views
PostgreSQL Error for Select Distinct in Rails
On Mysql it works correctly.
PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must
appear in select list LINE 1: ) ORDER BY
programs.rating DESC, program_sc... ^ :
Query:
...
8
votes
2answers
649 views
Can two “SELECT FOR UPDATE” statements on the same table cause a deadlock?
Suppose that two simultaneous transactions execute the following queries on a Postgresql DB:
Transaction A:
SELECT * FROM mytable WHERE id IN (1, 2, 3, 4) FOR UPDATE
Transaction B:
SELECT * FROM ...
4
votes
5answers
2k views
cannot install pg gem, checking for PQconnectdb() in -lpq… no
I'm trying to develop in Ruby on Rails using PostgreSQL locally, so I'm trying to install the pg gem. On Ubuntu 12.04. In terminal, I typed in:
gem install pg -v '0.12.2'
Which throws the ...
1
vote
1answer
363 views
Rails 0mPG::Error: ERROR: invalid byte sequence for encoding “UTF8”: 0xeda0bc
I'm running into an error while trying to write to tweets to my psql database.
I've searched the internet high and low (perhaps not well enough) for the answer, with no avail. I've looked at the ...
8
votes
1answer
2k views
Error when creating unaccent extension on PostgreSQL
I am trying to configure PostgreSQL to use fulltext search in my rails app as mentioned in this Railscast.
I am using a fresh Ubuntu 12.04 server running PostgreSQL 9.1.5 installed using apt-get with ...
5
votes
1answer
777 views
Way to use postgresql and avoid testunit by default in rails 3.2?
I'm tired of typing $ rails new [app name] -d postgresql --skip-test-unit every time I start a new rails app. I'm using rails 3.2.
Is there any way to make using postresql and skipping test unit ...
1
vote
2answers
512 views
TimeZone and DST in Rails and PostgreSQL
Background
Article model with default created_at column
Rails config.time_zone = 'Warsaw'
I've got an article with created_at = local time 2012-08-19 00:15 (2012-08-18 22:15 in UTC).
Goal
To ...
1
vote
1answer
414 views
I'm unable to save an activeRecord object in a legacy table using a view
I have a table in a legacy database that has a column named field.
It is impossible to link the table directly to an activeRecord model, since the latter will try to create the method field_changed? ...
0
votes
2answers
443 views
Why date time different 1 hour when retrieve timestamp data of postgresql from rails
I have a problem that is
I migrate database table from rails.
In the tables columns timestamps with timezone is also include.
When I insert data into database, timestamp columns save current time as ...
1
vote
2answers
4k views
How can I create a Postgres user and database whenever I create a new rails app?
I have followed this really helpful tutorial:
http://blog.willj.net/2011/05/31/setting-up-postgresql-for-ruby-on-rails-development-on-os-x/
I would really like to run rails new myapp and have the ...
0
votes
1answer
107 views
Postgres Join Query on Rails
I have researched a lot and I can't find the answer for my question. I have the following setup on my Rails app:
class Group < ActiveRecord::Base
has_many :people
# ...
end
class City < ...
0
votes
2answers
533 views
Strange PostgreSQL errors when trying to start a rails server on Mac OS X
I want to get a rails application working with PostgreSQL, but something strange is happening. My friends were able to install PostgreSQL and execute:
sudo su
su postgres
createdb development
...
1
vote
1answer
1k views
Invalid statement with Postgres hstore and rails
I am using the activerecord-postgres-hstore gem with rails 3.2. I have setup hstore and when I try and save any data I get the error:
ActiveRecord::StatementInvalid in ProductsController#create
...
4
votes
1answer
4k views
Postgresql date() with timezone
I'm having an issue selecting dates properly from Postgres - they are being stored in UTC, but
not converting with the Date() function properly.
Converting the timestamp to a date gives me the wrong ...
7
votes
3answers
2k views
Rspec: How to supress warnings and notices when running tests?
I was using Mysql database before and decided to switch to Postgresql and now, when I run my tests using rspec, I getting a lot of warnings and notices.
WARNING: there is already a transaction in ...
5
votes
1answer
2k views
Postgres sh: /usr/local/var/postgres/server.log: No such file or directory
I recently had to reinstall homebrew and postgres and now postgres isn't working with rails.
First when trying to run rails s, I get this:
...
0
votes
3answers
249 views
Why ActiveRecord caches find(:all) between requests?
I have this in my controller:
def frontpage
@sections = Section.all
end
In production environment, the query seems to be cached between requests. Until I restart an app, @sections is always the ...
0
votes
1answer
89 views
What's the smarter option: Ruby logic or SQL function?
I needed to write a method that always returns an integer value. If the record is non-existent, the method returns 0
I have a unique index on the columns being queried and came up with two solutions:
...
1
vote
1answer
293 views
Newly assigned Sequence is not working
In PostgreSQL, I created a new table and assigned a new sequence to the id column. If I insert a record from the PostgreSQL console it works but when I try to import a record from from Rails, it ...