Module: Sequel::Postgres

Defined in:
lib/sequel/lib/sequel/adapters/shared/postgres.rb,
lib/sequel/lib/sequel/adapters/postgres.rb

Overview

Top level module for holding all PostgreSQL-related modules and classes for Sequel. There are a few module level accessors that are added via metaprogramming. These are:

  • client_min_messages (only available when using the native adapter) - Change the minimum level of messages that PostgreSQL will send to the the client. The PostgreSQL default is NOTICE, the Sequel default is WARNING. Set to nil to not change the server default.

  • force_standard_strings - Set to false to not force the use of standard strings

  • use_iso_date_format (only available when using the native adapter) - Set to false to not change the date format to ISO. This disables one of Sequel's optimizations.

Changes in these settings only affect future connections. To make sure that they are applied, they should generally be called right after the Database object is instantiated and before a connection is actually made. For example, to use whatever the server defaults are:

DB = Sequel.postgres(...)
Sequel::Postgres.client_min_messages = nil
Sequel::Postgres.force_standard_strings = false
Sequel::Postgres.use_iso_date_format = false
# A connection to the server is not made until here
DB[:t].all

The reason they can't be done earlier is that the Sequel::Postgres module is not loaded until a Database object which uses PostgreSQL is created.

Defined Under Namespace

Modules: AdapterMethods, DatabaseMethods, DatasetMethods Classes: Adapter, Database, Dataset

Constant Summary collapse

PG_TYPES =

Hash with integer keys and proc values for converting PostgreSQL types.

{}
PG_TYPE_PROCS =

Use a single proc for each type to conserve memory

{
  [16] =>  lambda{|s| s == 't'}, # boolean
  [17] => lambda{|s| ::Sequel::SQL::Blob.new(Adapter.unescape_bytea(s))}, # bytea
  [20, 21, 22, 23, 26] => lambda{|s| s.to_i}, # integer
  [700, 701] => lambda{|s| s.to_f}, # float
  [790, 1700] => lambda{|s| BigDecimal.new(s)}, # numeric
  [1082] => lambda{|s| @use_iso_date_format ? Date.new(*s.split("-").map{|x| x.to_i}) : Sequel.string_to_date(s)}, # date
  [1083, 1266] => lambda{|s| Sequel.string_to_time(s)}, # time
  [1114, 1184] => lambda{|s| Sequel.database_to_application_timestamp(s)}, # timestamp
}
CONVERTED_EXCEPTIONS =

Array of exceptions that need to be converted. JDBC uses NativeExceptions, the native adapter uses PGError.

[]

Class Attribute Summary collapse

Class Attribute Details

.client_min_messagesObject

By default, Sequel sets the minimum level of log messages sent to the client to WARNING, where PostgreSQL uses a default of NOTICE. This is to avoid a lot of mostly useless messages when running migrations, such as a couple of lines for every serial primary key field.


43
44
45
# File 'lib/sequel/lib/sequel/adapters/shared/postgres.rb', line 43

def client_min_messages
  @client_min_messages
end

.force_standard_stringsObject

By default, Sequel forces the use of standard strings, so that '\' is interpreted as \ and not . While PostgreSQL defaults to interpreting plain strings as extended strings, this will change in a future version of PostgreSQL. Sequel assumes that SQL standard strings will be used.


50
51
52
# File 'lib/sequel/lib/sequel/adapters/shared/postgres.rb', line 50

def force_standard_strings
  @force_standard_strings
end

.use_iso_date_formatObject

As an optimization, Sequel sets the date style to ISO, so that PostgreSQL provides the date in a known format that Sequel can parse faster. This can be turned off if you require a date style other than ISO.


114
115
116
# File 'lib/sequel/lib/sequel/adapters/postgres.rb', line 114

def use_iso_date_format
  @use_iso_date_format
end