Giter Club home page Giter Club logo

sequel_pg's Introduction

sequel_pg

sequel_pg overwrites the inner loop of the Sequel postgres adapter row fetching code with a C version. The C version is significantly faster than the pure ruby version that Sequel uses by default.

Real world difference

The speed up that sequel_pg gives you depends on what you are selecting, but it should be noticeable whenever many rows are selected. Here’s an example that shows the difference it makes on a couple of models:

Track.count # => 202261
Album.count # => 7264

Without sequel_pg:

puts Benchmark.measure{Track.each{}}
# 3.400000   0.290000   3.690000 (  4.005150)
puts Benchmark.measure{10.times{Album.each{}}}
# 2.180000   0.120000   2.300000 (  2.479352)

With sequel_pg:

puts Benchmark.measure{Track.each{}}
# 1.660000   0.260000   1.920000 (  2.287216)
puts Benchmark.measure{10.times{Album.each{}}}
# 0.960000   0.110000   1.070000 (  1.260913)

sequel_pg also speeds up the following Dataset methods:

  • map

  • as_hash/to_hash

  • to_hash_groups

  • select_hash

  • select_hash_groups

  • select_map

  • select_order_map

Additionally, in most cases sequel_pg also speeds up the loading of model datasets by optimizing model instance creation.

Streaming

If you are using PostgreSQL 9.2+ on the client, then sequel_pg should enable streaming support. This allows you to stream returned rows one at a time, instead of collecting the entire result set in memory (which is how PostgreSQL works by default). You can check if streaming is supported by:

Sequel::Postgres.supports_streaming?

If streaming is supported, you can load the streaming support into the database:

DB.extension(:pg_streaming)

Then you can call the Dataset#stream method to have the dataset use the streaming support:

DB[:table].stream.each{|row| ...}

If you want to enable streaming for all of a database’s datasets, you can do the following:

DB.stream_all_queries = true

Installing the gem

gem install sequel_pg

Make sure the pg_config binary is in your PATH so the installation can find the PostgreSQL shared library and header files. Alternatively, you can use the POSTGRES_LIB and POSTGRES_INCLUDE environment variables to specify the shared library and header directories.

Running the specs

sequel_pg is designed to replace a part of Sequel, so it should be tested using Sequel’s specs (the spec_postgres rake task). There is a spec_cov task that assumes you have Sequel checked out at ../sequel, and uses a small spec suite for parts of sequel_pg not covered by Sequel’s specs. It sets the SEQUEL_PG_STREAM environment variable when running Sequel’s specs, make sure that spec/spec_config.rb in Sequel is set to connect to PostgreSQL and use the following additional settings:

DB.extension(:pg_streaming)
DB.stream_all_queries = true

Reporting issues/bugs

sequel_pg uses GitHub Issues for tracking issues/bugs:

http://github.com/jeremyevans/sequel_pg/issues

Contributing

The source code is on GitHub:

http://github.com/jeremyevans/sequel_pg

To get a copy:

git clone git://github.com/jeremyevans/sequel_pg.git

There are only a few requirements, which you should probably have before considering use of the library:

  • Rake

  • Sequel

  • pg

  • libpq headers and library

Building

To build the library from a git checkout, after installing the requirements:

rake build

Known Issues

  • You must be using the ISO PostgreSQL date format (which is the default). Using the SQL, POSTGRESQL, or GERMAN date formats will result in incorrect date/timestamp handling. In addition to PostgreSQL defaulting to ISO, Sequel also manually sets the date format to ISO by default, so unless you are overriding that setting (via DB.use_iso_date_format = false), you should be OK.

  • Adding your own type conversion procs only has an effect if those types are not handled by default.

  • You do not need to require the library, the sequel postgres adapter will require it automatically. If you are using bundler, you should add it to your Gemfile like so:

    gem 'sequel_pg', :require=>'sequel'
    
  • sequel_pg currently calls functions defined in the pg gem, which does not work on Windows and does not work in some unix-like operating systems that disallow undefined functions in shared libraries. If RbConfig::CONFIG['LDFLAGS'] contains -Wl,--no-undefined, you’ll probably have issues installing sequel_pg. You should probably fix RbConfig::CONFIG['LDFLAGS'] in that case.

Author

Jeremy Evans <[email protected]>

sequel_pg's People

Contributors

beanieboi avatar bornio avatar dbussink avatar delphaber avatar docelic avatar funny-falcon avatar jeremyevans avatar larskanis avatar maxsz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sequel_pg's Issues

`to_hash` raises ArgumentError

The newest version of sequel_pg causes Sequel::Dataset#to_hash to raise an ArgumentError. Here's a minimal repro case; it requires a test Postgres database on localhost that the default user has CREATE privileges on:

#!/usr/bin/env ruby

gem 'pg', '= 0.18.4'
gem 'sequel', '= 4.33.0'
gem 'sequel_pg', '= 1.6.15'

require 'pg'
require 'sequel'

DB = Sequel.connect( 'postgresql:/test' )

DB << 'DROP TABLE IF EXISTS foo'
DB << 'CREATE TABLE foo ( id serial, name text )'

ds = DB[:foo]
ds.to_hash( :id )

Running this in my environment looks like:

