rails-postgresql

Replace NULL values in an array in PostgreSQL

耗尽温柔 提交于 2019-12-05 11:33:12
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 value, it throws an error: "ERROR: array must not contain nulls" Can anyone help me to remove the null values from the array? Erwin Brandstetter 1) Arrays can contain NULL values in PostgreSQL 8.4+ db=# SELECT ARRAY[5,NULL,6]; array ------------ {5,NULL,6} 2) But you cannot subtract one ARRAY from another in standard PostgreSQL 8.4. db=# SELECT ARRAY[1,2,3] - ARRAY[5,NULL,6]; ERROR: operator does not

Rspec: How to suppress warnings and notices when running tests?

陌路散爱 提交于 2019-12-05 01:30:19
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 progress NOTICE: there is no transaction in progress should has link "Suspender" WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has css "title" with text "Suspensão de anúncio" WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has css "h1" with text "Awesome job!" How can I suppress that? Is

Can two “SELECT FOR UPDATE” statements on the same table cause a deadlock?

自作多情 提交于 2019-12-04 17:26:08
问题 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 mytable WHERE id IN (6, 3, 2, 1) FOR UPDATE Is it possible for a deadlock to occur due to Postgresql acquiring row locks in an inconsistent order? E.g. if Postgresql were to acquire row locks in the order the ids are given in this example, then there is a potential for deadlock. Or is Postgresql

gem install dm-postgres-adapter build error

笑着哭i 提交于 2019-12-04 11:27:24
问题 i'm trying to build dm-postgres-adapter but get this error. sudo gem install dm-postgres-adapter Building native extensions. This could take a while... ERROR: Error installing dm-postgres-adapter: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb checking for main() in -lpq... yes checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for postgres.h... yes checking for mb/pg_wchar.h... no ***

Rails doesn't convert timezone (PostgreSQL)

隐身守侯 提交于 2019-12-04 06:24:58
I have a problem with timezones and a postgresql db (Rails 3.0.4, PostgreSQL 9.0). I'm using a custom scope, in which I append some conditions, do joins etc.pp. The problem is, that Rails don't convert the times to my local timezone. Here is the code of the scope: scope :with_activities_within_range_in_week, lambda{ |latMin, lngMin, latMax, lngMax, date| select("date_trunc('day', activities.starting_at) as date, count(activities.id) as value ") \ .within(latMin, lngMin, latMax, lngMax) \ .joins(:activities) \ .merge(Activity.in_week(date)) \ .group("date") \ .order("date") } The within method

Error Installing PG Gem on Windows

笑着哭i 提交于 2019-12-04 06:01:02
问题 I'm using XAMPP as my installation folder for PostgreSQL 9.3. C:\xampp\pgsql\9.3 And now I'm trying to install PostgreSQL gem using that directory as a reference: gem install pg -- --with-pg-include="C:\xampp\pgsql\9.3\include" --with-pg-lib="C:\xampp\pgsql\9.3\lib" --with-pg-config="C:\xampp\pgsql\9.3\bin\pg_config" But this command failed with errors listed below: ERROR: Error installing pg: ERROR: Failed to build gem native extension. C:/Ruby/Ruby200/bin/ruby.exe extconf.rb --with-pg

Ransack, Postgres - sort on column from associated table with distinct: true

你。 提交于 2019-12-04 05:07:40
I have an app that uses the Ransack gem and I'm converting it from Mysql to Postgres. In an instance where the sort column is from an associated table and the distinct option is set to true, Postgres throws this error: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list The Ransack github page says that, in a case like this, "you're on your own." What's the best - any! - strategy for handling this scenario? q = Contact.includes(:contact_type).search q.sorts = ['contact_type_name asc'] q.result(distinct: true) PG::InvalidColumnReference: ERROR

How to add sequences to a migration and use them in a model?

你离开我真会死。 提交于 2019-12-03 19:47:26
问题 I want to have a " Customer " Model with a normal primary key and another column to store a custom "Customer Number". In addition, I want the db to handle default Customer Numbers. I think, defining a sequence is the best way to do that. I use PostgreSQL. Have a look at my migration: class CreateAccountsCustomers < ActiveRecord::Migration def up say "Creating sequenze for customer number starting at 1002" execute 'CREATE SEQUENCE customer_no_seq START 1002;' create_table :accounts_customers

Calendar tables in PostgreSQL 9

北慕城南 提交于 2019-12-03 18:01:51
问题 I am building an analytics database (I have a firm understanding of the data and the business objectives and only basic-to-moderate database skills). I have come across some references to building similar warehouses which implement the concept of 'calendar tables'. This makes sense and is easily enough done. Most examples I see, however, are calendar tables that limit scope to 'day'. My data will need to be analyzed down to hour-level. Possibly minutes. My question: would an implementation of

Heroku Rails could not fork new process for connection: Cannot allocate memory

偶尔善良 提交于 2019-12-03 18:01:28
问题 I have 3 Rails applications that all use the same code base. 2/3 of the applications are running fine, but one of them gives me this error: could not fork new process for connection: Cannot allocate memory Upon trying to look at the Postgres logs, it is a little more specific: psql: bin//psql-9.2.1-64bit pv: bin//pv-1.1.4-64bit psql-9.2.1-64bit: could not fork new process for connection: Cannot allocate memory could not fork new process for connection: Cannot allocate memory could not fork