Skip to main content
Filter by
Sorted by
Tagged with
4 votes
1 answer
810 views

How do I migrate an ActiveRecord model attribute from json to jsonb?

What should the migration look like? I would like to take advantage of the jsonb array querying technique.
Lee Dykes's user avatar
  • 1,077
0 votes
1 answer
2k views

LPAD & RPAD with parameter

I have a problem, I have a function in postgres, to generate headers that will be used to generate a more complex report. There all good. For the structure of the header, I leave spaces left or right ...
Darwin Delgado's user avatar
0 votes
0 answers
105 views

In postgresql , I am getting duplicates in a schema when I restore some tables in to a other schema in the same db .why?

In postgres 9.5 , I have a db called test. where I have 2 schemas 1.public 2. testcase when i try to restore tables from public to testcase shema. I creates duplicates in public schema and I couldn't ...
learner's user avatar
5 votes
3 answers
33k views

How to Connect to Docker Postgres Container from Host Machine

I put together a Rails dev environment by following instructions from https://docs.docker.com/compose/rails/ It works, but I am unable to connect to the Postgres server from the host machine. I am ...
Rayhan Muktader's user avatar
0 votes
1 answer
53 views

Issues with understanding multiple joins

I have the following tables: users ____________ | id | | first_name | |____________| pre_task_plans ____________ | id | | creator_id | (fk user_id) |____________| ...
hummmingbear's user avatar
  • 2,374
0 votes
1 answer
882 views

Backup taken from pgadmin is smaller than backup taken from pgdump

Hello experts I am using postgres 9.5 . When I take a backup from pgadmin it has 950 MB size but when i take the same db backup from pgdump.exe command the backup size is with 7.5 GB. I am confused ...
Stream's user avatar
  • 89
0 votes
1 answer
386 views

Rails Tenant schema switching with background jobs not working

