aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* Correctly handle limit on int4 and int8 types in PGSean Griffin2014-12-221-2/+2
| | | | | | | | | | | | | | | | PG doesn't register it's types using the `int(4)` format that others do. As such, if we alias `int8` to the other integer types, the range information is lost. This is fixed by simply registering it separately. The other option (which I specifically chose to avoid) is to pass the information of the original type that was being aliased as an argument. I'd rather avoid that, since an alias should truly be treated the same. If we need different behavior for a different type, we should explicitly register it with that, and not have a conditional based on aliasing. Fixes #18144 [Sean Griffin & ysbaddaden]
* Correctly respect subtypes for PG arrays and rangesSean Griffin2014-12-051-3/+6
| | | | | | | | | | | | | The type registration was simply looking for the OID, and eagerly fetching/constructing the sub type when it was registered. However, numeric types have additional parameters which are extracted from the actual SQL string of the type during lookup, and can have their behavior change based on the result. We simply need to use the block form of registration, and look up the subtype lazily instead. Fixes #17935
* no need to pass native_database_types aroundYves Senn2014-12-021-1/+1
|
* Fix value extracted from negative integers for PostgreSQL.Guo Xiang Tan2014-12-011-1/+1
| | | | Fixes: https://github.com/rails/rails/issues/17856.
* Wrap code snippets in +, not backticks, in sdocclaudiob2014-11-201-2/+2
| | | | | | | | I grepped the source code for code snippets wrapped in backticks in the comments and replaced the backticks with plus signs so they are correctly displayed in the Rails documentation. [ci skip]
* Revert "PERF: optimise type lookup to avoid invoking procs"Sean Griffin2014-11-191-13/+7
| | | | This reverts commit da99a2a2982d35f670ad9647463e09bfe9032b70.
* PERF: optimise type lookup to avoid invoking procsSam2014-11-171-7/+13
|
* exec_prepared is GVL friendly, so lets use it.Aaron Patterson2014-11-131-4/+2
| | | | | also increase the version of pg required so that people will get the GVL friendly version
* Added SchemaDumper support for tables with jsonb columns.Ted O'Meara2014-11-041-0/+1
|
* Correctly cast calculation results on PGSean Griffin2014-11-011-0/+10
| | | | | MySQL reports the column name as `"MAX(developer_id)"`. PG will report it as `"max"`
* Remove redundant `to_s` in interpolationclaudiob2014-10-301-2/+2
|
* add bigserial pk supportAaron Patterson2014-10-291-0/+1
|
* Remove duplicate 'select' database statementclaudiob2014-10-201-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `select` method has the same definition in almost all database adapters, so it can be moved from the database-specific adapters (PostgreSQl, MySQL, SQLite) to the abstract `database_statement`: ```ruby def select(sql, name = nil, binds = []) exec_query(sql, name, binds) end ``` --- More details about this commit: the only two DB-specific adapters that have a different definition of `select` are MySQLAdapter and MySQL2Adapter. In MySQLAdapter, `select` invokes `exec_query(sql, name, binds)`, so calling `super` achieves the same goal with less repetition. In MySQL2Adapter, `select` invokes `exec_query(sql, name)`, that is, it does not pass the `binds` parameter like other methods do. However, [MySQL2Adapter's `exec_query`](https://github.com/rails/rails/blob/74a527cc63ef56f3d0a42cf638299958dc7cb08c/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb#L228L231) works exactly the same whether this parameters is passed or not, so the output does not change: ```ruby def exec_query(sql, name = 'SQL', binds = []) result = execute(sql, name) ActiveRecord::Result.new(result.fields, result.to_a) end ```
* add table.bigint supportAaron Patterson2014-10-151-0/+1
| | | | | | | | In the DSL you can now do: create_table(:foos) do |t| t.bigint :hi end
* add a truncate method to the connectionAaron Patterson2014-09-221-0/+4
| | | | | | it doesn't work on SQLite3 since it doesn't support truncate, but that's OK. If you call truncate on the connection, you're now bound to that database (same as if you use hstore or any other db specific feature).
* introduce `connection.supports_views?` and basic view tests.Yves Senn2014-09-091-0/+4
| | | | | | | `AbstractAdapter#supports_views?` defaults to `false` so we have to turn it on in adapter subclasses. Currently the flag only controls test execution. /cc @yahonda
* Freeze ADAPTER_NAME in adaptersAbdelkader Boudih2014-09-051-6/+1
|
* Add support for Postgresql JSONBPhilippe Creux2014-07-241-0/+1
| | | | [Philippe Creux, Chris Teague]
* Don't rely on the sql type to quote XML columns in PGSean Griffin2014-07-061-1/+1
|
* Fix SQL injection when querying against ranges and bitstringsRafael Mendonça França2014-07-021-1/+1
| | | | Fix CVE-2014-3483 and protect against CVE-2014-3482.
* Always pass a column with a type object to quoteSean Griffin2014-06-281-0/+5
| | | | | | | | The only case where we got a column that was not `nil`, but did not respond to `cast_type` was when type casting the default value during schema creation. We can look up the cast type, and add that object to the column definition. Will allow us to consistently rely on the type objects for type casting in all directions.
* fk: `add_foreign_key` and `remove_foreign_key` for PostgreSQL adapter.Yves Senn2014-06-261-0/+4
|
* Encapsulate knowledge of type objects on `ActiveRecord::Result`Sean Griffin2014-06-221-3/+2
| | | | | | | | | | | | | Attempting to reduce the number of places that care about the details of how type casting occurs. We remove the type casting of the primary key in `JoinDependecy`, rather than encapsulating it. It was originally added for consistency with https://github.com/rails/rails/commit/40898c8c19fa04442fc5f8fb5daf3a8bdb9a1e03#diff-06059df8d3dee3101718fb2c01151ad0R211, but that conditional was later removed in https://github.com/rails/rails/commit/d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734. What is important is that the same row twice will have the same value for the primary key, which it will.
* this method is no longer being usedJosh Sharpe2014-06-191-4/+0
|
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-2/+2
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Remove optimization that was required with whiny nilsSean Griffin2014-06-051-8/+0
| | | | Whiny nils is no longer a thing, so we no longer need this optimization
* Collapse PG default extractoin of most types to single regexSean Griffin2014-06-041-48/+6
| | | | | | | For any type that is represented as a string and then type cast, we do not need separate regular expressions for the various types. No function will match this regex. User defined types *should* match this, so that the type object can decide what to do with the value.
* pg, preserve money type when dumping schema and extract money default.Yves Senn2014-06-031-0/+3
|
* Respect limit for PG bit stringsSean Griffin2014-06-031-5/+5
|
* pg, preserve type when schema dumping bit and bit varying columns.Yves Senn2014-06-031-2/+4
|
* pg, preserve point type when schema dumping.Yves Senn2014-06-031-1/+2
|
* pg, support default values for enum types. Closes #7814.Yves Senn2014-05-301-1/+8
| | | | | This is an intermediate solution. It is related to the refactoring @sgrif is making and will change in the future.
* Deprecate decimal columns being automatically treated as integersSean Griffin2014-05-271-0/+2
| | | | | | With ActiveRecord::Properties, we now have a reasonable path for users to continue to keep this behavior if they want it. This is an edge case that has added a lot of complexity to the code base.
* pg, add missing `:nodoc:` to adapter.Yves Senn2014-05-261-8/+8
|
* pg, remove unused code. Use `extract_schema_and_table` instead.Yves Senn2014-05-261-10/+0
|
* pg, extract schema definitions into separate file.Yves Senn2014-05-241-135/+3
| | | | | | | This mirrors the layout of abstract adapter and puts the definitions inside the `PostgreSQL` namespace (no longer under the adapter namespace). /cc @kares
* Remove special case in schema dumper for decimal without scaleSean Griffin2014-05-231-25/+15
|
* Move parsing of PG sql strings for defaults out of columnSean Griffin2014-05-231-0/+71
|
* Push limit to type objectsSean Griffin2014-05-221-2/+10
| | | | | Columns and injected types no longer have any conditionals based on the format of SQL type strings! Hooray!
* Push precision to type objectsSean Griffin2014-05-221-3/+15
|
* Push scale to type objectsSean Griffin2014-05-221-1/+5
| | | | | | Ideally types will be usable without having to specify a sql type string, so we should keep the information related to parsing them on the adapter or another object.
* Move `extract_precision` onto type objectsDan Croak and Sean Griffin2014-05-221-1/+1
|
* Merge pull request #15249 from sgrif/sg-register-types-in-adapterRafael Mendonça França2014-05-221-2/+49
|\ | | | | Use the generic type map for all PG type registrations
| * Use the generic type map for all PG type registrationsSean Griffin2014-05-221-2/+49
| | | | | | | | | | | | | | We're going to want all of the benefits of the type map object for registrations, including block registration and real aliasing. Moves type name registrations to the adapter, and aliases the OIDs to the named types
* | Allow additional arguments to be used during type map lookupsSean Griffin2014-05-221-2/+2
|/ | | | | | | | Determining things like precision and scale in postgresql will require the given blocks to take additional arguments besides the OID. - Adds the ability to handle additional arguments to `TypeMap` - Passes the column type to blocks when looking up PG types
* Use the generic type map for PostgreSQL OID registrationsSean Griffin2014-05-201-3/+20
|
* Have Postgres OID types inherit from general typesSean Griffin2014-05-201-1/+1
| | | | | Using general types where possible. Several more can go away once infinity gets figured out.
* Remove :timestamp column typeSean Griffin2014-05-191-1/+0
| | | | | | | | | | | | The `:timestamp` type for columns is unused. All database adapters treat them as the same database type. All code in `ActiveRecord` which changes its behavior based on the column's type acts the same in both cases. However, when the type is passed to code that checks for the `:datetime` type, but not `:timestamp` (such as XML serialization), the result is unexpected behavior. Existing schema definitions will continue to work, and the `timestamp` type is transparently aliased to `datetime`.
* Delegate `Column#type` to the injected type objectSean Griffin2014-05-191-9/+0
| | | | | | | | | | | | | | | | The decision to wrap type registrations in a proc was made for two reasons. 1. Some cases need to make an additional decision based on the type (e.g. a `Decimal` with a 0 scale) 2. Aliased types are automatically updated if they type they point to is updated later. If a user or another adapter decides to change the object used for `decimal` columns, `numeric`, and `number` will automatically point to the new type, without having to track what types are aliased explicitly. Everything else here should be pretty straightforward. PostgreSQL ranges had to change slightly, since the `simplified_type` method is gone.
* pg, re-introduce `PostgreSQL::Utils` to unify schema/table extraction.Yves Senn2014-05-191-0/+1
| | | | Partial revert of c0bfc3f412834ffe8327a15ae3a46602cc28e425