$ ruby -vd examples/to_hash_breakage.rb
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
Exception `LoadError' at /Users/ged/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems.rb:1222 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/ged/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems.rb:1231 - cannot load such file -- rubygems/defaults/ruby
eval:1: warning: instance variable @ajd not initialized
/Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel_pg-1.6.15/lib/sequel_pg.bundle: warning: method redefined; discarding old yield_hash_rows
/Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel-4.33.0/lib/sequel/adapters/postgres.rb:854: warning: previous definition of yield_hash_rows was here
/Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel_pg-1.6.15/lib/sequel_pg.bundle: warning: method redefined; discarding old fetch_rows_set_cols
/Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel-4.33.0/lib/sequel/adapters/postgres.rb:832: warning: previous definition of fetch_rows_set_cols was here
/Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel-4.33.0/lib/sequel/dataset/query.rb:80: warning: instance variable @columns not initialized
Exception `ArgumentError' at /Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel_pg-1.6.15/lib/sequel_pg/sequel_pg.rb:39 - wrong number of arguments (3 for 1..2)
/Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel-4.33.0/lib/sequel/dataset/actions.rb:718:in `to_hash': wrong number of arguments (3 for 1..2) (ArgumentError)
    from /Users/ged/.rvm/gems/ruby-2.2.4@[gemset]/gems/sequel_pg-1.6.15/lib/sequel_pg/sequel_pg.rb:39:in `to_hash'
    from examples/to_hash_breakage.rb:16:in `<main>'

Install on CentOS 8 + postgresql14(pg official guide) compile failed.

I install pg use following solution, which come from https://www.postgresql.org/download/linux/redhat/

# Install the repository RPM:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable the built-in PostgreSQL module:
sudo dnf -qy module disable postgresql

# Install PostgreSQL and devel tools
sudo dnf install -y postgresql14-devel

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14

After done this, i can install pg gem successful, it works well with sequel.

but, when i install sequel_pg, it failed, following is log.

have_library: checking for -lms/libpq... -------------------- no

"gcc -o conftest -I/home/deployer/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0/x86_64-linux -I/home/deployer/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0/ruby/backward -I/home/deployer/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0 -I.    -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable  -fPIC -Drb_tainted_str_new=rb_str_new -DNO_TAINT -Wall  conftest.c  -L. -L/home/deployer/.rvm/rubies/ruby-3.0.2/lib -Wl,-rpath,/home/deployer/.rvm/rubies/ruby-3.0.2/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/deployer/.rvm/rubies/ruby-3.0.2/lib -L/home/deployer/.rvm/rubies/ruby-3.0.2/lib -lruby -lms/libpq  -lm   -lc"
/usr/bin/ld: cannot find -lms/libpq
collect2: error: ld returned 1 exit status
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     int (* volatile tp)(void)=(int (*)(void))&t;
 9:     printf("%d", (*tp)());
10:   }
11: 
12:   return !!argv[argc];
13: }
14: 
15: int t(void) { ; return 0; }
/* end */

But, it seem like current pg official install guide no libpq-devel package anymore.
in fact when i try to install it,it told me install

[deployer@zw963 20211022024949]$ sudo dnf install libpq-devel
Last metadata expiration check: 3:39:35 ago on Fri 22 Oct 2021 07:31:35 AM HKT.
Package postgresql14-devel-14.0-1PGDG.rhel8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

but, this package not exists, it just replace by postgresql14-devel-14.0-1PGDG.rhel8.x86_64.

[deployer@zw963 20211022024949]$ rpm -q libpq-devel
package libpq-devel is not installed
[deployer@zw963 20211022024949]$ rpm -q postgresql14-devel
postgresql14-devel-14.0-1PGDG.rhel8.x86_64

use pkg-config to find parameters to link against libpq

pg_config was never really meant to be used for programs using libpq.
But for lack of better alternatives everyone started using it in the
past. There is a better alternative now pkg-config libpq.

Index: sequel_pg-1.12.0/ext/sequel_pg/extconf.rb
===================================================================
--- sequel_pg-1.12.0.orig/ext/sequel_pg/extconf.rb
+++ sequel_pg-1.12.0/ext/sequel_pg/extconf.rb
@@ -1,8 +1,10 @@
 require 'mkmf'
 $CFLAGS << " -O0 -g" if ENV['DEBUG']
 $CFLAGS << " -Wall " unless RUBY_PLATFORM =~ /solaris/
+if !pkg_config('libpq')
 dir_config('pg', ENV["POSTGRES_INCLUDE"] || (IO.popen("pg_config --includedir").readline.chomp rescue nil),                                                                                  
                  ENV["POSTGRES_LIB"]     || (IO.popen("pg_config --libdir").readline.chomp rescue nil))                                                                                      
+end

 if (have_library('pq') || have_library('libpq') || have_library('ms/libpq')) && have_header('libpq-fe.h')                                                                                    
   have_func 'PQsetSingleRowMode'

Unable to install gem; format-security error

I'm having an issue installing the sequel_pg v1.6.5 gem on a fairly vanilla AWS instance. It fails with this error:

sequel_pg.c:279:3: error: format not a string literal and no format arguments [-Werror=format-security]

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post aobut this project for more information.

1.12.1 Fails to Install on macOS with Postgres.app

I've tried most of the many workarounds often proposed to get the pg gem to install when it is being troublesome on macOS (though that gem is having no troubles in this case), but none work for sequel_pg 1.12.1. Since sequel_pg 1.12.0 works, I'm guessing the breaking change is #31

checking for -lpq... yes
checking for libpq-fe.h... no
*** 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 more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=[...]/ruby-2.6.3/bin/$(RUBY_BASE_NAME)
	--with-libpq-config
	--without-libpq-config
	--with-pkg-config
	--without-pkg-config
	--with-pqlib
	--without-pqlib
Could not find PostgreSQL build environment (libraries & headers): Makefile not created

And mkmf.log just echoes that notion, i.e., libpq-fe.h is not found.

Note, I'm testing this on a brand new Mac with factory-installed 10.14.5 and Xcode 10.2.1 as the first and only Xcode install, ditto Postgres.app 2.3b1. CLI tools are installed, no other native gems, including pg, are having issues, nor is the previous version of sequel_pg. PATH includes the correct binaries for Postgres.

sequel_pg is still trying to parse the money (and int2vector?) type.

Sequel stopped parsing the money type because it would just convert to a 0.0 BigDecimal (jeremyevans/sequel@e9a002c), but sequel_pg is still doing this:

Loading development environment (Rails 3.2.11)
1.9.3p327 :001 > c = DB[:charges].get(:amount)
 => #<BigDecimal:5fc8668,'0.0',9(9)> 

# comment out sequel_pg in the Gemfile

Loading development environment (Rails 3.2.11)
1.9.3p327 :001 > c = DB[:charges].get(:amount)
 => "$10.00" 

I haven't tested int2vector since I'm unfamiliar with it, but it was removed from Sequel in the same commit, so it may be doing the same.

Thanks!

uninitialized constant Postgres

So I installed the gem no problem

$ gem install sequel_pg
Building native extensions.  This could take a while...
Successfully installed sequel_pg-1.6.10
1 gem installed

I also have pg_config in my PATH:

which pg_config
/usr/local/bin/pg_config

However after bundle install I run rackup and get this error:

  uninitialized constant Postgres (NameError)
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `const_get'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
  from ~/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
  from ~/apps/dml/roda/config/boot.rb:13:in `<top (required)>'
    # This is raised when I call: Bundler.require(:default)
  from ~/apps/dml/roda/config.ru:3:in `require'
  from ~/apps/dml/roda/config.ru:3:in `block in <main>'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  from ~/apps/dml/roda/config.ru:in `new'
  from ~/apps/dml/roda/config.ru:in `<main>'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
  from ~/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
  from ~/.rvm/gems/ruby-2.1.2/bin/rackup:23:in `load'
  from ~/.rvm/gems/ruby-2.1.2/bin/rackup:23:in `<main>'
  from ~/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
  from ~/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'

A peek at my Gemfile

gem 'pg'
gem 'roda'
gem 'sequel'
gem 'sequel_pg'

Am I missing something, or is this a legit bug?

IPAddr native implementation breaks Model#save

Hey there - I noticed that as of 1.10.0 inet is cast to an IPAddr - which is great! However, it seems to be interfering with Sequel::Model. I have have a simple test table like so:

  • id serial primary key
  • address inet
  • label varchar

When I save a new row, I set address with a String object. It gets translated to IPAddr (cool), but breaks subsequent #save calls.

can't express #<IPAddr: IPv4:192.168.0.1/255.255.255.255> as a SQL literal

I'm using ruby 2.6.5 (via rvm), and have verified this happening on multiple systems (Arch, FreeBSD 11, FreeBSD 12). I tested with a fresh gemset, and only installed sequel, and sequel_pg.

[katelyn@h ~]$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
[katelyn@h ~]$ gem list | egrep '(pg|sequel)'
pg (1.2.3)
sequel (5.30.0)
sequel_pg (1.12.5)

Here's a short barebones test script:

require 'sequel'

DB = Sequel.connect( 'postgres://postgres:[email protected]:5432/postgres?search_path=test' )

DB.create_table( :tests ) do
    primary_key :id
    inet :address
    varchar :label
end

class Test < Sequel::Model
end

t = Test.new( address: '192.168.0.1' )
t.save

puts "Created: #{t.inspect}"

tt = Test.find( address: '192.168.0.1' )

puts "Found: #{tt.inspect}"

begin
    tt.label = 'something'
    tt.save
rescue => e
    puts "Exception: #{e.message}"
end

tt = Test.find( address: '192.168.0.1' )
puts "Final: #{tt.inspect}"

DB.drop_table( :tests )

With just sequel and pg, I get this:

[katelyn@h ~]$ ruby test.rb 
Created: #<Test @values={:id=>1, :address=>"192.168.0.1", :label=>nil}>
Found: #<Test @values={:id=>1, :address=>"192.168.0.1", :label=>nil}>
Final: #<Test @values={:id=>1, :address=>"192.168.0.1", :label=>"something"}>

But, with sequel_pg installed, I get this:

[katelyn@h ~]$ ruby test.rb 
Created: #<Test @values={:id=>1, :address=>#<IPAddr: IPv4:192.168.0.1/255.255.255.255>, :label=>nil}>
Found: #<Test @values={:id=>1, :address=>#<IPAddr: IPv4:192.168.0.1/255.255.255.255>, :label=>nil}>
Exception: can't express #<IPAddr: IPv4:192.168.0.1/255.255.255.255> as a SQL literal
Final: #<Test @values={:id=>1, :address=>#<IPAddr: IPv4:192.168.0.1/255.255.255.255>, :label=>nil}>

Sorry if this is expected behavior (i.e. I should re-cast address) or something; not really keen on Postgres and Sequel, but learning!

Undefined method `single_row_mode='