Setting up a scheduled rake task using Whenever gem. Required to switch to a specific schema (Using Apartment gem in my project) Code in config/schedule.rb env :PATH, ENV['PATH'] env :GEM_PATH, ENV[...
user avatar
1 vote
1 answer
120 views

update query not working on Heroku using cloud 9 command line

I have the following tables: and the users table contains the following columns: I am trying to run the following statement: UPDATE users SET isTeacher = 'TRUE' WHERE id = '2'; but I am getting ...
justewe3's user avatar
0 votes
1 answer
92 views

Find conversations between users

I need an ActiveRecord query to find conversations for current_user and any another user Conversations can have many users. I need to set users ids in that query(it can be two or more users). class ...
pere slop's user avatar
0 votes
1 answer
61 views

How can I calculate locationGeo space in pgadmin 3 type with PostGIS functions?

My table name is map and I have latitude(double),longitude(double) and locationGeo(geometry) columns. I want to use a function to automatically compute the LocationGeo value using the given latitude ...
redPlanet's user avatar
1 vote
1 answer
967 views

Postgres Trigger in specified time

Hello expert I am working in banking software vendor company and we are working in PostgreSQL database due to load of work in office time(pick hour) I want to execute some function in specified time(...
Stream's user avatar
  • 89
1 vote
1 answer
602 views

How to send PG binary data from the Rails controller?

I have a Postgres database with PostGIS extension and some geo-data in it. I need to generate tiles with custom SQL queries (using ST_... functions), that returns binary data (bytea, like \...
Jack Owels's user avatar
1 vote
1 answer
335 views

Why is Postgres double-quoting the first function identifier when I set a default function for a column?

I have a legacy table with a default expression in a Rails project. This expression picks a random four-digit number and converts it to a string. During my tests I have been typing this exact ...
UrLicht's user avatar
  • 949
1 vote
2 answers
1k views

Why does this Postgres Select Query work in the local Docker Container but not on Amazon RDS Postgres?

My team has a local development environment that contains a Ruby on Rails app that connects to a Postgres database to retrieve some information about airports and use that to make further queries. ...
Necevil's user avatar
  • 2,892
0 votes
1 answer
56 views

Rails ActiveRecord Behaviour?

I wanted to understand how ActiveRecord works in the following scenario. @messages = Message.joins(:users).where("some condition").uniq now if i use @messages.sum(:url_view_count) I see the query is ...
Sachin srinivasan's user avatar
1 vote
3 answers
13k views

SQL Count digits in a string

I have a table of the following information. description: adjkfa34kj34kj33j4k3jk4 description: adfkjjkdf34_3434kjkjkj3 description: akjdfkjadfkjadkjfkjadfj description: 34394394093040930949039 How ...
user avatar
0 votes
1 answer
942 views

Save a list of objects in a transaction operation

I'm trying to save in my postgres database a list of objects from a excel file. It must be done inside a transaction. From the code below I can't rollback the transaction from invalid cases. The ...
Pedro Gabriel Lima's user avatar
1 vote
1 answer
2k views

Connecting to localhost PostgreSQL on Mac using PSequel GUI?

I have used Sequel Pro as a GUI to connect to databases with previous projects which were done using Laravel 5.4. It seemed simple enough to connect to the database using the Sequel Pro GUI. I have ...
AltBrian's user avatar
  • 2,512
1 vote
1 answer
217 views

Postgres- pgsql taking more time to retrieve data from table with more than 1.5 billion rows

How can I optimize the table or the query the following pgsql query(takes 34 min. to get 770 records)? Already indexes are added to the table for few columns. Not sure what else can make this query ...
Karthey Sundarem's user avatar
1 vote
1 answer
43 views

How to achieve concept of connection list with minimal cost using rails ActiveRecord?

Say User A is connected to B, then user B is automatically considered to be connected with user A. User has_many connection Connection Table: id, user_id, connected_user_id Say id || user_id|| ...
Manish's user avatar
  • 261
0 votes
1 answer
85 views

Rails dropping last value in array when saving to Postgres database as JSON array

I am building a web app using Rails and Postgres. I am trying to save an array into my database table and it is only deleting the last value in the array. For example if my array is: a= [10,12,14,16]...
aharonhillel's user avatar
0 votes
1 answer
563 views

Sort results in varchar column with Postgres [duplicate]

I have theses values in my table id | NAME 1 | 20 MEGA 2 | 30 MEGA 3 | 10 MEGA 4 | 300 MEGA 5 | 100 MEGA 6 | 25 MEGA What i want: id | NAME 3 | 10 MEGA 1 | 20 MEGA 6 | 25 MEGA 2 | 30 MEGA 5 | 100 ...
Eduardorph's user avatar
0 votes
2 answers
58 views

How do I match a database ID when pulling data from a database with an ID that needs to match a text string?

If the question isn't clear enough, I'm saving, for example, states in a database with an ID. I can return that ID but then I'm having difficulty turning it into the state name, for instance "...
code4fun's user avatar
  • 166
0 votes
1 answer
88 views

How do I automatically generate a new row in a table when the user signs up?

I'm trying to edit the devise sign up flow so that when a new user signs up I automatically add a row to a specific table with all default values. What is the best way to do this? Some thought ...
code4fun's user avatar
  • 166
0 votes
1 answer
519 views

How do I create a foreign key in rails 5 if I've already created the models for the tables I want to associate?

All of the references I've found either show me how to do it upon table creation, or are for a much earlier version of rails. Ideally, I'd like like the foreign_key to be named 'author_id' in the ...
Jeremy Flanagan's user avatar
0 votes
1 answer
318 views

how to efficently use group_by using rails

I have tables records like below: I am grouping them based on by am, pm and none. What I really need to break down the group_by for none to 7 7 columns as my total records of none are 14. Query I ...
user avatar
0 votes
1 answer
884 views

ActiveRecord error when running rails console

When I launch rails console and want to test a model template I just created, rails console failed to create my new model instance. yellow:maw thierry$ rails console Running via Spring preloader in ...
BeFree's user avatar
  • 11
0 votes
1 answer
46 views

How can I use value of the id column as default value of another non-nullable column when using postgresql-rails?

Here's one example where such a requirement comes up: Suppose we have a table 'sample' in our database which has a column 'col1' and an auto-incremental 'id' column. We want the default value of '...
Analytical Monk's user avatar
1 vote
0 answers
71 views

ActiveRecord::ConnectionAdapters::PostgreSQLColumn.range_to_string gone from Rails 4.1 -> 4.2

ActiveRecord::ConnectionAdapters::PostgreSQLColumn.range_to_string gone from Rails 4.1 -> 4.2 My searches on the web were so fruitfull that I finished hardcoding the 4.1 version into our code, and I ...
lab419's user avatar
  • 1,219
0 votes
2 answers
460 views

Push new table to heroku without having to reset existing database

I'm at the early stages of learning RoR and working with Heroku. So i have a fledging app with local and production databases. I've used pg:push to create the initial production database but I ...
Simon Cooper's user avatar
  • 1,594
8 votes
1 answer
2k views

Substring search with pg_search

I'm using pg_search to search for Products: class Product include PgSearch pg_search_scope( :search_for, against: %i(sku), associated_against: { translations: [:name, :description] },...
csch's user avatar
  • 4,756
0 votes
0 answers
62 views

Randomly degrading heroku DB performance?

So I am working on a pretty high traffic rails/heroku/postgres app, the backend only, and after running for hours, days, or weeks at times the database will randomly start taking 120 seconds to ...
TheGmann's user avatar
3 votes
2 answers
1k 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, with the ...
David V. Teixeira's user avatar
4 votes
2 answers
4k 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 ...
jack_was_taken's user avatar
2 votes
1 answer
388 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, ...
Kingsley Simon's user avatar
0 votes
2 answers
2k 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 ...
Simon's user avatar
  • 128
0 votes
1 answer
185 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 ...
Ville Lehtinen's user avatar
0 votes
1 answer
270 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....
user3676943's user avatar
4 votes
1 answer
5k 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.
Hardik Gondaliya's user avatar
2 votes
1 answer
38 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 ...
goterpsgo's user avatar
  • 307
1 vote
1 answer
27 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....
Simon's user avatar
  • 128
11 votes
1 answer
16k 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 ...
Barry Fruitman's user avatar
0 votes
0 answers
118 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 < ...
Terry Raimondo's user avatar
1 vote
1 answer
937 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 ...
Nikki Ganju's user avatar
30 votes
8 answers
30k 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 ...
Scott B's user avatar
  • 1,488
1 vote
1 answer
311 views

What validations 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 ...
Asarluhi's user avatar
  • 1,290
1 vote
1 answer
1k 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 ...
Aniket Rao's user avatar
1 vote
1 answer
758 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> ...
crievino's user avatar
0 votes
2 answers
3k 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 ...
Jack Rothrock's user avatar
5 votes
4 answers
349 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. ...
user1301037's user avatar

1
2 3 4 5
10