Open source RDBMS (relational database management system) when used in conjunction with the Ruby on Rails framework.
1
vote
1answer
20 views
How to group and count the last N results?
In Rails, you can use:
Model.group(:field).count
to yield something like:
{"a"=>7, "b"=>5, "c"=>3 "d"=>3, "e"=>4}
But how can I count ONLY in the last N lines, not the entire table?
Do not ...
3
votes
2answers
23 views
Postgres conditional unique constraint
Pretend I have a users table where users are members of a specific tenant, and their e-mails are uniquely indexed to their tenant, like this:
User
id | tenant_id | email
1 1 ...
1
vote
1answer
29 views
Add Current User id to trigger sql query hair_trigger gem rails
I am using hair_trigger gem and in my model, i want to keep changes to some columns.
trigger.after(:insert).declare("#{current_user.id} as current_user_id") do
"insert into histories (item_type, ...
0
votes
2answers
28 views
How to order records by created_at last 3 days first, then by another column, using rails [Postgresql]
Using Active Record, How to order by 2 columns (created_at, views):
1st: the records created within the last 3 days
2nd: everything after that should be ordered only by views
In order to get a ...
5
votes
3answers
222 views
Rails 5 how to clear or delete production postgres database
I am trying to delete a production database so I can start fresh. When I upgraded to rails 5 from rails 4, it is now protecting the production database from accidental deletion. It shows the following ...
6
votes
6answers
14k views
rake db:create fails, authentication problem with postgresql 8.4
first things first, please excuse my utter noobness. I really tried to find a solution out there, but now i'm stuck and completely clueless.
i'm trying to deploy a rails 3 app on a distant server ; ...
141
votes
20answers
120k views
PG::ConnectionBad - could not connect to server: Connection refused
Everytime I run my rails 4.0 server, I get this output.
Started GET "/" for 127.0.0.1 at 2013-11-06 23:56:36 -0500
PG::ConnectionBad - could not connect to server: Connection refused
Is the server ...
0
votes
1answer
15 views
Correct associations and database design without (single table) inheritance for Rails-Ember
I'm struggling to figure out how to design my PostgreSQL database tables and Rails API models such that their associations can be implemented 1:1 in my Ember front-end, whereby Ember and Rails can ...
0
votes
2answers
228 views
Postgresql, Rails - could not fork autovacuum worker process: Resource temporarily unavailable
This is happening to me while in my local environment, Mac OSX, every time I start my server - puma - and workers - resque.
The logs don't say anything helpful, just a repeated, "could not fork ...
0
votes
1answer
32 views
In Rails 5, How to create a controller action which serves some binary data?
Today I am working with Keras.js which has a repo here:
https://github.com/transcranial/keras-js
To operate this I need to serve some JS which looks something like this:
const model = new KerasJS....
0
votes
1answer
26 views
postgresql 9.3 log slow queries
I am using Rails application with Postgres 9.3 database and doing some performance fixes. I would like to know how to find out slowest queries in log files. let say queries taking more then 30ms.
2
votes
1answer
25 views
DB migrate scripts break on references
I've been following online examples of how to create tables the Rails way and I noticed the migration scripts I created containing references don't work out of the box. I thought maybe I did something ...
1
vote
1answer
15 views
How to list records of a Table with a counter of how many are used through a relationship
I have these 2 tables:
create_table "instruments", force: :cascade do |t|
t.string "name"
...
create_table "user_instruments", force: :cascade do |t|
t.integer "user_id"
t....
0
votes
1answer
31 views
Can Postgres silently ignore column constraint conflicts?
I have a Postgres 9.6 table with certain columns that must be unique. If I try to insert a duplicate row, I want Postgres to simply ignore the insert and continue, instead of failing or aborting. If ...
27
votes
2answers
13k 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 ...
0
votes
0answers
35 views
ActiveRecord Complex Query
I need some advice on how I should be going about some business logic in our app. Currently I have a loop for returning all of a user’s sales opportunities.. It involves going through current_user‘s ...
1
vote
1answer
312 views
Unable to retrieve excerpt from Postgres using pg_search gem
Update
First of all, there is no method "context". That was a word my brain made up at some point and stuck with. Obviously I should've been running .excerpt(). Second, I was running the command ...
0
votes
0answers
29 views
Why HABTM relation entries are not cleared after a destroy in Rails?
I was wondering why I have to write this (following) code to clear the relation table after destroying one of the two elements joined in a HABTM relation in Rails (using 5 here).
class Model < ...
3
votes
1answer
6k views
Bulk create records in rails?
Ok so I have a rails application called HashtagMapper.com which finds tweets by the thousands and maps them. The problem I am having is that between geocoding 1000+ queries can take up to 10 seconds, ...
1
vote
1answer
31 views
PostgreSQL-Data File
Which process writes the data file in PostgreSQL?
And what are the data files in postgreSQL?
Note: Performing Insert/Update/Delete operation on postgreSQL-9.5. I want to verify which Process is ...
1
vote
1answer
2k views
Postgres operators for JSON data type using Rails 4
Got a record:
2.1.1 :202 > r.column_data
=> {"data1"=>[1, 2, 3], "data2"=>"data2-3", "array"=>[{"hello"=>1}, {"hi"=>2}], "nest"=>{"nest1"=>"yes"}}
Trying to query inside ...
12
votes
4answers
12k views
Rails 4.0.1 on Heroku, can't create database
I can't get rake db:migrate to run on my rails 4.0.1 app on Heroku.
I'm guessing that I don't have postgres configured properly... but reading the docs on heroku hasn't really helped and I'm not sure ...
4
votes
1answer
5k views
Replace NULL values in an array in PostgreSQL
SELECT ARRAY[1,2,3] - ARRAY[5,NULL,6]
I am using contrib _int.sql package for array operations in postgresql 8.4
In the above query there is a NULL in right hand side array. Because of this NULL ...
1
vote
1answer
20 views
What vaildations to use for an array data type
PostgreSQL adds other data types to the Active Record default.
See PostgreSQL documentation, List of available datatypes at Stackoverflow and Active Record and PostgreSQL at RailsGuides.
For the ...
36
votes
7answers
40k 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/
active_record/connection_adapters/...
1
vote
1answer
87 views
PG::UndefinedTable: ERROR: relation does not exist for Multitenant Rails App
I am working on a Multi-tenant Ruby on Rails App along with another developer. I pulled his branch and received new migration files. I ran rake db:migrate. I visit the index of that controller and I ...
503
votes
30answers
175k views
Can't find the 'libpq-fe.h header when trying to install pg gem
I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error:
demonchand@system-001:~/exercise/personal/pro$ gem ...
1
vote
1answer
38 views
geocode 2 addresses with geocoder gem
I'm trying to geocode 2 addresses which are asked in 1 form.
<%= f.input :kotadres %>
<%= f.input :location %>
Both of them work with Google Autocomplete like this:
<script>
...
0
votes
0answers
29 views
Save a Time object in JSONB
I have a JSONB field in my database defined like this:
t.jsonb :some_data, null: false, default: []
I've tried to save time objects to this field by any of the below methods
my_instance.some_data =...
5
votes
4answers
157 views
Group_by - Ruby/Rails + Postgres
I am pretty new to ROR and Postgre and i'm in trouble to achieve this.
I have a Working_hour Model and a Merchant Model, where merchant has_many working_hours and working_hour belongs to Merchant. ...
4
votes
2answers
9k views
Rails pg gem Incompatible library version
I'm getting the following 'incompatible library version' error when I try and access my Ruby on Rails website in development mode.
incompatible library version - /var/www/vhosts/launch.site.com/...
0
votes
1answer
43 views
GROUP BY PostgreSQL query where I need a column that is not in the GROUP BY clause [duplicate]
I have a database that parallels the 'widget' database below.
widget_id | vendor_id | price
------------------------------
1 | 101 | 10.00
2 | 101 | 9.00
3 | ...
1
vote
1answer
21 views
How should I define a constraint for unique array values within a column in Rails?
I am trying to store some leads in my Rails CRM Application. Here's the sample Lead model.
class Lead < ActiveRecord::Base
belongs_to :campaign
validates_presence_of :name
end
Here's a sample ...
43
votes
4answers
35k 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, ...
5
votes
1answer
1k views
JSON data type in Rails4 form_for
how to achieve filling values from JSON PostgreSQL type into nested form in rails?
I have a model like
title :text
description :text
grid :json
Inside properties I want to store a dimension and ...
1
vote
1answer
14 views
Getting an sqlite error when migrating after heroku deployment
So I deployed my app to Heroku and installed gem 'pg' and removed sqlite.
Now getting this error when I migrate locally or on Heroku
Gem::LoadError: Specified 'sqlite3' for database adapter, but the ...
0
votes
1answer
49 views
How to create extension in PostgreSQL db
I want to create an extension, called UNACCENT, when I create my database.
I know this can be achieved with the database command:
CREATE EXTENSION UNACCENT
However, I don't know where to put this. ...
1
vote
1answer
494 views
PG::ConnectionBad: could not translate host name error after running export DATABASE_URL=postgres://$(whoami)
I received this error after running
export DATABASE_URL=postgres://$(whoami)
on the command line. Now when I run the command
$$ rake db:migrate
This is the full error
rake aborted!
PG::...
1
vote
1answer
617 views
Alternative for Serial type in RedShift / PostgreSQL
I am actually trying to make Rails working with RedShift, and facing some issue with Rails default indexes. My work is based on the repo activerecord-redshift-adapter.
By default, Rails use the ...
0
votes
2answers
45 views
Search results ordering based on rating and other values
I am struggling to build a complex ordering algorithm for the search results page.
I would like to order my items by rating (rating count, average rating), but I only want the rating take between 60-...
7
votes
3answers
9k 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) 9.2....
5
votes
2answers
5k views
Creating a PostgreSQL sequence to a field (which is not the ID of the record)
I am working on a Ruby on Rails app. We are using a PostgreSQL database.
There is a table named scores with the following columns:
Column | Type
--------------+-----------------------
id ...
0
votes
3answers
29 views
Why does Rails .select alias change attributes to lowercase?
In our controller, we are trying to show a video series, which should return JSON similar to this:
{
id: 1,
name: "Series Name",
videos: [
id: 2,
name: "Video Name",
...
-2
votes
1answer
131 views
Ruby on Rails - how can I open project with postgres?
last day I have get a ruby on rails project. Know my question: How can I open this project (with postgres).
More information:
My contribution is Windows. Ruby and Rails are both installed.
First I ...
0
votes
1answer
60 views
ruby on rails query on jsonb field does not work
I have a table in the PostgreSQL 9.5 with jsonb column called segmented_data and I have a record with some data in this field
ProjectKeyword.first
=> #<ProjectKeyword:0x007fa83a17e7f8 id: 2201, ...
1
vote
1answer
182 views
Rails postgres hstore: query for a specific key with any of the given values
My question is specific to rails+postgres hstore datatype.
The WHERE IN [1,2, 3] or the rails equivalent Model.where(data: [1,2,3]) works fine for regular columns, but not for hstore.
I have a ...
0
votes
1answer
48 views
`initialize': fe_sendauth: no password supplied (PG::ConnectionBad)
I am new to postgresql. I am trying to use postgresql with ruby on rails. I have just installed postgresql and I have just created my database. But when I try to run postgresql on localhost on port ...
0
votes
1answer
79 views
Sorting issues for Pagination sorting in Postgresql
For pagination sorting am geting duplicated data once load the next page.
For Eg: if a we have full name: Ahern in 1st page and after moving next page also sometimes we can able to see the same record....
4
votes
2answers
1k views
pghero on PostgresApp pg_stat_statements must be loaded via shared_preload_libraries
I have this error
PG::ObjectNotInPrerequisiteState: ERROR: pg_stat_statements must be loaded via shared_preload_libraries
on localhost. Using osx (10.9.5), PostgresApp 9.3.1.0 and pghero gem
...
1
vote
2answers
667 views
How to set default 'uuid-ossp' extension to all migration files using rails?
How to set default 'uuid-ossp' extension to all migration files?
enable_extension 'uuid-ossp'
I'm using ruby 2.1 and rails 4
PostgreSQL
Thanks,