标签: pg

从Postgres时间戳中添加或减去时间

我将以下ruby代码与PG gem一起使用,以返回Postgres“无时区的时间戳”格式的时间戳。我不希望返回当前值,而是希望它返回值(-1小时)。

def get_latest_timestamp(id)
  conn1 = PGconn.open(:dbname => 'testdb')
  res = conn1.exec("SELECT MAX(time_of_search) FROM listings WHERE id=#{id}")
  res.values[0][0]
end
Run Code Online (Sandbox Code Playgroud)

ruby postgresql pg

1
推荐指数
1
解决办法
3618
查看次数

安装pg gem时出错

为了将我的rails应用程序部署到heroku,我通过添加更改了我的Gemfile

gem 'pg'
Run Code Online (Sandbox Code Playgroud)

我曾经做过

bundle install
Run Code Online (Sandbox Code Playgroud)

我收到以下错误 -

Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.1.1) 
Using i18n (0.6.9) 
Using minitest (4.7.5) 
Using multi_json (1.8.2) 
Using atomic (1.1.14) 
Using thread_safe (0.1.3) 
Using tzinfo (0.3.38) 
Using activesupport (4.0.0) 
Using builder (3.1.4) 
Using erubis (2.7.0) 
Using rack (1.5.2) 
Using rack-test (0.6.2) 
Using actionpack (4.0.0) 
Using mime-types (1.25.1) 
Using polyglot (0.3.3) 
Using treetop (1.4.15) 
Using mail (2.5.4) 
Using actionmailer (4.0.0) 
Using activemodel (4.0.0) 
Using activerecord-deprecated_finders (1.0.3) …
Run Code Online (Sandbox Code Playgroud)

macos gem heroku pg ruby-on-rails-4

1
推荐指数
1
解决办法
3529
查看次数

如何在 Rails 中安装 pg gem

我尝试安装 pg gem。但它会产生以下错误。谁能帮我解决这个问题?

root@localhost:/home/rails/Project# gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/pg-0.18.4/ext
/usr/bin/ruby2.3 -r ./siteconf20160908-9582-xu3pmx.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no …
Run Code Online (Sandbox Code Playgroud)

ruby rubygems ruby-on-rails pg ruby-on-rails-4

1
推荐指数
1
解决办法
3485
查看次数

无法在 Windows 上安装 pg gem

我正在尝试在我的项目中安装 pg gem,但是当我运行 gem install pg 或运行 bundle install 时出现以下错误:

ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

current directory: /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/pg-1.1.4/ext
/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/ruby -I /home/ec2- 
user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0 -r 
./siteconf20191103-5491-ro2ye0.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for …
Run Code Online (Sandbox Code Playgroud)

ruby windows postgresql rubygems pg

1
推荐指数
1
解决办法
924
查看次数

Postgresql WHERE子句添加''左右?

今天早上我切换到postgresql,现在我的地方选择不再工作了.

我想做的是超级简单:

shirt_ids = "1,5,6" # String generated by javascript
Shirt.where("id in (?)", shirt_ids)
Run Code Online (Sandbox Code Playgroud)

这给了我:

PG::Error: ERROR:  invalid input syntax for integer: "1,5,6"
LINE 1: SELECT "shirts".* FROM "shirts"  WHERE (id in ('1,5,6'))
Run Code Online (Sandbox Code Playgroud)

这有效:

Shirt.where("id in (#{shirt_ids})")
Run Code Online (Sandbox Code Playgroud)

但众所周知,这是不安全的.

我正在使用:

pg (0.13.2 x86-mingw32)
rails (3.2.2)
Run Code Online (Sandbox Code Playgroud)

Postgresql数据库是最新版本,今天早上我安装了它.

谢谢您的帮助.^

postgresql ruby-on-rails pg ruby-on-rails-3

0
推荐指数
1
解决办法
782
查看次数

如何在rails中创建postgres触发器?

我有一个表产品(id,name)和表product_raiting(product_id,rate_type,rate).当我创建新产品时,我需要为此产品创建三个raitings.

如何添加postgres触发器,例如:



    product.create
    product.product_raitings.create( :rate_type => 0, :rate => 0 )
    product.product_raitings.create( :rate_type => 1, :rate => 0 )
    product.product_raitings.create( :rate_type => 2, :rate => 0 )
    product.product_raitings.create( :rate_type => 3, :rate => 0 )

Run Code Online (Sandbox Code Playgroud)

请帮忙.

postgresql triggers ruby-on-rails pg

0
推荐指数
1
解决办法
1858
查看次数

如何使用PostgreSQL和Ruby将db表中的列名提取到数组中?

如何遍历给定数据库的表中的所有列标题,并将每个列名单独添加到数组中?

我知道我可以从表中收集所有信息,SELECT * FROM my_table但此时我只需要处理列标题.完成此任务的最佳方法是什么?

ruby postgresql pg

0
推荐指数
1
解决办法
1047
查看次数

actions_as_votable数据库模型在Rails控制台中不存在,但在PgAadmin中可用

我在我的项目中使用acts_as_votable gem。由于某些奇怪的原因,我无法访问中的Vote模型表Rails console。我重新加载了development环境,甚至重新启动了计算机。

我可以upvote一个模型和get_upvotes.size投票模型。

我想做一些专门的查询,例如Vote.where(...)。当我尝试Vote.all在Rails控制台中查询时,出现错误。顺便说一下,我正在使用postgresql进行开发。

2.0.0-p353 :007 > Vote.all
NameError: uninitialized constant Vote
Run Code Online (Sandbox Code Playgroud)

Vote模型存在于我的模型中,schema.rb而不存在于中app/models。该Vote表位于pgAdmin中。提前致谢。

rubygems ruby-on-rails rails-models pg acts-as-votable

0
推荐指数
1
解决办法
190
查看次数

pg gem 在 M1 mac 上安装失败:“错误:‘PQconnectdb’的类型冲突”

pg我正在M1 macbook pro 上的 mac osx 12.5 上安装gem。Ruby 打包程序在运行时找不到 libpq gem install pg

current directory: /Users/me/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.4/ext
/Users/me/.rbenv/versions/3.1.2/bin/ruby -I /Users/me/.rbenv/versions/3.1.2/lib/ruby/site_ruby/3.1.0 extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... yes
Using config values from /opt/homebrew/opt/libpq/bin/pg_config
checking for whether -Wl,-rpath,/opt/homebrew/opt/libpq/lib is accepted as LDFLAGS... yes
Using libpq from /opt/homebrew/opt/libpq/lib
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't …
Run Code Online (Sandbox Code Playgroud)

homebrew libpq bundler pg apple-m1

0
推荐指数
1
解决办法
1360
查看次数