TIL (okay, a couple days ago) that there is a json_agg() function in PostgreSQL.

SELECT
  r.review_id,
  r.review_timestamp,
  json_agg(a.*) AS answers
FROM $schema.review r
INNER JOIN $schema.answer a ON a.review_id = r.review_id
WHERE -- stuff
GROUP BY review_id, review_timestamp

Now I get just one row returned for each relevant review, and each row contains a JSON string with all the answers associated with that review. 🙂

    $schema.answer

    Not sure why my brain is expecting a ? or :schema.answer there

    cluelessPHP Not sure why my brain is expecting a ? or :schema.answer there

    We use Postgres's "schemas" to separate each client's data -- functionally similar to having them each in their own database, except they're not. 🙂 That query was actually extracted from the PHP code that builds the query (and simplified and anonymized here), so $schema would actually be replaced with the relevant schema name for the client being processed, e.g FROM client_foo.review r, and then processed with $pdo->prepare().

    cluelessPHP
    This saddened me a bit. Watched "You Only Live Twice" and "Thunderball" this weekend in his honor. Wish I had a copy of "Robin and Marian", the chemistry he had with Audrey Hepburn was amazing. And I might be a fan indeed as I don't even hate Zardoz TOO much.

    Finally, pretty good compilation of the early Bond themes: https://youtu.be/J4jdUhxOz0M

    dalecosp

    Zardoz is fun if not taken seriously. 🙂

    "The Man Who Would Be King" is pretty darned good. He and Michael Caine make a great pair in it.

    5 days later
    25 days later
    6 days later

    TIL that the film 'Lawrence of Arabia' had its world premiere 10 years closer to the start of the Great War than to the current day.

      9 days later

      sneakyimp you might not like what else ol' Zardoz has to say...

      You sound like my wife 😆

      Remember, at the end Connery comes to find out that part ain't true after all ... 😄

      20 days later

      TIL that returning false works if you declare return type int:

      function foo() : int {
              return false;
      }
      var_dump(foo());

      the result:

      int(0)

      but returning NULL from an int function throws an exception:

      function foo() : int {
              return null;
      }
      var_dump(foo());

      the result:

      PHP Fatal error:  Uncaught TypeError: Return value of foo() must be of the type integer, null returned in /tmp/a.php:3
      Stack trace:
      #0 /tmp/a.php(5): foo()
      #1 {main}
        thrown in /tmp/a.php on line 3

      sneakyimp

      You'll also get that if you try to return a non-numeric string (a numeric string would be recast).

      Also, attempting to return anything other than an int fail if you declare(strict_types=1);.

      Returning null is hazardous, and equivalent to returning nothing at all (return null; is identical in meaning to return;; if a function is supposed to return a value, return; looks wrong). If for some reason you do want nulls hanging around, you can declare the possibility as function foo(): ?int.

      14 days later

      Today I learned Mira Furlan is dead, this year sucks let's go to 2022

        a month later

        TIL that the U.S. Government website for reporting online crime does not work:

         curl -v https://www.ic3.gov/complaint/default.aspx
        *   Trying 65.201.175.169:443...
        * TCP_NODELAY set
        *   Trying 2600:803:c20::3:16:443...
        * TCP_NODELAY set
        * Immediate connect fail for 2600:803:c20::3:16: Network is unreachable
        *   Trying 2600:803:c20::3:15:443...
        * TCP_NODELAY set
        * Immediate connect fail for 2600:803:c20::3:15: Network is unreachable
        *   Trying 2600:803:c20::3:16:443...
        * TCP_NODELAY set
        * Immediate connect fail for 2600:803:c20::3:16: Network is unreachable
        *   Trying 2600:803:c20::3:15:443...
        * TCP_NODELAY set
        * Immediate connect fail for 2600:803:c20::3:15: Network is unreachable

          Today I learned PHP filters. I really enjoy the PHP language while I am learning it.

            TIL (thanks to sneakyimp) that you can do...

            16:16 $ /usr/bin/php -a
            Interactive shell
            
            php > $😊 = 'happy';
            php > echo $😊;
            happy
            php >