Skip to content

Commit

Permalink
Add a Date decoder to the pg adapter to type cast dates
Browse files Browse the repository at this point in the history
at the connection level

Fix rails#51448

Type cast columns of type `date` to ruby `Date` when running a raw
query through `ActiveRecord::Base.connection.select_all`.
  • Loading branch information
JoeDupuis committed Apr 4, 2024
1 parent 3d418c0 commit 92f7d37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,14 @@
* `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.

Ex:
```ruby
ActiveRecord::Base.connection
.select_value("select '2024-01-01'::date").class #=> Date
```

*Joé Dupuis*


* `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transation` object.

This allows to register callbacks on it.
Expand Down
Expand Up @@ -1159,6 +1159,7 @@ def add_pg_decoders
"bool" => PG::TextDecoder::Boolean,
"timestamp" => PG::TextDecoder::TimestampUtc,
"timestamptz" => PG::TextDecoder::TimestampWithTimeZone,
"date" => PG::TextDecoder::Date,
}

known_coder_types = coders_by_name.keys.map { |n| quote(n) }
Expand Down

0 comments on commit 92f7d37

Please sign in to comment.