Had a ... fun thing happen in GitHub Actions today where my tests were starting before the MySQL server they needed was up and running. MySQL in this case was running in Docker compose. So I started my process with a little shell script using mysqladmin: #!/usr/bin/env bash count=0 alive="no" while [ "$count" -lt 5… Continue reading Waiting for MySQL to be Ready in Docker Compose
Category: Databases
PostgreSQL’s ROW_TO_JSON and JSON_AGG with JSON Columns
I've hit this a few times and had to remind myself how Postgres behaves when aggregating JSON columns or including them in ROW_TO_JSON. The short answer is that Postgres does the right thing. When a JSON column is included in ROW_TO_JSON or JSON_AGG the resulting values are not nested, encoded JSON. Here's our sample table… Continue reading PostgreSQL’s ROW_TO_JSON and JSON_AGG with JSON Columns
How do MySQL’s LAST_INSERT_ID() and INSERT … ON DUPLICATE KEY Work Together
What happens when an INSERT ... ON DUPLICATE KEY statement is followed by LAST_INSERT_ID() when an update is made? Does LAST_INSERT_ID() return the ID of the row updated? MySQL's documentation on INSERT ... ON DUPLICATE KEY states that... If a table contains an AUTO_INCREMENT column and INSERT ... ON DUPLICATE KEY UPDATE inserts or updates… Continue reading How do MySQL’s LAST_INSERT_ID() and INSERT … ON DUPLICATE KEY Work Together
Working with PostgreSQL Arrays in PHP
I recently had to do some work with PostgreSQL arrays in a PHP app. My first question: how do I manage arrays as parameterized values in a query? Turns out there are two ways forward: Array Literals These appear in the Postgres documentation as curly brace surrounded, comma delimited lists: {1,2,3}. A literal like this… Continue reading Working with PostgreSQL Arrays in PHP