Hello,

I'm trying to fix a bug we randomly have in one of our applications. Our initialization code looks very similar to this.

DB = Sequel.connect(db_config)

if Sequel::Postgres.supports_streaming?
  DB.extension(:pg_streaming)
  DB.stream_all_queries = true
else
  puts "Streaming not supported" 
end

Sequel.extension :migration

unless Sequel::Migrator.is_current?(DB, File.join(APP_ROOT,"db","migrate"))
  puts "DB is missing migrations"
end

We are running sequel 4.29.0 and sequel_pg 1.6.13.

This is the complete stacktrace (only at the sequel level).

NoMethodError: undefined method `single_row_mode=' for #<Sequel::Postgres::Adapter:0x9c58b50>
/my-app/gems/sequel_pg-1.6.13/lib/sequel/extensions/pg_streaming.rb:45:in `_execute'
/my-app/gems/sequel-4.29.0/lib/sequel/adapters/postgres.rb:340:in `block (2 levels) in execute'
/my-app/gems/sequel-4.29.0/lib/sequel/adapters/postgres.rb:545:in `check_database_errors'
/my-app/gems/sequel-4.29.0/lib/sequel/adapters/postgres.rb:340:in `block in execute'
/my-app/gems/sequel-4.29.0/lib/sequel/database/connecting.rb:249:in `block in synchronize'
/my-app/gems/sequel-4.29.0/lib/sequel/connection_pool/threaded.rb:103:in `hold'
/my-app/gems/sequel-4.29.0/lib/sequel/database/connecting.rb:249:in `synchronize'
/my-app/gems/sequel-4.29.0/lib/sequel/adapters/postgres.rb:340:in `execute'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:950:in `execute'
/my-app/gems/sequel_pg-1.6.13/lib/sequel/extensions/pg_streaming.rb:98:in `fetch_rows'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:833:in `with_sql_each'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:841:in `with_sql_first'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:659:in `single_record!'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:647:in `single_record'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:669:in `single_value'
/my-app/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:247:in `get'
/my-app/gems/sequel-4.29.0/lib/sequel/extensions/migration.rb:542:in `current_migration_version'
/my-app/gems/sequel-4.29.0/lib/sequel/extensions/migration.rb:519:in `is_current?'
/my-app/gems/sequel-4.29.0/lib/sequel/extensions/migration.rb:374:in `is_current?'

I read some of the sequel_pg code and found that when adding the pg_streaming extension, the extension disconnects the database. I'm thinking that for some reason (under certain conditions) the connection is not back in time and that is why the single_row_mode call on the connection fails.

I'm also wondering if this could be related to this fix 8274ba6. I'm not familiar with the codebase so all this are wild guesses.

Thanks before hand!

Not compatible with pg 1.1.0

I'm getting this after upgrading pg from 1.0.0 to 1.1.0:

