Tag: rails postgresql

为字段创建PostgreSQL序列(不是记录的ID)

我正在开发Ruby on Rails应用程序。 我们正在使用PostgreSQL数据库。 有一个名为scores的表,其中包含以下列: 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) 我需要在job_id添加一个序列 (注意:没有job模型)。 如何创建此序列?

Postgres rails无法识别用户

所以我的rails应用程序给了我“我们很抱歉,但出了点问题。” 当我查看日志时,我明白了 PG::Error (FATAL: role “ubuntu” does not exist ): 但是,当我这样做时(注意我相信我从来没有为角色ubuntu添加密码): sudo -u postgres createuser ubuntu Shall the new role be a superuser? (y/n) y createuser: creation of new role failed: ERROR: role “ubuntu” already exists 我在使用nginx服务器的ubuntu ec2实例上运行它。 编辑:我只是尝试卸载并重新安装postgres,并完全打破它,所以我将无法接受任何答案。

使用rvm在Mac OS Lion上安装pg gem

212-178-13-214:~ igorfedoronchuk$ gem install pg Building native extensions. This could take a while… /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777 ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb checking for pg_config… yes Using config values from /usr/bin/pg_config checking for libpq-fe.h… *** extconf.rb failed *** Could not […]

无法在postgresql(rails)中的json字段中存储数组,无法将数组转换为json

这是我运行db:migrate时遇到的错误 rake aborted! can’t cast Array to json 这是我的桌子 class CreateTrips < ActiveRecord::Migration def change create_table :trips do |t| t.json :flights t.timestamps end end end 这是在我的seeds.rb文件中 flights = [{ depart_time_hour: 600, arrive_time_hour: 700, passengers: [ { user_id: 1, request: true } ] }] trip = Trip.create( { name: ‘Flight’, flights: flights.to_json } ) 出于某种原因,我不能这样做。 如果我这样做 […]

Ransack,Postgres – 从关联表中对列进行排序,使用distinct:true

我有一个使用Ransackgem的应用程序,我将它从Mysql转换为Postgres。 在排序列来自关联表并且distinct选项设置为true的实例中,Postgres会抛出此错误: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list Ransack github页面说,在这种情况下,“你是独立的。” 什么是最好的 – 任何! – 处理这种情况的策略? q = Contact.includes(:contact_type).search q.sorts = [‘contact_type_name asc’] q.result(distinct: true) PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list 谢谢!

gem install dm-postgres-adapter build错误

我正在尝试构建dm-postgres-adapter但是得到了这个错误。 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 *** extconf.rb failed *** Could not create […]

Heroku上的Rails 4.0.1,无法创建数据库

我无法得到rake db:migrate在Heroku上运行我的rails 4.0.1应用程序。 我猜我没有正确配置postgres …但是阅读heroku上的文档并没有真正帮助,我不知道该怎么做。 我对heroku或postgres不太了解。 任何帮助或资源将不胜感激。 如果我还有其他任何内容可以发帖,请告诉我。 (另外,我正在使用设计,如果这很重要) 当我运行heroku run rake db:migrate我得到这个: Running `rake db:migrate` attached to terminal… up, run.5077 PG::UndefinedTable: ERROR: relation “users” does not exist LINE 5: WHERE a.attrelid = ‘”users”‘::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = […]

Ruby中DateTime的毫秒分辨率

我有一个像2012-01-01T01:02:03.456这样的字符串,我使用ActiveRecord存储在Postgres数据库TIMESTAMP中。 不幸的是,Ruby似乎砍掉了毫秒: ruby-1.9.3-rc1 :078 > ‘2012-12-31T01:01:01.232323+3’.to_datetime => Mon, 31 Dec 2012 01:01:01 +0300 Postgrs支持微秒级分辨率。 如何才能相应地保存我的时间戳? 我需要至少毫秒的分辨率。 (PS是的,我可以在postgres中以毫秒整数列进行破解;这种方式会破坏ActiveRecord的整个目的。) 更新: 非常有用的响应表明,Ruby的DateTime并没有缩短毫秒数; 使用#to_f显示它。 但是,做: m.happened_at = ‘2012-01-01T00:00:00.32323’.to_datetime m.save! m.reload m.happened_at.to_f 是否丢弃毫秒。 现在,有趣的是,在Rails和Postgres中, created_at确实显示毫秒。 但其他时间戳字段(如上面的happen_at)则没有。 (也许Rails对created_at使用NOW()函数而不是传入DateTime)。 这导致了我的终极问题: 如何让ActiveRecord在时间戳字段上保留毫秒分辨率?