pg

How do I fetch column names from a db table into an array, using PostgreSQL and Ruby?

霸气de小男生 提交于 2019-12-25 00:27:35
问题 How can I iterate through all of the column headers in a table for a given database and add each column name individually to an array? I know I can gather all of the information from the table using SELECT * FROM my_table but I need to work with just the column headers at this point. What is the best way to accomplish this? 回答1: Are you using the pg gem? If so, you can try this: require 'pg' # `db_config` must contain your database configuration conn = PG::Connection.open(db_config) column

Receiving the error PG::UndefinedColumn: ERROR: column mymodels.distance does not exist when using Geocoder's near method

懵懂的女人 提交于 2019-12-23 11:44:18
问题 When using this query (the same as in Railscasts episode #273): @locations = Location.near(params[:search], 50, :order => :distance) Or, to be more concise: @mymodels = MyModel.near(address, distance, order: :distance) I get the error: PG::UndefinedColumn: ERROR: column mymodels.distance does not exist The distance column is supposed to be added to the results by the Geocoder gem but it does not appear to appear in the results (so I get the above error). 回答1: When using Postgres along with

Receiving the error PG::UndefinedColumn: ERROR: column mymodels.distance does not exist when using Geocoder's near method

懵懂的女人 提交于 2019-12-23 11:44:07
问题 When using this query (the same as in Railscasts episode #273): @locations = Location.near(params[:search], 50, :order => :distance) Or, to be more concise: @mymodels = MyModel.near(address, distance, order: :distance) I get the error: PG::UndefinedColumn: ERROR: column mymodels.distance does not exist The distance column is supposed to be added to the results by the Geocoder gem but it does not appear to appear in the results (so I get the above error). 回答1: When using Postgres along with

Can we always fetch date column as string (varchar) with knex and postgres?

微笑、不失礼 提交于 2019-12-22 09:56:35
问题 I have a column in postgres database with type date . It is a column like birthday, which is just a date and does not need to have a time part. When fetching this column with knex, the result is a javascript Date object. It is presumably doing new Date(row.birthday) , and this is the result that is sent to the client. The problem now is that the value that the client receives is in the standard ISO 8601 format with the time part and the Z . When the client tries to create a new Date object

How to fix “PG::Error: Wait on socket” error when accessing Postgres DB in Rails 3 app

大憨熊 提交于 2019-12-20 05:49:20
问题 One of our application is built on Rails 3 which uses postgres as database. We observe that while doing load test i.e continuously submitting request, there are random exceptions related to database (comes from postgres_adapter): 1. PG::Error: Wait on socket error (WaitForMultipleObjects): 2. NoMethodError: undefined method `result_error_field' for nil:NilClass: I am not able to find any reference on cause of these issues as they're coming at different points. Any help on how to avoid this or

Postgres on AZURE Unhandled rejection TimeoutError: ResourceRequest timed out

时间秒杀一切 提交于 2019-12-20 04:17:23
问题 I have a database postgres on azure, whith General Purpose, 2 vCore(s), 100 GB. at this moment, when i do a simple request to database, database answer me lot of times with message: Unhandled rejection TimeoutError: ResourceRequest timed out at ResourceRequest._fireTimeout (/Project/development/TFS-git/RAILES/railes-backend-api-pt-0317/node_modules/sequelize/node_modules/generic-pool/lib/ResourceRequest.js:62:17) at Timeout.bound (/Project/development/****/*****/*********/node_modules

Set default value for Postgres JSON column in Rails < 4

本秂侑毒 提交于 2019-12-18 12:58:06
问题 So I'm starting to use the Postgres JSON datatype, now that there's a lot of fun stuff you can do with it. In one of my Rails apps which is not yet Rails 4 (where support for Postgres JSON has been added) I added a JSON column like this: create_table :foo do |t| t.column :bar, :json end but I can't figure out how to set a default value for the column. I tried all variations like {} , '{}' , '{}'::json , '[]'::json etc. but I either get an error when the migration runs or it simply doesn't

Postgres - the last version 0.14.0 of the “pg” gem gives error

独自空忆成欢 提交于 2019-12-18 08:26:05
问题 I have updated my bundler which contains pg gem and I got the error An error occured while installing pg (0.14.0), and Bundler cannot continue. Make sure that `gem install pg -v '0.14.0'` succeeds before bundling. I have checked this gem on rubygems.org and today (June 23) was released this version. I don't know why, but the version doesn't works me correctly and return the error above. The solution is set up the specific version - in this case gem "pg", "~> 0.13.2" Anyone with the same issue

Postgres - the last version 0.14.0 of the “pg” gem gives error

孤街浪徒 提交于 2019-12-18 08:24:47
问题 I have updated my bundler which contains pg gem and I got the error An error occured while installing pg (0.14.0), and Bundler cannot continue. Make sure that `gem install pg -v '0.14.0'` succeeds before bundling. I have checked this gem on rubygems.org and today (June 23) was released this version. I don't know why, but the version doesn't works me correctly and return the error above. The solution is set up the specific version - in this case gem "pg", "~> 0.13.2" Anyone with the same issue

Installing pg -v 0.17.1

陌路散爱 提交于 2019-12-18 05:22:03
问题 I'm using/I want to use Postgresql as database, but when I type "bundle install" or "bundle update", I get this error, what do I do to fix this? :) Installing pg (0.17.1) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby 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...