TypeError: wrong argument type PG::Result (expected Data)
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:679:in `yield_hash_rows'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:679:in `block in fetch_rows'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:155:in `execute'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:514:in `_execute'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:326:in `block (2 levels) in execute'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:536:in `check_database_errors'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:326:in `block in execute'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/database/connecting.rb:301:in `block in synchronize'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/connection_pool/threaded.rb:107:in `hold'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/database/connecting.rb:301:in `synchronize'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:326:in `execute'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/dataset/actions.rb:1081:in `execute'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:679:in `fetch_rows'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/dataset/actions.rb:154:in `each'
/var/lib/gems/2.4.0/gems/sequel_pg-1.6.19/lib/sequel_pg/sequel_pg.rb:62:in `each'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/dataset/actions.rb:465:in `map'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/dataset/actions.rb:465:in `map'
/var/lib/gems/2.4.0/gems/sequel_pg-1.6.19/lib/sequel_pg/sequel_pg.rb:24:in `map'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/shared/postgres.rb:1167:in `pg_class_relname'
/var/lib/gems/2.4.0/gems/sequel-4.48.0/lib/sequel/adapters/shared/postgres.rb:689:in `tables'

Sequel::DatabaseError: PG::UnableToSend: another command is already in progress

Following can reproduce on my own project.

my db config:

DB = Sequel.connect(db_url, timeout: 10000)
if DB.adapter_scheme == :postgres
  DB.extension :pg_streaming
  DB.stream_all_queries = true
end

And i write a rake task like this:

task :update_insider_history_insider_id do
	# a insider history many to one insider (foreign key: insider_id)
	# i want to traversing all `insider histories`, and create insider use name string if not exists, 
	# after create it, then update foreign key insider_id.
	
    InsiderHistory.dataset.each do |ih|
      insider = Insider.find_or_create(name: ih.name)
      ih.update(insider_id: insider.id)
    end
end

It works well if comment DB.stream_all_queries = true out in db config, but, if not,
i got following error message.

 ╰─ $ rake db:update_insider_history_insider_id
RACK_ENV=development
DB connected: postgres://postgres:postgres@localhost:5432/marketbet_crawler_development
I, [2021-11-09T19:18:00.322859 #1146592]  INFO -- : (0.000271s) SET standard_conforming_strings = ON
I, [2021-11-09T19:18:00.323156 #1146592]  INFO -- : (0.000162s) SET client_min_messages = 'WARNING'
I, [2021-11-09T19:18:00.323363 #1146592]  INFO -- : (0.000129s) SET DateStyle = 'ISO'
I, [2021-11-09T19:18:00.324160 #1146592]  INFO -- : (0.000068s) SELECT CAST(current_setting('server_version_num') AS integer) AS v
I, [2021-11-09T19:18:00.325231 #1146592]  INFO -- : (0.000084s) SELECT "pg_attribute"."attname" AS "name", CAST("pg_attribute"."atttypid" AS integer) AS "oid", CAST("basetype"."oid" AS integer) AS "base_oid", format_type("basetype"."oid", "pg_type"."typtypmod") AS "db_base_type", format_type("pg_type"."oid", "pg_attribute"."atttypmod") AS "db_type", pg_get_expr("pg_attrdef"."adbin", "pg_class"."oid") AS "default", NOT "pg_attribute"."attnotnull" AS "allow_null", COALESCE(("pg_attribute"."attnum" = ANY("pg_index"."indkey")), false) AS "primary_key", "pg_attribute"."attidentity", ("pg_attribute"."attgenerated" != '') AS "generated" FROM "pg_class" INNER JOIN "pg_attribute" ON ("pg_attribute"."attrelid" = "pg_class"."oid") INNER JOIN "pg_type" ON ("pg_type"."oid" = "pg_attribute"."atttypid") LEFT OUTER JOIN "pg_type" AS "basetype" ON ("basetype"."oid" = "pg_type"."typbasetype") LEFT OUTER JOIN "pg_attrdef" ON (("pg_attrdef"."adrelid" = "pg_class"."oid") AND ("pg_attrdef"."adnum" = "pg_attribute"."attnum")) LEFT OUTER JOIN "pg_index" ON (("pg_index"."indrelid" = "pg_class"."oid") AND ("pg_index"."indisprimary" IS TRUE)) WHERE (("pg_attribute"."attisdropped" IS FALSE) AND ("pg_attribute"."attnum" > 0) AND ("pg_class"."oid" = CAST(CAST('"insider_histories"' AS regclass) AS oid))) ORDER BY "pg_attribute"."attnum"
I, [2021-11-09T19:18:00.329566 #1146592]  INFO -- : (0.000040s) SELECT * FROM "insider_histories"
E, [2021-11-09T19:18:00.331996 #1146592] ERROR -- : PG::UnableToSend: another command is already in progress: SELECT "pg_attribute"."attname" AS "name", CAST("pg_attribute"."atttypid" AS integer) AS "oid", CAST("basetype"."oid" AS integer) AS "base_oid", format_type("basetype"."oid", "pg_type"."typtypmod") AS "db_base_type", format_type("pg_type"."oid", "pg_attribute"."atttypmod") AS "db_type", pg_get_expr("pg_attrdef"."adbin", "pg_class"."oid") AS "default", NOT "pg_attribute"."attnotnull" AS "allow_null", COALESCE(("pg_attribute"."attnum" = ANY("pg_index"."indkey")), false) AS "primary_key", "pg_attribute"."attidentity", ("pg_attribute"."attgenerated" != '') AS "generated" FROM "pg_class" INNER JOIN "pg_attribute" ON ("pg_attribute"."attrelid" = "pg_class"."oid") INNER JOIN "pg_type" ON ("pg_type"."oid" = "pg_attribute"."atttypid") LEFT OUTER JOIN "pg_type" AS "basetype" ON ("basetype"."oid" = "pg_type"."typbasetype") LEFT OUTER JOIN "pg_attrdef" ON (("pg_attrdef"."adrelid" = "pg_class"."oid") AND ("pg_attrdef"."adnum" = "pg_attribute"."attnum")) LEFT OUTER JOIN "pg_index" ON (("pg_index"."indrelid" = "pg_class"."oid") AND ("pg_index"."indisprimary" IS TRUE)) WHERE (("pg_attribute"."attisdropped" IS FALSE) AND ("pg_attribute"."attnum" > 0) AND ("pg_class"."oid" = CAST(CAST('"insiders"' AS regclass) AS oid))) ORDER BY "pg_attribute"."attnum"
E, [2021-11-09T19:18:00.332344 #1146592] ERROR -- : PG::UnableToSend: another command is already in progress: SELECT * FROM "insiders" LIMIT 0
rake aborted!
Sequel::DatabaseError: PG::UnableToSend: another command is already in progress
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:81:in `send_query'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:81:in `block in execute_query'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/database/logging.rb:43:in `log_connection_yield'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:81:in `execute_query'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:144:in `block in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:120:in `check_disconnect_errors'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:144:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:500:in `_execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:47:in `_execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:318:in `block (2 levels) in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:522:in `check_database_errors'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:318:in `block in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/connection_pool/threaded.rb:88:in `hold'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/database/connecting.rb:269:in `synchronize'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:318:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/dataset/actions.rb:1093:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:112:in `fetch_rows'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/dataset/actions.rb:152:in `each'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel_pg/sequel_pg.rb:81:in `each'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/dataset/actions.rb:86:in `columns!'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/dataset/actions.rb:76:in `columns'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:242:in `columns'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:788:in `block (2 levels) in get_db_schema'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:686:in `block in check_non_connection_error'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/database/transactions.rb:201:in `block in transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/connection_pool/threaded.rb:88:in `hold'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/database/connecting.rb:269:in `synchronize'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/database/transactions.rb:195:in `transaction'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:686:in `check_non_connection_error'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:788:in `block in get_db_schema'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:821:in `get_db_schema'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:606:in `set_dataset'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/model/base.rb:869:in `inherited'
/home/zw963/Stocks/marketbet_crawler/app/models/insider.rb:1:in `<top (required)>'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:27:in `require'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:27:in `require'
/home/zw963/Stocks/marketbet_crawler/lib/tasks/update_db.rake:13:in `block (3 levels) in <top (required)>'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:113:in `block (2 levels) in fetch_rows'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:113:in `yield_each_row'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:113:in `block in fetch_rows'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:146:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:500:in `_execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:47:in `_execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:318:in `block (2 levels) in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:522:in `check_database_errors'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:318:in `block in execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/connection_pool/threaded.rb:92:in `hold'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/database/connecting.rb:269:in `synchronize'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/adapters/postgres.rb:318:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel-5.50.0/lib/sequel/dataset/actions.rb:1093:in `execute'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel/extensions/pg_streaming.rb:112:in `fetch_rows'
/home/zw963/others/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/sequel_pg-1.14.0/lib/sequel_pg/sequel_pg.rb:79:in `each'
/home/zw963/Stocks/marketbet_crawler/lib/tasks/update_db.rake:12:in `block (2 levels) in <top (required)>'
/home/zw963/others/.rvm/gems/ruby-3.0.2@global/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/zw963/.rvm/gems/ruby-3.0.2@global/bin/ruby_executable_hooks:22:in `eval'
/home/zw963/.rvm/gems/ruby-3.0.2@global/bin/ruby_executable_hooks:22:in `<main>

And, i try invoke stream directly instead. (with comment DB.stream_all_queries = true out),like this:

  task :update_insider_history_insider_id do
    require_relative '../../config/environment'
    InsiderHistory.dataset.stream.each do |ih|
      puts '*'*100
      pp ih
      puts '*'*100
      insider = Insider.find_or_create(name: ih.name)
      ih.update(insider_id: insider.id)
    end
  end

It still not work, only first records get updated.

RACK_ENV=development
DB connected: postgres://postgres:postgres@localhost:5432/marketbet_crawler_development
I, [2021-11-09T20:12:43.467444 #1167811]  INFO -- : (0.000305s) SET standard_conforming_strings = ON
I, [2021-11-09T20:12:43.467778 #1167811]  INFO -- : (0.000208s) SET client_min_messages = 'WARNING'
I, [2021-11-09T20:12:43.468024 #1167811]  INFO -- : (0.000166s) SET DateStyle = 'ISO'
I, [2021-11-09T20:12:43.469202 #1167811]  INFO -- : (0.000372s) SELECT CAST(current_setting('server_version_num') AS integer) AS v
I, [2021-11-09T20:12:43.472419 #1167811]  INFO -- : (0.002543s) SELECT "pg_attribute"."attname" AS "name", CAST("pg_attribute"."atttypid" AS integer) AS "oid", CAST("basetype"."oid" AS integer) AS "base_oid", format_type("basetype"."oid", "pg_type"."typtypmod") AS "db_base_type", format_type("pg_type"."oid", "pg_attribute"."atttypmod") AS "db_type", pg_get_expr("pg_attrdef"."adbin", "pg_class"."oid") AS "default", NOT "pg_attribute"."attnotnull" AS "allow_null", COALESCE(("pg_attribute"."attnum" = ANY("pg_index"."indkey")), false) AS "primary_key", "pg_attribute"."attidentity", ("pg_attribute"."attgenerated" != '') AS "generated" FROM "pg_class" INNER JOIN "pg_attribute" ON ("pg_attribute"."attrelid" = "pg_class"."oid") INNER JOIN "pg_type" ON ("pg_type"."oid" = "pg_attribute"."atttypid") LEFT OUTER JOIN "pg_type" AS "basetype" ON ("basetype"."oid" = "pg_type"."typbasetype") LEFT OUTER JOIN "pg_attrdef" ON (("pg_attrdef"."adrelid" = "pg_class"."oid") AND ("pg_attrdef"."adnum" = "pg_attribute"."attnum")) LEFT OUTER JOIN "pg_index" ON (("pg_index"."indrelid" = "pg_class"."oid") AND ("pg_index"."indisprimary" IS TRUE)) WHERE (("pg_attribute"."attisdropped" IS FALSE) AND ("pg_attribute"."attnum" > 0) AND ("pg_class"."oid" = CAST(CAST('"insider_histories"' AS regclass) AS oid))) ORDER BY "pg_attribute"."attnum"
I, [2021-11-09T20:12:43.474305 #1167811]  INFO -- : (0.000042s) SELECT * FROM "insider_histories"
****************************************************************************************************
#<InsiderHistory @values={:id=>6, :date=>#<Date: 2020-10-19 ((2459142j,0s,0n),+0s,2299161j)>, :name=>"Lucas D Creasy", :title=>"CTO", :number_of_holding=>0, :number_of_shares=>19191, :average_price=>0.22e2, :share_total_price=>0.422202e6, :created_at=>2021-05-25 23:25:46.53774 +0800, :stock_id=>1, :insider_id=>nil}>
****************************************************************************************************
I, [2021-11-09T20:12:43.479718 #1167811]  INFO -- : (0.002737s) SELECT "pg_attribute"."attname" AS "name", CAST("pg_attribute"."atttypid" AS integer) AS "oid", CAST("basetype"."oid" AS integer) AS "base_oid", format_type("basetype"."oid", "pg_type"."typtypmod") AS "db_base_type", format_type("pg_type"."oid", "pg_attribute"."atttypmod") AS "db_type", pg_get_expr("pg_attrdef"."adbin", "pg_class"."oid") AS "default", NOT "pg_attribute"."attnotnull" AS "allow_null", COALESCE(("pg_attribute"."attnum" = ANY("pg_index"."indkey")), false) AS "primary_key", "pg_attribute"."attidentity", ("pg_attribute"."attgenerated" != '') AS "generated" FROM "pg_class" INNER JOIN "pg_attribute" ON ("pg_attribute"."attrelid" = "pg_class"."oid") INNER JOIN "pg_type" ON ("pg_type"."oid" = "pg_attribute"."atttypid") LEFT OUTER JOIN "pg_type" AS "basetype" ON ("basetype"."oid" = "pg_type"."typbasetype") LEFT OUTER JOIN "pg_attrdef" ON (("pg_attrdef"."adrelid" = "pg_class"."oid") AND ("pg_attrdef"."adnum" = "pg_attribute"."attnum")) LEFT OUTER JOIN "pg_index" ON (("pg_index"."indrelid" = "pg_class"."oid") AND ("pg_index"."indisprimary" IS TRUE)) WHERE (("pg_attribute"."attisdropped" IS FALSE) AND ("pg_attribute"."attnum" > 0) AND ("pg_class"."oid" = CAST(CAST('"insiders"' AS regclass) AS oid))) ORDER BY "pg_attribute"."attnum"
I, [2021-11-09T20:12:43.481129 #1167811]  INFO -- : (0.000408s) SELECT * FROM "insiders" WHERE ("name" = 'Lucas D Creasy') LIMIT 1
I, [2021-11-09T20:12:43.481614 #1167811]  INFO -- : (0.000143s) BEGIN
I, [2021-11-09T20:12:43.482143 #1167811]  INFO -- : (0.000322s) INSERT INTO "insiders" ("name") VALUES ('Lucas D Creasy') RETURNING *
I, [2021-11-09T20:12:43.483361 #1167811]  INFO -- : (0.001132s) COMMIT
I, [2021-11-09T20:12:43.483747 #1167811]  INFO -- : (0.000105s) BEGIN
I, [2021-11-09T20:12:43.484450 #1167811]  INFO -- : (0.000486s) UPDATE "insider_histories" SET "insider_id" = 5 WHERE ("id" = 6)
I, [2021-11-09T20:12:43.485495 #1167811]  INFO -- : (0.000974s) COMMIT

This issue may similar with #38, but i use postgres on Arch linux locally.

 ╰─ $ pacman -Qi postgresql
Name            : postgresql
Version         : 13.4-1
Description     : Sophisticated object-relational DBMS
Architecture    : x86_64
URL             : https://www.postgresql.org/
Licenses        : custom:PostgreSQL
Groups          : None
Provides        : None
Depends On      : postgresql-libs>=13.4  krb5  libxml2  readline>=6.0  openssl>=1.0.0  pam  icu  systemd-libs  libldap  llvm-libs  libxslt
Optional Deps   : python2: for PL/Python 2 support [installed]
                  python: for PL/Python 3 support [installed]
                  perl: for PL/Perl support [installed]
                  tcl: for PL/Tcl support [installed]
                  postgresql-old-upgrade: upgrade from previous major version using pg_upgrade
                  logrotate: rotates system logs automatically
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 53.18 MiB
Packager        : Levente Polyak <[email protected]>
Build Date      : Thu 09 Sep 2021 02:07:50 AM CST
Install Date    : Thu 21 Oct 2021 08:57:41 PM CST
Install Reason  : Explicitly installed
Install Script  : Yes
Validated By    : Signature

hstore: quote escaping bug

Hi Jeremy,

I believe I've found a SQL injection bug when storing data containing quotes, when that data is stored with hstore. Given the hash:

h = { "value" => "foo\"bar\"" }

storing this in hstore via will produce an SQL injection bug:

dataset.insert(:data => h.hstore)

I haven't tried to reproduce this exact case as such but I have a very similar issue and the code paths are quite simple, so I'm reasonably sure this is what's happening, but let me know if you cannot confirm and I should dig in further.

Thanks!

Query in a stream block: undefined method `check' for nil:NilClass

