Tag: postgresql

Rails / Postgres:“必须出现在GROUP BY子句中或用于聚合函数”

我正在使用这种方法: def self.lines_price_report(n) Income.group(‘date(filled_at)’).having(“date(filled_at) > ?”, Date.today – n).sum(:lines_price) end 我在Heroku中收到此错误: PG::Error: ERROR: column “incomes.filled_at” must appear in the GROUP BY clause or be used in an aggregate function 我怎样才能解决这个问题? 谢谢。 执行查询: SELECT SUM(“incomes”.”lines_price”) AS sum_lines_price, date(filled_at) AS date_filled_at FROM “incomes” HAVING (date(filled_at) > ‘2012-12-04’) GROUP BY date(filled_at) ORDER BY filled_at ASC 预期结果 [[“2012-12-04”, SUM_FOR_DATE], […]

错误未定义方法`的to_key’:尝试在Active Admin table_for上使用数组数据时的数组(Rails,Postgresql,postgres_ext gem)

我想使用我管理的数据进入一个数组数组,将它们放在我的一个活动管理控制台上的表(table_for)中 我的应用程序是一个每日交易应用程序,旨在了解更多Ruby on Rails。 感谢SO的帮助,我现在设法获得我在Array中需要的所有数据: 在Active Admin仪表板中计算序列化属性(数组)中值的出现次数(Rails,Active admin 1.0,Postgresql数据库,postgres_ext gem) 我想要使​​用的数组数据看起来像(它实际上是一个数组数组) 但我想要的是看起来像下面的图像,所以我想使用Active Admin的table_for(稍后具有所有导出function): 我的仪表板页面上的当前代码是 columns do column do data = Deal.connection.select_rows( %q{ with expanded_deals(id, goal) as ( select id, unnest(deal_main_goal) from deals) select goal, count(*) n from expanded_deals group by goal order by goal; }).each do |row| goal = row.first n = row.last.to_i #…. end […]

Rails 4:heroku基本计划上的ConnectionTimeoutError

我们正在开发一个简单的Rails 4 webapp ,由Heroku托管,提供免费计划。 最近,我们遇到了一些ActiveRecord::ConnectionTimeoutError – 每隔几天一次 – 我们并不真正理解它背后的原因。 你可能想看看这里的完整堆栈。 我们知道Heroku设置了与Postgres数据库的20个连接的池限制,这很可能是抛出exception的原因。 这是我们的猜测: 我们使用Herku调度程序每小时启动一次rake任务,并且由于该任务查询数据库,问题可能在于这些连接在使用后没有从池中释放。 所以我们试图将所有内容放在一个块中: ActiveRecord::Base.connection_pool.with_connection do #code with queries end 但这似乎并没有解决问题。 你有更好的建议/解释吗? 我们非常感谢任何帮助和/或见解,以及我们应该如何调试此问题。 PS:我们还尝试在专用的初始化程序中添加以下代码,但它没有解决问题 Rails.application.config.after_initialize do ActiveRecord::Base.connection_pool.disconnect! ActiveSupport.on_load(:active_record) do config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env] config[‘reaping_frequency’] = ENV[‘DB_REAP_FREQ’] || 10 # seconds config[‘pool’] = ENV[‘DB_POOL’] || 20 ActiveRecord::Base.establish_connection(config) end end

Heroku语言区域设置无法正常工作

它看起来像我在heroku上的语言区域设置不起作用。 On my local mashine : 1. maj Heroku : 01 May 00:00 我的看法: :short %> 地点: en: hello: “Hello world” views: pagination: previous: “« Tilbage” next: “Næste side »” # active_support date: # See http://sproget.dk/svarbase/SV00000046/ and http://en.wikipedia.org/wiki/Date_formats # either use traditional (2.10.03, 2. oktober 2003): “%e.%m.%y”, “%e. %B %Y” # or international ISO 8601 […]

PG :: UndefinedObject:错误:类型“hstore”不存在但它确实存在

首先,这可能看起来像是重复: postgres hstore存在且不存在于同一时间 但事实并非如此。 虽然我在这种情况下收到相同的错误消息。 在检查数据库中是否安装了hstore时,我们可以看到它是: ./psql -d photographerio_development -c ‘\dx’ List of installed extensions Name | Version | Schema | Description ———+———+————+————————————————– hstore | 1.2 | hstore | data type for storing sets of (key, value) pairs plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language 它也在template_1 DB上。 所以,当我尝试运行迁移来添加hstore时,我得到PG::Error: ERROR: extension “hstore” already exists […]

如何在rails中使用jsonb

我有一个使用Postgresql 9.4作为后端的rails项目。 我有这样的列: t.json :slot_details, null: false, default: {} 如何从JSON将其更改为JSONB? 我应该添加索引,并将更改为JSONB吗?

PostgreSQL + Rails citext

我正在尝试迁移到使用PostgreSQL 8.4的heroku,它有一个citext列类型,这是很好的,因为该应用程序是为MySQL编写的。 有没有办法使用:带有rails的citext(如果迁移是在MySQL上运行的,那么citext只会使用字符串/文本? 我找到了这张票,但似乎它暂时不会成为rails的一部分: https : //rails.lighthouseapp.com/projects/8994/tickets/3174-add-support-for-postgresql- citext列型

当数据库位于不同的服务器上时安装postgres gem

我的数据库与应用程序位于不同的服务器上。 当我运行“捆绑”时,我收到以下错误: 没有pg_config ……无论如何都要尝试。 如果构建失败,请使用–with-pg-config = / path / to / pg_config重试 如果应用服务器上实际没有安装pg,如何设置pg配置路径? 我也尝试过: bundle config build.pg –without-pg_config 谢谢

Rails – 如何存储大数字,如100000076685963

我需要存储大量数字:100000076685963 对于db字段类型的整数,哪个是大的。 在我的数据库迁移中,我使用: t.integer :fb_uid 我应该为这样的大数字使用什么字段类型? 谢谢

使用Postgresql后端在Heroku上的Rails应用程序中使用COPY FROM

我想让用户选择在我的Ruby on Rails 3.2应用程序中上传文件,并将数据导入数据库。 我想使用COPY FROM命令,因为它比插入ruby对象更快。 如果我做 User.connection.execute(“COPY users (name, taxon_id, created_at, updated_at) FROM ‘a.txt'”) 我明白了 ActiveRecord::StatementInvalid: PG::Error: ERROR: must be superuser to COPY to or from a file HINT: Anyone can COPY to stdout or from stdin. psql’s \copy command also works for anyone. 但是, \copy在数据库连接中也不起作用。 如何在Heroku上使用PostgreSQL轻松地从Rails中的平面文件上传数据? 你能获得超级用户权限吗?