...will make a single query. It uses a sub-query, which is slow in MySQL, but fast in PostgreSQL: SELECT * FROM posts WHERE user_id IN (SELECT id FROM users...
...invoice.products # => [# ] How the :uniq option works In the example above it changes the MySQL query for Invoice#products to something like SELECT DISTINCT * FROM products ... Issues with PostgreSQL
...rake db:migrate" on an empty # database, we swallow such errors. end end For MySQL, rescue Mysql2::Error, ActiveRecord::StatementInvalid might be fitting...
See also PostgreSQL: Difference between text and varchar columns Text column sizes in MySQL
...mix dates and times incomparisons, mind to not compare datetimes with date ranges in MySQL. Visualisation 1. ------- ------- AAA AAA BBB BBB ------- ------- 2. ------- AAA B ------- 3. ------- A BBB ------- 4. ------- AAA
This card compares patterns to store trees in a relation database like MySQL or PostgreSQL. Implementation examples are for the ActiveRecord ORM used with Ruby on Rails, but the techniques...
...always use Time.current instead of Time.now, etc. Why? Because of the way Rails and MySQL deal with time zones you would need to take care to use Time.zone.now in projects...
...because those times will also be converted using to_s(:db) and sent to MySQL. The database itself does not care about the (longer) value and just stores the date...
Tod is a gem for working with daytimes. That's a tuple of (hour, minute second) without a day, month...
PostgreSQL, unlike MySQL, treats strings as case sensitive in all circumstances. This includes comparison with = and LIKE collision detection in unique indexes Usually this is fine, but some strings (like...
...not found", "Can't open file or directory", ...) after configuration changes, e.g. when changing MySQL's data directory. Remember to have a look at AppArmor's daemon configuration (usually at...
...with both old and new Rails applications. Switch to MariaDB Remove MySQL: sudo apt remove mysql-common mysql-client mysql-server mysql-apt-config Install MariaDB: sudo apt install mariadb...
The mysql and mysql2 gems installed on your machine are still built against the mysql-client package you just uninstalled, so you will probably get this error when booting...
...will make ActiveRecord join the notes and authors tables and the query will fail: Mysql::Error: Column 'created_at' in order clause is ambiguous Unless you have a test covering...
...id: Post.distinct_on_user.pluck(:user_id)).order(...) Further ressources There are some good examples on the MySql documentation to produce queries with the same result in the article 5.6.4 The Rows Holding...
...public | pages | 3919 Please note that this does not work reliably on database slaves. MySQL SELECT table_name, table_rows FROM information_schema.tables WHERE table_schema = (SELECT database()) ORDER BY table...
If you have a replication error with MySQL and you know the "error" is okay (e.g. you've executed the same statement at the same time on 2 masters which...
...your second statement is really the next one which would get executed by the MySQL server. Example: you've executed drop database foobar; and drop database blubber; in a row...
...will resemble your database's EXPLAIN style. For example, it looks like this on MySQL: User.where(id: 1).includes(:articles).explain EXPLAIN for: SELECT `users`.* FROM `users` WHERE `users`.`id...
...server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? Connection to the MySQL database does not work anymore Your travis-ci builds might have started failing on the...
mysql -e 'create database IF NOT EXISTS minidusen_test;' with an error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) The command "mysql...
So you got this error, even though your Gemfile bundles mysql2: !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' or Please install the mysql adapter: `gem install...
...activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) The reason for this confusing error message is probably that your Gemfile says mysql2, but your...
Active Record's select method allows you to make use of the power of MySQL select statements. On the one hand it allows you to select specific fields. Post.select("content...
...allows you to include additional data in your models such as the results of MySQL functions. Those function resulst then are accessible like any other attribute of your model. Lets...
...on the server (ls -l). In our case, it's 1234567890. Know your (local) MySQL root password. We'll use SECRET below. Know your (local) target database name. For us...
...my_project_development. Go wild: ^ ssh user@example.com "cat /mnt/dumps/my_project.dump.bz2" | pv -s 1234567890 | bzip2 -d | mysql -uroot -pSECRET my_project_development That will: Print the (bzipped) file to stdout on the...
If you get a stacktrace complaining about uninitialized constant MysqlCompat::MysqlRes a system library update might broke your gem. You might have switched from MySQL to MariaDB, but forgot to...
...rebuild your MySQL gems. Try fully removing and re-installing the gem: gem uninstall mysql mysql2 bundle install
...get this error message Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"project_development", "password"=>"topsecret"}, charset: utf8, collation: utf8_unicode_ci (if you set the...
...make sure the user you have specified (root/topsecret) in your database.yml has access to MySQL. You can check this by running mysql -uroot -p...
...can lead to NULL distances in edge cases. The reason for this is that MySQL is performing several sine and cosine computations which can result in slight rounding errors -- which...
...to compute the arc cosine of a result like 1.0000000001. Since this is undefined, MySQL correctly returns NULL (instead of the expected distance of 0 for the circle's center...