Do a query inside a stream block against the same db. This is just a stupid example, but will trigger the error: DB[:plans].stream.each { |r| p DB[:plans][name: r[:name]] }

NoMethodError: undefined method `check' for nil:NilClass
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel_pg-1.6.14/lib/sequel/extensions/pg_streaming.rb:99:in `yield_each_row'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel_pg-1.6.14/lib/sequel/extensions/pg_streaming.rb:99:in `block in fetch_rows'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/postgres.rb:175:in `execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/postgres.rb:525:in `_execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel_pg-1.6.14/lib/sequel/extensions/pg_streaming.rb:47:in `_execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/postgres.rb:341:in `block (2 levels) in execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/postgres.rb:546:in `check_database_errors'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/postgres.rb:341:in `block in execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/database/connecting.rb:251:in `block in synchronize'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:105:in `hold'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/database/connecting.rb:251:in `synchronize'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/postgres.rb:341:in `execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/dataset/actions.rb:952:in `execute'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel_pg-1.6.14/lib/sequel/extensions/pg_streaming.rb:98:in `fetch_rows'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/dataset/actions.rb:141:in `each'
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel_pg-1.6.14/lib/sequel_pg/sequel_pg.rb:58:in `each'
        from (irb):7
        from /Users/carl/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/bin/sequel:252:in `<top (required)>'
        from /Users/carl/.rbenv/versions/2.3.0/bin/sequel:23:in `load'
        from /Users/carl/.rbenv/versions/2.3.0/bin/sequel:23:in `<main>'

sequel_pg is incompatible to pg-1.2.0

This was originally raised at ruby-pg: ged/ruby-pg#318

sequel_pg retrieves the connection encoding from the result T_DATA object here.
However the storage of the encoding information has changed in ruby-pg-1.2.0 due to ged/ruby-pg#280 . As a result sequel_pg marks all strings as ASCII-8BIT.

I can imagine the following ways to solve this:

  1. Redefine struct t_pg_result in sequel_pg to get access to enc_idx
  2. Add an export function to pg-1.2.1 kind of pg_get_connection_enc_idx()
  3. Use PG::Connection.internal_encoding to retrieve the encoding
  4. Set string encoding fixed to UTF-8
  5. Make use of pg's builtin streaming and typecast work making sequel_pg obsolete

No stream in Sequel 5

DB.extension :pg_streaming
Sequel::Postgres.supports_streaming? => true
yet
NoMethodError: undefined method stream' for #Sequel::Postgres::Dataset:0x007f7ff41fc388`

