aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #27767 from benoittgt/freeze_sql_type_with_get_oid_typeArthur Nogueira Neves2017-01-311-1/+1
|\ | | | | Freeze default empty string for sql_type in get_oid_type
| * Freeze default empty string for sql_type in get_oid_typeBenoit Tigeot2017-01-221-1/+1
| | | | | | | | One empty string allocation per column per row.
* | Simplify Postgres query for column_definitions()Jordan Lewis2017-01-301-5/+5
|/ | | | | | | | | | | | | | column_definitions() needs to fetch the collation for every column, if present. Previously, it did so using a correlated subquery - a subquery that references results from the outer scope. This patch updates the query to remove the subquery in favor of a simpler and more efficient JOIN clause. Running the two queries through EXPLAIN against Postgres additionally shows that the original form with a correlated subquery requires a Nested Loop Left Join, while the new form with a simple JOIN can use a more efficient Merge Left Join.
* Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-6/+0
| | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* Merge pull request #21233 from ↵Rafael França2017-01-031-0/+6
|\ | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
| * Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2016-12-031-0/+6
| | | | | | | | | | | | | | | | | | privileges ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* | Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-1/+1
| | | | | | | | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* | Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-4/+2
| |
* | No need to nodoc private methodsAkira Matsuda2016-12-241-11/+11
| |
* | Translate numeric value out of range to the specific exceptionRyuta Kamizono2016-12-061-0/+3
| | | | | | | | Raise `ActiveRecord::RangeError` when values that executed are out of range.
* | Translate NOT NULL violation to the specific exceptionRyuta Kamizono2016-12-061-0/+3
| | | | | | | | | | Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted or updated because it would violate a not null constraint.
* | Change MySQL and Postgresql to use Bigint primary keysJon McCartie2016-12-051-1/+1
|/
* Stop using the `pg` Float encoderSean Griffin2016-12-011-1/+0
| | | | | | | | | | PG's type map assumes that all Ruby floats are going to a field with an OID of type float4 or float8, and generates text which is invalid syntax for other types. Since the gem can handle floats properly without this encoder (albeit slightly slower), we can continue to use that as we have in prior versions of Rails. Fixes #27246
* For `PostgreSQL >= 9.4` use `gen_random_uuid()`Yaw Boakye2016-11-221-0/+4
| | | | | | | | | | Since 9.4, PostgreSQL recommends using `pgcrypto`'s `gen_random_uuid()` to generate version 4 UUIDs instead of the functions in the `uuid-ossp` extension. These changes uses the appropriate UUID function depending on the underlying PostgreSQL server's version, while maintaining `uuid_generate_v4()` in older migrations.
* Permit loads while queries are runningMatthew Draper2016-10-271-2/+8
| | | | | A query may wait on a database-level lock, which could lead to a deadlock between threads.
* Quote table name properlyRyuta Kamizono2016-10-141-1/+1
| | | | If does not quote table name properly, invalid SQL is generated.
* Merge pull request #26208 from nanaya/pg-insensitive-textMatthew Draper2016-10-111-2/+6
|\ | | | | | | Fix case insensitive check for text column in pg
| * Fix case insensitive check for text column in pgnanaya2016-09-011-0/+4
| | | | | | | | There's no 'text to text' casting in the cast table so the feature detection fails.
| * Use proper castingnanaya2016-09-011-2/+2
| |
* | Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-4/+4
|/ | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Remove deprecated handling of PG PointsSean Griffin2016-08-311-2/+2
| | | | | | | | | | There are some minor changes to the point type as I had forgotten that this will affect the behavior of `t.point` in migrations and the schema dumper so we need to handle those as well. I'll say this again so I can convince myself to come up with a better structure... TYPES SHOULD NOT CARE ABOUT SCHEMA DUMPING AND WE NEED TO BETTER SEPARATE THESE.
* Add `Type.default_value` and use it everywhere for internalRyuta Kamizono2016-08-261-1/+1
| | | | For reduce instantiating `Type::Value`.
* applies remaining conventions across the projectXavier Noria2016-08-061-13/+13
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-74/+74
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Leave internal pgsql name intact as const referenceDavid Heinemeier Hansson2016-08-041-2/+2
|
* The problem isn't the detection but the deadlock itselfDavid Heinemeier Hansson2016-08-041-3/+3
|
* Merge pull request #25107 from Erol/introduce-new-ar-transaction-error-classesRafael Mendonça França2016-08-031-1/+4
|\ | | | | | | | | | | Introduce new ActiveRecord transaction error classes Closes #26018
| * Introduce new ActiveRecord transaction error classesErol Fornoles2016-05-241-1/+4
| |
* | Extract `type_casted_binds` methodRyuta Kamizono2016-07-261-2/+2
| | | | | | | | | | Because `type_cast` against `binds` always requires `attr.value_for_database` and this pattern appears frequently.
* | Pass `type_casted_binds` to log subscriber for logging bind values properlyRyuta Kamizono2016-07-191-2/+2
|/ | | | Address to https://github.com/rails/rails/commit/5a302bf553af0e6fedfc63299fc5cd6e79599ef3#commitcomment-18288388.
* Add AR::TransactionSerializationError for transaction serialization failures ↵Erol Fornoles2016-05-211-0/+3
| | | | or deadlocks
* Treat blank comments as no comment for indexesRyuta Kamizono2016-04-291-4/+0
| | | | | | Follow up of 1683410. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-0/+4
| | | | | | | | | | | | | | | | Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes #19090. Fixes #21765. Fixes #21819. Fixes #24359. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Follow up of #23461Vipul A M2016-04-241-1/+1
| | | | | | | | - Rename max to statement_limit - Remove magic number 1000 from everywhere - Defined StatementPool::DEFAULT_STATEMENT_LIMIT and started using it everywhere Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Include the Savepoints module in all adapters.Vipul A M2016-04-241-1/+4
| | | | | Adapters override `#supports_savepoints?` to return `true` if they support transaction savepoints. Defaults to `false`.
* Move `require 'ipaddr'` in `postgresql/oid/cidr.rb`Ryuta Kamizono2016-04-241-2/+0
| | | | `IPAddr` is used in `OID::Cidr`.
* Define `arel_visitor` method on all adaptersRyuta Kamizono2016-04-201-0/+4
| | | | `Arel::Visitors::VISITORS` was removed at https://github.com/rails/arel/pull/412.
* Merge pull request #23515 from kamipo/extract_arel_visitorJeremy Daer2016-04-191-8/+0
|\ | | | | | | Extract `arel_visitor` and move up to the abstract adapter
| * Extract `arel_visitor` and move up to the abstract adapterRyuta Kamizono2016-04-041-8/+0
| |
* | Merge pull request #23522 from kamipo/add_value_too_long_exception_classJeremy Daer2016-04-181-0/+3
|\ \ | | | | | | | | | Add `ActiveRecord::ValueTooLong` exception class
| * | Add `ActiveRecord::ValueTooLong` exception classRyuta Kamizono2016-02-061-0/+3
| | |
* | | Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-2/+6
| | | | | | | | | | | | | | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* | | Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-4/+9
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
* | use same name to type objectyuuji.yaginuma2016-03-091-1/+1
| | | | | | | | Follow up to #24079
* | Merge pull request #22170 from ↵Matthew Draper2016-03-021-13/+29
|\ \ | |/ |/| | | | | samphilipd/sam/properly_deallocate_prepared_statements_outside_of_transaction Correctly deallocate prepared statements if we fail inside a transaction
| * Correctly deallocate prepared statements if we fail inside a transactionSam Davies2015-11-051-13/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #12330 Overview ======== Cached postgres prepared statements become invalidated if the schema changes in a way that it affects the returned result. Examples: - adding or removing a column then doing a 'SELECT *' - removing the foo column then doing a 'SELECT bar.foo' In normal operation this isn't a problem, we can rescue the error, deallocate the prepared statement and re-issue the command. However in PostgreSQL transactions, once any command fails, the transaction becomes 'poisoned' and any subsequent commands will raise InFailedSQLTransaction. This includes DEALLOCATE statements, so the default deallocation strategy instead of removing the cached prepared statement instead raises InFailedSQLTransaction. Why this is bad =============== 1. InFailedSQLTransaction is a fairly cryptic error and doesn't communicate any useful information about what has actually gone wrong. 2. In the naive implementation the prepared statement never gets deallocated - it stays alive for the length of the session taking up memory on the postgres server. 3. It is unsafe to retry the transaction because the bad prepared statement is still in the cache and we would see the exact same failure repeated. Solution ======== If we are outside a transaction we can continue to handle these failures gracefully in the usual way. Inside a transaction instead of issuing a DEALLOCATE command that will certainly fail, we now raise ActiveRecord::PreparedStatementCacheExpired. This can be handled further up the stack, notably inside TransactionManager#within_new_transaction. Here we can make sure to first rollback the transaction, then safely issue DEALLOCATE statements to invalidate the rest of the cached prepared statements. This also allows the user (or some gem) the opportunity to catch this error and voluntarily retry the transaction if a schema change causes the prepared statement cache to become invalidated. Because the outdated statement has been deallocated, we can expect the transaction to succeed on the second try.
* | Mention supported PG version in the error message.Prathamesh Sonpatki2016-02-031-1/+1
| |
* | The minimum supported version of PostgreSQL is now >= 9.1Remo Mueller2016-02-021-3/+2
| |
* | Extract `ExplainPrettyPrinter` to appropriate filesRyuta Kamizono2016-02-011-0/+1
| |
* | `OID::Money.precision` is unused since #15239Ryuta Kamizono2016-01-311-6/+0
| | | | | | | | | | | | | | | | p PostgreSQLAdapter::OID::Money.precision # => 19 p PostgreSQLAdapter::OID::Money.new.precision # => nil