...behavior and implementation. PostgreSQL Timeout Type: statement_timeout Scope: Applies to all types of SQL statements (SELECT, INSERT, UPDATE, DELETE). Units: Can be specified in various time units (milliseconds, seconds...

...to the timeout (ERROR: canceling statement due to statement timeout (PG::QueryCanceled)). If multiple SQL statements appear in a single simple-query message, the timeout is applied to each statement...

When debugging slow SQL queries, it’s helpful to understand the database engine's query plan. Whenever you execute a declarative SQL query, the database generates a "query plan" that...

...Most of the time, we don’t need to worry about this plan because SQL engines are highly optimized and can generate efficient execution strategies automatically. However, if a query...

validates_uniqueness_of is not sufficient to ensure the uniqueness of a value. The reason for this is that in...

Don't sum up columns with + in a sql-query if NULL-Values can be present. MySQL and PostgreSQL cannot sum up NULL values with the + value. The sum value...

DevOps Curriculum

Mit SQL spricht man mit relationalen Datenbanken. Ziele Verstehe die folgenden SQL Befehle SELECT WHERE ORDER INNER JOIN, LEFT JOIN GROUP BY LIMIT UPDATE INSERT and INSERT...

DELETE

...welchen Umständen kann hot_standby_feedback zu Problemen mit VACUUM und Indizes führen? Inhalte SQLZOO Tutorial: Übungsaufgaben in Tutorials Joins Visualizer: Explains the differences between various types of JOIN statements...

...views, procedures, triggers or custom ditionaries. In these cases you must switch to a SQL based schema format: # in application.rb config.active_record.schema_format = :sql This now creates a file db/structure.sql instea...

...drawback of db/structure.sql is that different developer PCs or servers may create slightly different SQL output. Since this file is rewritten with every migration run, this can generate a lot...

makandra dev
rails-sqli.org

...page lists many query methods and options in ActiveRecord which do not sanitize raw SQL arguments and are not intended to be called with unsafe user input. Careless use of...

...these methods can open up code to SQL Injection exploits. The examples here do not include SQL injection from known CVEs and are not vulnerabilites themselves, only potential misuses of...

guides.rubyonrails.org

ActiveRecord offers an explain method similar to using EXPLAIN SQL statements on the database. However, this approach will explain all queries for the given scope which may include joins or...

MySQL and MariaDB have an SQL mode setting which changes how MySQL behaves. The SQL mode value is comprised of multiple flags like "STRICT_TRANS_TABLES, NO_ZERO_IN_DATE...

...Each flag activates or disables a particular behavior. The default SQL mode varies widly between versions of MySQL and MariaDB. In general, more recent versions of MySQL and MariaDB have...

...run your test suite to see if the migration was successful. Troubleshooting: Use an SQL compatibility mode If you get unexpected SQL errors related to the handling of missing or...

...values, you need to either fix your app or remove the STRICT_TRANS_TABLES SQL mode flag that is default in MariaDB 10.2. Note that if you switch to a...

arrival_place: :translations ) .to_a What we do here: First make some custom SQL with INNER JOINs where our order constraint can be fulfilled (Power of plain SQL: Using...

If you want to load an SQL dump from an ActiveRecord migration, you might find this to be harder than you thought. While you can call ActiveRecord::Base.connection.execute(sql) to...

...execute arbitrary SQL commands, the MySQL connection is configured to only accept a single statement per query. If you try to feed it multiple statements, it will die with You...

api.rubyonrails.org

...for the time of executing a block of code. Thus you can capture all sql queries that are triggered when executing your block. Now all you have to do is...

event = ActiveSupport::Notifications::Event.new(*args) events << event end # subscribe to active record sql events ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do # the code you want to analyze ... Tv.generate_schedule...

...dbi:ODBC:MyLegacyServer', 'my_name', 'my_password') DBI::DatabaseError: INTERN (0) [RubyODBC]Cannot allocate SQLHENV from /usr/lib/ruby/1.8/dbd/odbc/driver.rb:36:in `connect' from /usr/lib/ruby/1.8/dbi/handles/driver.rb:33:in `connect' from /usr/lib/ruby/1.8/dbi.rb:148:in `connect...

Image.order(created_at: :desc) Not only do you not have to write SQL, you also get qualified column names (created_at becomes images.created_at) for free. Multiple order...

ActiveRecord caches results of SQL queries. If you want to discard the cached results for one model, you can call MyModel.connection.clear_query_cache...

After you configured your ODBC describe in Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10 and Connecting to MSSQL with Ruby on...

User.active.to_sql Rails 2 Use either the Edge Rider or fake_arel gem to get #to_sql backported to Rails 2. If you don't want to use...

...a gem for this, you can do this with vanilla Rails 2: User.active.construct_finder_sql...

SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'your_database' order by table_rows;

robots.thoughtbot.com

Arel is a library that was introduced in Rails 3 for use in constructing SQL queries. Every time you pass a hash to where, it goes through Arel eventually. Rails...

makandra dev
begriffs.com

The attached article explains options you have to store the order of items in a database table. The simplest solution...

...We will talk about this in another card. 1. Use the full power of SQL Plain SQL can be very powerful. Once you get to know it, it can actually...

class AddFollowersCountToPosts < ActiveRecord::Migration def up add_column :posts, :followers_count, :integer update <<~SQL.squish UPDATE posts SET followers_count = ( SELECT COUNT(*) FROM followers WHERE followers.post_id = posts.id ) SQL

...not return rows where role is NULL, since in NOT NULL equals NULL in SQL. If this important for you, use a solution with a subquery (role NOT IN (...)).

...Finally, you may use where_values_hash from ActiveRecord::Relation to construct a single SQL query which NOTs your scope's conditions. User.where.not(User.admins.where_values_hash) That's just like...

...all we need to implement this method: class Message < ApplicationRecord scope :search, ->(query) { where(<<~SQL, query: query) } to_tsvector('simple', messages.body) @@ websearch_to_tsquery('simple', :query) SQL end This implementation...

...operator multiple times and OR the results: class Message < ApplicationRecord scope :search, ->(query) { where(<<~SQL, query: query) } (to_tsvector('simple', messages.subject) @@ websearch_to_tsquery('simple', :query)) OR (to_tsvector('simple...