ruby 2.4.1
sequel 5.0.0
sequel_pg 1.7.1
pg 0.21.0
postgresql 9.6.3

Possible memory leak when upgrading pg_sequel to 1.15.0

We have sidekiq job which fetches data from postgres and generates some xml reports via streaming. Under normal circumstances it consumes about 300 MB RAM, but after upgrading pg_sequel gem from 1.14.0 to 1.15.0 it started to consume about 7GB.

We've double checked this job in isolation downgrading gem to 1.14.0 and the memory usage was fine. We don't use #paged_each so the change in default settings shouldn't be the issue.

ruby - 3.0.2
pg - 1.4.1

Could there be any memory leaks in 1.15.0?

Support for jruby?

Hello, I'm using jruby and when I try to install sequel_pg it wants to install pg, but for jruby people use jruby-pg. Any chance of supporting that?

Streaming support with activerecord_connection

Hi,

Using https://github.com/janko/sequel-activerecord_connection to reuse ActiveRecord existing pgsql connections:

  db = Sequel.postgres(extensions: [:activerecord_connection, :pg_streaming])
  db[:whatever]
    .stream.each do |entry|
      puts entry
    end

I get the following errors:

NoMethodError: undefined method single_row_mode=' for #<PG::Connection:0x000000010d8c6aa0 @db=#<Sequel::Postgres::Database: {:adapter=>:postgres, :extensions=>[:activerecord_connection, :pg_streaming]}>, @prepared_statements={}>`

Is there any way I can make both work together? Thanks!

Streaming doesn't work with RDS db

We're trying to iterate over a very large table (1M+ rows) for a big data migration. The plan was to use streaming to reduce memory usage and make it faster.

We have the data stored in an RDS Postgres 12.2 database.

Sequel::Postgres.supports_streaming? returns true

Our code is something like this:

Sequel.connect('postgres://postgres:xxxxxxxxxx:5432/postgres?search_path=x') do |db|
  db.extension(:pg_streaming)
  db[:table].stream.each do |row|
    ...
  end
end

But it waits for about 30 seconds, and returns:

PG::Error: cannot set single row mode

Maybe there's some timeout or something happening? Or maybe I misunderstood how this feature works.

Interestingly if we change the code to:

Sequel.connect('postgres://postgres:xxxxxxxxxx:5432/postgres?search_path=x') do |db|
  db.extension(:pg_streaming)
  db.stream_all_queries = true
  db[:table].first
end

It raises in exception on the db[:table].first line with:

PG::UnableToSend: another command is already in progress

The following code:

Sequel.connect('postgres://postgres:xxxxxxxxxx:5432/postgres?search_path=x') do |db|
  db.extension(:pg_streaming)
  db[:table].first
end

Works correctly and db[:table].first returns the first row in the database.

We are using:

  • sequel (5.32.0)
  • sequel_pg (1.13.0)
  • pg (1.2.3)

Issue with timestamps

I just came across an issue with timestamps.
I have a table exported from a rails project where I needed to analyse some data with sequel, the Timestamps of the table look like this:

 routing_start_date     | timestamp without time zone    |           |          |
 routing_end_date       | timestamp without time zone    |           |          |
 created_at             | timestamp(6) without time zone |           | not null |
 updated_at             | timestamp(6) without time zone |           | not null |

As it seems the timestamp without time zone cause an issue with sequel_pg

my ruby code looks like this:

    DB = Sequel.connect(ENV.fetch("DATABASE_URL"))
    class HeadNumber < Sequel::Model(:head_numbers)
    end

Something like HeadNumber.count works, but as soon as I want to see some data HeadNumber.first I get an error

ArgumentError (unexpected timetamp format, too short)

https://github.com/jeremyevans/sequel_pg/blob/master/ext/sequel_pg/sequel_pg.c#L535

Thanks for the typo, I probably wouldn't have found it without it.
So it seems like it doesn't like my timestamps, not sure if the timestamp(6) without time zone or timestamp without time zone create the issue, I dropped both and after that it started working.
I will reimport the DB dump when I'm done to verify which timestamp causes the issue.

Or even better, I will create some test data in a mini project with sql for import to reproduce this issue.

undefined symbol: pgresult_get

For some reason I'm running into undefined symbol: pgresult_get when trying to load sequel_pg. Do you have any thoughts as to why that may be?

% cat Gemfile
source 'http://rubygems.org'
gem 'sequel_pg'

% bundle install --path vendor/bundle
Fetching gem metadata from http://rubygems.org/..............
Using bundler 1.16.1
Fetching pg 1.1.3
Installing pg 1.1.3 with native extensions
Fetching sequel 5.14.0
Installing sequel 5.14.0
Fetching sequel_pg 1.11.0
Installing sequel_pg 1.11.0 with native extensions
Bundle complete! 1 Gemfile dependency, 4 gems now installed.
Bundled gems are installed into `./vendor/bundle`

% bundle console
Traceback (most recent call last):
        19: from /bin/bundle:23:in `<main>'
        18: from /bin/bundle:23:in `load'
        17: from /usr/share/gems/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
        16: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
        15: from /usr/share/gems/gems/bundler-1.16.1/exe/bundle:30:in `block in <top (required)>'
        14: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/cli.rb:18:in `start'
        13: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
        12: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/cli.rb:27:in `dispatch'
        11: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
        10: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
         9: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
         8: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/cli.rb:455:in `console'
         7: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/cli/console.rb:15:in `run'
         6: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
         5: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
         4: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
         3: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
         2: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
         1: from /usr/share/gems/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
/usr/share/gems/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require': /home/feuerbach/tst/sequel-pg/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/sequel_pg-1.11.0/sequel_pg.so: undefined symbol: pgresult_get - /home/feuerbach/tst/sequel-pg/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/sequel_pg-1.11.0/sequel_pg.so (LoadError)

% ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

% lsb_release -d
Description:    Fedora release 29 (Twenty Nine)

undefined method `check' for nil:NilClass (NoMethodError)

