Tag: postgresql

how to parse and display hstore key/value in rails

I’ved got a data type that is postgres hstore that stores a json string. I want to be able to parse and display the key/values on rails html page. Somehow, I just do not know how to run a parse on the data field and display each one of key/value listed in the string. <% […]

Postgres: Error using GROUP BY and ORDER (on heroku)

I am trying to solve my heroku problem which it seems to have problem of We’re sorry, but something went wrong. We’ve been notified about this issue and we’ll take a look at it shortly. Is there any mistake I have and how to overcome it? How can I interpret these Heroku logs? ActionView::Template::Error (PGError: […]

Rails 4 / postgresql 9.4 – Query and update a ruby object inside an array

I have a method (find_by_sql) that outputs a ruby object inside an array like this: [#<deal id: 66480, opportunity_id: 4, admin_user_id: 1, created_at: “2015-09-20 18:37:29”, updated_at: “2015-09-20 18:37:29”, deal_available: true>] How can I update the object’s ‘deal_available’ attribute inside my database in raw postgresql ? I tried different ways to write it but I stumble […]

dyld: lazy symbol binding failed: Symbol not found: _ruby_run when using heroku

I’ve run into this problem after I installed the newest version of the heroku toolbelt. If I use the heroku command, I get this error: $ heroku -v dyld: lazy symbol binding failed: Symbol not found: _ruby_run Referenced from: /usr/local/bin/ruby Expected in: /usr/lib/libruby.dylib dyld: Symbol not found: _ruby_run Referenced from: /usr/local/bin/ruby Expected in: /usr/lib/libruby.dylib Trace/BPT […]

create unique constraints per user

I am building a small app and at this point I am creating the database schema. I use PostgreSQL with Sequel and I have the two migrations: Sequel.migration do change do Sequel::Model.db.run ‘CREATE EXTENSION IF NOT EXISTS “uuid-ossp”‘ create_table :user do String :id, :type => :uuid, :primary_key => true, :default => Sequel.function(:uuid_generate_v4) DateTime :created_at DateTime […]

Get max id of all sequences in PostgreSQL

We have a monitor on our databases to check for ids approaching max-int or max-bigint. We just moved from MySQL, and I’m struggling to get a similar check working on PostgreSQL. I’m hoping someone can help. Here’s the query in MySQL SELECT table_name, auto_increment FROM information_schema.tables WHERE table_schema = DATABASE(); I’m trying to get the […]

Group by specified column in PostgreSQL

Maybe, this question is a little stupid, but I’m confused. How to group records by specified column ? 🙂 Item.group(:category_id) does’t works… It says: ActiveRecord::StatementInvalid: PGError: ERROR: column “items.id” must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT “items”.* FROM “items” GROUP BY category_id What kind of […]

ROR + Ruby Date in Different Format

If I have @today = Thu Apr 21 2011 00:00:00 GMT 0530 (IST), How do I convert @today into “Thur April 21, 2011” ?

createdb not recognized as a command when using ActiveRecord

I’m a newbie to Ruby and web development. I’m using Windows 7 64-bit with Ruby 2.0 and I have PostgreSQL 9.4 installed. I’m trying to use ActiveRecord to create a database. I checked that my postgresql server is running and I did bundle install to make sure I had all the required gems. However, when […]

Scope: Sort by difference between two dates

I would like to create a scope which sort data from the closest date to the farthest. For example I have 3 values: <Value id: 1, date: ‘2012-12-20’> <Value id: 2, date: ‘2012-12-28’> <Value id: 3, date: ‘2012-12-31’> Then I would like to sort the date closest to a given date: 2012-12-29. I should have […]

Ruby is the best programming language in the world - Ruby on Rails.