rails-postgresql

Batch insertion in rails 3

若如初见. 提交于 2019-11-27 18:08:14
I want to do a batch insert of few thousand records into the database (POSTGRES in my case) from within my Rails App. What would be the "Rails way" of doing it? Something which is fast and also correct way of doing it. I know I can create the SQL query by string concatenation of the attributes but I want a better approach. ActiveRecord .create method supports bulk creation. The method emulates the feature if the DB doesn't support it and uses the underlying DB engine if the feature is supported. Just pass an array of options. # Create an Array of new objects User.create([{ :first_name =>

Rails: rake db:create:all fails to connect to PostgreSQL database

牧云@^-^@ 提交于 2019-11-27 16:47:38
问题 I am trying to create a Rails app that uses PostgreSQL. Here is a description of what I did. PostgreSQL setup: I installed PostgreSQL 9.1.3 via the ppa:pitti/postgresql maintained by Martin Pitt. There was PostgreSQL 8.4 installed before; I am not sure if it is still installed or gone. I added a database user with superuser rights to the database that has the same name as my Ubuntu account. I start the database daemon with sudo service postgresql start . I installed pgadmin3, Version 1.14.0

Error when creating unaccent extension on PostgreSQL

那年仲夏 提交于 2019-11-27 13:27:06
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 the ppa:pitti/postgresql with precise . I get the following error when trying to run the migration and when I try the same command in the psql console with the peer postgres user: postgres=# CREATE EXTENSION unaccent; ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/unaccent.control": No such file or directory In my local box running Ubuntu 10.04 desktop I use the

Postgresql adapter (pg): could not connect to server

六月ゝ 毕业季﹏ 提交于 2019-11-27 11:11:11
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/postgresql_adapter.rb:1208:in `initialize': could not connect to server: No such file or directory (PG::Error) Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? I'm using Postgres.app that it's correctly running. If I run $ psql I can login properly to Postgresql console. $ which psql /Applications/Postgres.app/Contents/MacOS/bin/psql

How to solve privileges issues when restore PostgreSQL Database

时光总嘲笑我的痴心妄想 提交于 2019-11-27 09:43:26
问题 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, I encountered several errors which prevents me from restoring the data: ERROR: must be owner of extension plpgsql ERROR: must be owner of schema public ERROR: schema "public" already exists ERROR: must be owner of schema public CREATE EXTENSION ERROR: must be owner of extension plpgsql I digged into

Creating a PostgreSQL sequence to a field (which is not the ID of the record)

瘦欲@ 提交于 2019-11-27 08:46:26
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 | integer value | double precision ran_at | timestamp active | boolean build_id | bigint metric_id | integer platform_id | integer mode_id | integer machine_id | integer higher_better | boolean job_id | integer variation_id | integer step | character varying(255) I need to add a sequence to job_id (note: there is no model for job ). How do I create this sequence? Use CREATE SEQUENCE : CREATE SEQUENCE scores

Postgres JSON data type Rails query

萝らか妹 提交于 2019-11-26 23:47:32
I am using Postgres' json data type but want to do a query/ordering with data that is nested within the json. I want to order or query with .where on the json data type. For example, I want to query for users that have a follower count > 500 or I want to order by follower or following count. Thanks! Example: model User data: { "photos"=>[ {"type"=>"facebook", "type_id"=>"facebook", "type_name"=>"Facebook", "url"=>"facebook.com"} ], "social_profiles"=>[ {"type"=>"vimeo", "type_id"=>"vimeo", "type_name"=>"Vimeo", "url"=>"http://vimeo.com/", "username"=>"v", "id"=>"1"}, {"bio"=>"I am not a person

Creating a PostgreSQL sequence to a field (which is not the ID of the record)

我的梦境 提交于 2019-11-26 14:17:28
问题 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 | integer value | double precision ran_at | timestamp active | boolean build_id | bigint metric_id | integer platform_id | integer mode_id | integer machine_id | integer higher_better | boolean job_id | integer variation_id | integer step | character varying(255) I need to add a sequence to job_id (note:

Postgres JSON data type Rails query

…衆ロ難τιáo~ 提交于 2019-11-26 08:46:56
问题 I am using Postgres\' json data type but want to do a query/ordering with data that is nested within the json. I want to order or query with .where on the json data type. For example, I want to query for users that have a follower count > 500 or I want to order by follower or following count. Thanks! Example: model User data: { \"photos\"=>[ {\"type\"=>\"facebook\", \"type_id\"=>\"facebook\", \"type_name\"=>\"Facebook\", \"url\"=>\"facebook.com\"} ], \"social_profiles\"=>[ {\"type\"=>\"vimeo\

PG::ConnectionBad - could not connect to server: Connection refused

橙三吉。 提交于 2019-11-26 05:33:14
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 running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432? : activerecord (4.0.0) lib