Hey Jeremy (and everyone),

I'm trying to use your delightful gem as I prefer not to load 52 Million records into memory, but I get the following error:

/Users/nambrot/.rvm/gems/ruby-2.1.1/gems/sequel_pg-1.6.10/lib/sequel/extensions/pg_streaming.rb:100:inyield_each_row': undefined method check' for nil:NilClass (NoMethodError)

The offending method is:
DB[:datas].limit(10).stream.each {|commit| update_location commit }

If I leave out stream, it runs fine. I tried to go through the source, unfruitful unfortunately :(

new versions require pg_inet semantics globally

I was testing upgrading gems and narrowed down that sequel_pg upgrades break my application, as they opt me into the IPAddr type for Ruby, something I did not have set before.

The Ruby IPAddr type is cumbersome as comes to CIDR expressions: it make rendering them in the usual, uh, CIDR notation rather difficult, and packages that are far more useful like NetAddr don't take them apart very well.

Not sure what the right resolution is. Surely I can make this work, but it may not have been anticipated.

each_slice with streaming

Hi there,

I've a question, is each_slice supposed to work with streaming enabled?

I've some like:

DB[query].stream.each_slice(1_000_000) do |group|
   values = group.map  do |row|
      compute_some_with(row)
   end
   DB[:my_table].multi_insert(values)
end

Right now I get the following exception:

undefined method `check' for nil:NilClass
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel_pg-1.6.5/lib/sequel/extensions/pg_streaming.rb:99:in `yield_each_row'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel_pg-1.6.5/lib/sequel/extensions/pg_streaming.rb:99:in `block in fetch_rows'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/adapters/postgres.rb:138:in `execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/adapters/postgres.rb:434:in `_execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel_pg-1.6.5/lib/sequel/extensions/pg_streaming.rb:47:in `_execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/adapters/postgres.rb:262:in `block (2 levels) in execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/adapters/postgres.rb:446:in `check_database_errors'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/adapters/postgres.rb:262:in `block in execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/database/connecting.rb:236:in `block in synchronize'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/connection_pool/threaded.rb:104:in `hold'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/database/connecting.rb:236:in `synchronize'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/adapters/postgres.rb:262:in `execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/dataset/actions.rb:861:in `execute'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel_pg-1.6.5/lib/sequel/extensions/pg_streaming.rb:98:in `fetch_rows'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel-3.46.0/lib/sequel/dataset/actions.rb:154:in `each'
/Users/DAddYE/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sequel_pg-1.6.5/lib/sequel_pg/sequel_pg.rb:58:in `each'

Adapter load order issues

Since sequel dynamically loads the adapter on connect, bundling sequel_pg raises a NameError for Sequel::Postgres. Requiring it manually after a Sequel.connect works, though.

This doesn't work.

require 'bundler'
Bundler.require # pulls in sequel, sequel_pg

Sequel::Model.db = Sequel.connect ENV['DATABASE_URL']

This does.

require 'sequel'
Sequel::Model.db = Sequel.connect ENV['DATABASE_URL']
require 'sequel_pg'

How about either adding to the readme or having this gem require the sequel postgres adapter?

Change default max_columns to 1600

1600 is the actual postgres limit, and with the current default of 256 people may run into problems which then forces them to do things to change the default (as described in the readme). If we change the default to 1600, then no one will run into the column limit problem, while those who have reason to have a smaller number (performance or something?) can do the work of adjusting the limit.

README RbConfig::Config -> CONFIG

The README file refers to RbConfig::Config towards the end (particularly RbConfig::Config['LDFLAGS']) when in actuality the name of the constant is RbConfig::CONFIG.

$ ruby -e 'p RbConfig::Config["LDFLAGS"]'
-e:1:in `<main>': uninitialized constant RbConfig::Config (NameError)
$ ruby -e 'p RbConfig::CONFIG["LDFLAGS"]'
"-L. -Wl,-O1 -Wl,--as-needed -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,--no-undefined"

Linking fails on macOS 13

Apparently it can't find the pg symbols when linking. Any ideas?

$ ruby -v
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [arm64-darwin22]


$ gem install sequel_pg
Building native extensions. This could take a while...
ERROR:  Error installing sequel_pg:
	ERROR: Failed to build gem native extension.

    current directory: /Users/szengel/.rvm/gems/ruby-3.0.4/gems/sequel_pg-1.15.0/ext/sequel_pg
/Users/szengel/.rvm/rubies/ruby-3.0.4/bin/ruby -I /Users/szengel/.rvm/rubies/ruby-3.0.4/lib/ruby/3.0.0 -r ./siteconf20220810-70773-vff1zg.rb extconf.rb
checking for -lpq... yes
checking for libpq-fe.h... yes
checking for PQsetSingleRowMode()... yes
checking for timegm()... yes
creating Makefile

current directory: /Users/szengel/.rvm/gems/ruby-3.0.4/gems/sequel_pg-1.15.0/ext/sequel_pg
make DESTDIR\= clean

current directory: /Users/szengel/.rvm/gems/ruby-3.0.4/gems/sequel_pg-1.15.0/ext/sequel_pg
make DESTDIR\=
compiling sequel_pg.c
sequel_pg.c:27:9: warning: 'ntohll' macro redefined [-Wmacro-redefined]
#define ntohll(c) ((uint64_t)( \
        ^
/Applications/Xcode14b5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_endian.h:140:9: note: previous definition is here
#define ntohll(x)       __DARWIN_OSSwapInt64(x)
        ^
1 warning generated.
linking shared-object sequel_pg.bundle
Undefined symbols for architecture arm64:
  "_pg_get_pgconn", referenced from:
      _spg_set_single_row_mode in sequel_pg.o
      _spg__flush_results in sequel_pg.o
  "_pg_get_result_enc_idx", referenced from:
      _spg_yield_hash_rows in sequel_pg.o
      _spg__yield_each_row in sequel_pg.o
  "_pgresult_get", referenced from:
      _spg_yield_hash_rows in sequel_pg.o
      _spg__yield_each_row in sequel_pg.o
      _spg__yield_each_row_internal in sequel_pg.o
      _spg__yield_each_row_stream in sequel_pg.o
  "_pgresult_stream_any", referenced from:
      _spg__yield_each_row_internal in sequel_pg.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sequel_pg.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/szengel/.rvm/gems/ruby-3.0.4/gems/sequel_pg-1.15.0 for inspection.
Results logged to /Users/szengel/.rvm/gems/ruby-3.0.4/extensions/arm64-darwin-22/3.0.0/sequel_pg-1.15.0/gem_make.out

Segfault with 1.6.11 when errors are swallowed

Had a bug that we're fixing in newrelic_rpm where out Sequel extension would swallow errors it shouldn't from within log_yield.

This was plainly a problem in our code, but on sequel_pg 1.6.11 it resulted in a segfault which doesn't seem good either. 1.6.10 has errors from the bad behavior here, but not segfaults.

I've made as minimal a repro case as I could at https://github.com/jasonrclark/sequel_pg-eat_errors_repro in case you're interested. We should have a new agent out today with the patch that addresses the bug on our side.

cc @tkrajcar @ollie

disable native IPAddr for cidr ranges

Hey Jeremy,

i really appreciate the effort you are putting into Sequel and sequel-pg.
We are currently upgrading sequel-pg and running into a couple of problems with parsing of cidr fields into IPAddr objects.

IPAddr is not made for CIDR blocks. It can store the prefix but if you try to use it with a CIDR Block it quickly falls apart.

  1. Issue
    Calling .to_s swallows the prefix. example: IPAddr.new("98.51.100.0/23").to_s returns "98.51.100.0" which is not the same.

  2. Issue
    Comparing IPAddr works unexpected with CIDR blocks.

$ ip1 = IPAddr.new("98.51.100.0/24")
$ ip2= IPAddr.new("98.51.100.0/23")
ip1==ip2
=> true

those are not the same CIDR blocks.

Is there a way to disable the native IPAddr conversion? We find ourselves in a place where we have to undo the conversions in our Sequel Models with getters by converting them back to strings to avoid any kind of issues. We tried to work with IPAddr internally but it has too many edge cases which are unexpected with IPAddr

We are using the NetAddr gem (https://github.com/dspinhirne/netaddr-rb). Is there a way to tell sequel-pg to return a NetAddr object instead of a IPAddr object? We really like the idea of supporting many native types. Our application is very deep in the networking domain and has to deal with a lot of Ipaddress, subnets etc.

thank you for all your efforts any input is greatly appreciated

Failed to build gem native extension (Mac OS Ventura) x86_64-darwin-22

👋

I'm trying to install sequel (5.62.0) and sequel_pg (1.17.0) on Ruby 3.1.2 with bundler (2.3.11) on Mac OS Ventura (13) with Intel Chips (x86_64) and with PostgreSQL 11 and I've got this error:

current directory:
/Users/faber/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sequel_pg-1.17.0/ext/sequel_pg
/Users/faber/.rbenv/versions/3.1.2/bin/ruby -I /Users/faber/.rbenv/versions/3.1.2/lib/ruby/3.1.0 -r
./siteconf20221108-49950-ho3wst.rb extconf.rb
checking for -lpq... yes
checking for libpq-fe.h... yes
checking for PQsetSingleRowMode()... yes
checking for timegm()... yes
creating Makefile

current directory: /Users/faber/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sequel_pg-1.17.0/ext/sequel_pg
make DESTDIR\= clean

current directory: /Users/faber/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sequel_pg-1.17.0/ext/sequel_pg
make DESTDIR\=
compiling sequel_pg.c
sequel_pg.c:27:9: warning: 'ntohll' macro redefined [-Wmacro-redefined]
#define ntohll(c) ((uint64_t)( \
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_endian.h:140:9: note: previous definition
is here
#define ntohll(x)       __DARWIN_OSSwapInt64(x)
        ^
1 warning generated.
linking shared-object sequel_pg.bundle
Undefined symbols for architecture x86_64:
  "_pg_get_pgconn", referenced from:
      _spg_set_single_row_mode in sequel_pg.o
      _spg__flush_results in sequel_pg.o
  "_pg_get_result_enc_idx", referenced from:
      _spg_yield_hash_rows in sequel_pg.o
      _spg__yield_each_row in sequel_pg.o
  "_pgresult_get", referenced from:
      _spg_yield_hash_rows in sequel_pg.o
      _spg__yield_each_row in sequel_pg.o
      _spg__yield_each_row_internal in sequel_pg.o
      _spg__yield_each_row_stream in sequel_pg.o
  "_pgresult_stream_any", referenced from:
      _spg__yield_each_row_internal in sequel_pg.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sequel_pg.bundle] Error 1

make failed, exit code 2

I've already reinstalled xcode-select --install and did a rbenv uninstall 3.1.2 rbenv install 3.1.2 to start over with a clean ruby installation, but this did not work.

 ↳ $ xcode-select --version
xcode-select version 2396.

Any advice? 🙏

Note: It was working on Mac OS Monterey (12). It happened after I've upgraded 😬

Trouble installing on ubuntu 12.10

I am trying to install sequel_pg on an ubuntu 12.10 server and I'm getting the following error

$ sudo gem install sequel_pg -v '1.6.5'
Building native extensions.  This could take a while...
ERROR:  Error installing sequel_pg:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
checking for main() in -lpq... yes
checking for libpq-fe.h... yes
checking for PQsetSingleRowMode()... yes
creating Makefile

make
compiling sequel_pg.c
sequel_pg.c: In function ‘spg_timestamp_error’:
sequel_pg.c:279:3: error: format not a string literal and no format arguments [-Werror=format-security]
sequel_pg.c: In function ‘spg__yield_each_row’:
sequel_pg.c:855:11: warning: variable ‘conn’ set but not used [-Wunused-but-set-variable]
cc1: some warnings being treated as errors
make: *** [sequel_pg.o] Error 1


Gem files will remain installed in /var/lib/gems/1.9.1/gems/sequel_pg-1.6.5 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/sequel_pg-1.6.5/ext/sequel_pg/gem_make.out

I have postgres 9.2 installed from ppa:pitti/postgresql

Any ideas on what may be causing this? Is there more info I can provide that will help tracking this down?

Installation trouble - failed to build the native extension

With Postgres 9.4 and the pg-0.18.1 gem installed sequel_pg fails to compile it's native extension. Whetther allowing the extconfig run pg_config or by manually setting the env vars, the complile fails diuring the link phase:

POSTGRES_LIB=/usr/lib64/postgresql-9.4/lib64/ POSTGRES_INCLUDE=/usr/include/postgresql-9.4/ gem install sequel_pg
Building native extensions.  This could take a while...
ERROR:  Error installing sequel_pg:
        ERROR: Failed to build gem native extension.

    /usr/bin/ruby19 extconf.rb
checking for main() in -lpq... yes
checking for libpq-fe.h... yes
checking for PQsetSingleRowMode()... yes
creating Makefile

make  clean

make
compiling sequel_pg.c
sequel_pg.c: In function ‘spg__yield_each_row’:
sequel_pg.c:873:11: warning: variable ‘conn’ set but not used [-Wunused-but-set-variable]
   PGconn *conn;
           ^
linking shared-object sequel_pg.so
sequel_pg.o: In function `spg__flush_results':
sequel_pg.c:(.text+0x338): undefined reference to `pg_get_pgconn'
sequel_pg.o: In function `spg_set_single_row_mode':
sequel_pg.c:(.text+0x188f): undefined reference to `pg_get_pgconn'
sequel_pg.o: In function `spg__yield_each_row':
sequel_pg.c:(.text+0x1a04): undefined reference to `pg_get_pgconn'
sequel_pg.c:(.text+0x1a49): undefined reference to `pgresult_get'
sequel_pg.c:(.text+0x1bb7): undefined reference to `pgresult_get'
sequel_pg.o: In function `spg_yield_hash_rows':
sequel_pg.c:(.text+0x1da4): undefined reference to `pgresult_get'
collect2: error: ld returned 1 exit status
Makefile:214: recipe for target 'sequel_pg.so' failed
make: *** [sequel_pg.so] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/lib64/ruby/gems/1.9.1/gems/sequel_pg-1.6.11 for inspection.
Results logged to /usr/local/lib64/ruby/gems/1.9.1/extensions/x86_64-linux/1.9.1/sequel_pg-1.6.11/gem_make.out 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.