Tag: postgresql

Mountain Lion上的pg gem’0.14.0’失败了

我刚从OS X Lion升级到OS X Mountain Lion。 我的铁路环境大部分都保持着机智。 我必须做的唯一步骤才能让事情恢复到良好状态: – 安装XCode 4.4 – 安装XCode 4.4命令行工具 – 安装gcc-4.2 一切顺利。 这是问题,当我运行bundle install时几乎所有的gem都安装正确,除了我需要的最重要的一个 – postgresql gem’pg’。 它特别适用于0.12.2以上的版本。 我正在使用ruby 1.9.3p125。 我可以成功地获取0.12.2 pg gem以及下面的版本,但是它们给了我分段错误(我猜是因为我正在使用的ruby版本)。 因此,这让我相信它特定于pg gem,而不是我的整体环境看到其他gem安装正常。 我也尝试重新安装Postgresql以确保我的postgres环境没问题,并且在这方面似乎很好。 有没有人能够安装’pg’gem版0.13.0或更高版本(更优选0.14.X)? 这是我的堆栈跟踪: Building native extensions. This could take a while… ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/caseyli/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking […]

Ruby on Rails:有没有办法从数据库中提取项目并按指定顺序返回它们?

我有一个项目ID, item_ids 。 我将此数组传递给ActiveRecord查询以从数据库中检索相应的项: Item.where(:id => item_ids) 有没有办法以与通过item_ids数组传入的顺序相同的顺序返回项目? 如果它有所不同,我在Ruby on Rails 3.0.12上使用PostgreSQL作为我的数据库。

如何将数据从ASCII(ISO / IEC 8859-1)导入到我的Rails / PGSQL数据库?

我正在尝试使用美国农业部发现的数据: http : //www.ars.usda.gov/Services/docs.htm? docid = 23634 ASCII(8.6Mb) – 该文件包含ASCII(ISO / IEC 8859-1)中的SR26数据,分隔文件。 这些表以关系格式组织,最好与关系数据库管理系统(RDBMS)一起使用,这将允许您形成自己的数据库查询并生成自定义报告。 我是新来操纵这样的数据,并认为我想用CSV格式,也许吧? 但是,那么我可能会失去关系,所以也许我应该去PGSQL。 不知道如何处理这个问题。 寻求指导,谢谢。

Rails中的多个数据库连接

我正在使用active_delegate在Rails中进行多个连接。 这里我使用mysql作为master_database用于某些模型,而postgresql用于其他一些模型。 问题是,当我尝试访问mysql模型时,我收到以下错误! 堆栈跟踪显示,它仍然使用postgresql适配器来访问我的mysql模型! RuntimeError: ERROR C42P01 Mrelation “categories” does not exist P15 F.\src\backend\parser\parse_relation.c L886 RparserOpenTable: SELECT * FROM “categories” STACKTRACE =========== d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:507:in `execute’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:985:in `select_raw’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:972:in `select’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:615:in `find’ D:/ROR/Aptana/dedomenon/app/models/category.rb:50:in `get_all_with_exclusive_scope’ D:/ROR/Aptana/dedomenon/app/models/category.rb:50:in `get_all_with_exclusive_scope’ D:/ROR/Aptana/dedomenon/app/controllers/categories_controller.rb:48:in `index’ 这是我的database.yml文件 postgre: &postgre adapter: postgresql […]

错误:关系“places”不存在Heroku数据库导入

我知道在postgres的查询中有引号或区分大小写错误时会发生这种错误。 实际上我有一个.sql文件,我试图通过命令行在我的heroku数据库中导入,但不断出现此错误。我的.sql文件包含这些查询 INSERT INTO “places” (“Name”, “Address”) VALUES (‘Cookshop Restaurant &amp’, ‘ Bar’), (‘Cafeteria’, ‘119 7th Ave, New York, NY 10011’), (‘Franchia Vegan Cafe’, ’12 Park Ave, New York, NY 10016′);

Rails报告找不到那里的列

我目前正在尝试使用Rails对表进行复杂的WHERE搜索,麻烦的是我收到错误: PG::Error: ERROR: column “email” does not exist LINE 1: SELECT “bans”.* FROM “bans” WHERE (Email=” AND IP=” AND (… ^ : SELECT “bans”.* FROM “bans” WHERE (Email=” AND IP=” AND (Username=’NULL’ )) 我知道该列确实存在,并且做一个rails dbconsole给了我以下内容: Jungle=> select * from bans; id | Username | IP | Email | Reason | Length | created_at | updated_at […]

Rails迁移:PostgreSQL上的Bigint似乎失败了吗?

尝试使用bigint列创建表会创建标准整数列。 怎么可能出错? 我不知道从哪里开始寻找。 我在迁移中使用它: create_table :table_name do |t| t.integer :really_big_int, limit: 8 end 我正在使用Ruby 1.9.2,PostgreSQL 9.0.3和Rails 3.0.9。 我已经删除了数据库并多次运行迁移,但它仍然没有创建bigint列。

如何使用Postgresql创建简单的模糊搜索?

我的基于RoR的网站上的搜索function有点问题。 我有很多产品和一些CODE。 此代码可以是任何字符串,如“AB-123-lHdfj”。 现在我使用ILIKE运算符来查找产品: Product.where(“code ILIKE ?”, “%” + params[:search] + “%”) 它工作正常,但找不到像“AB123-lHdfj”或“AB123lHdfj”这样的代码的产品。 我该怎么办? 可能postgresql有一些字符串规范化function,还是其他一些方法来帮助我? 🙂

PG对等身份validation失败

我有一个用户密码与database.yml中指定的密码匹配 postgres=# select * from pg_user ; usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig ————+———-+————-+———-+———–+———+———-+———-+———– goodsounds | 16386 | t | t | t | t | ******** | | postgres | 10 | t | t | t | t | ******** | | […]

PG :: GROUP BY子句中的错误

我想不出更好的方法来重构下面的代码(看到这个问题 ),虽然我知道它非常难看。 但是,它会抛出一个Postgres错误(不是SQLite): ActiveRecord::StatementInvalid: PG::Error: ERROR: column “articles.id” must appear in the GROUP BY clause or be used in an aggregate function 查询本身是: SELECT “articles”.* FROM “articles” WHERE “articles”.”user_id” = 1 GROUP BY publication 它来自以下视图代码: =@user.articles.group(:publication).map do |p| =p.publication =@user.articles.where(“publication = ?”, p.publication).sum(:twitter_count) =@user.articles.where(“publication = ?”, p.publication).sum(:facebook_count) =@user.articles.where(“publication = ?”, p.publication).sum(:linkedin_count) 在SQLite中,这给出了输出(例如)NYT 12 18 14 […]