Category: Blog

  • A New Word: Falesia

    falesia– n.  the disquieting awareness that someone’s importance to you and your importance to them may not necessarily match – that your best friend might only think of you as a buddy, that someone you barely know might consider you a mentor, that someone you love unconditionally might have one or two conditions.

    Wow, falesia is a disconcerting idea in itself. Just reading that makes me a little uncomfortable. I’m sure many people have falesia early on in their relationships, whether dating or friendship, thinking that the person you think is very important doesn’t feel the same way about you.

    I tend to look at most people are equals and try to treat them that way. However, I also get uncomfortable at times when people praise me or thank me for the work I’ve done with SQL Server Central or SQL Saturday. In those cases, I’m sure that the importance we feel towards each other isn’t the same.

    I know I have some falesia and I am definitely uncomfortable in those cases.

    From the Dictionary of Obscure Sorrows

  • Using AI to Test a SQL Query

    Someone sent me this code.

    WITH p AS
     ( SELECT ID, ROW_NUMBER() OVER (ORDER BY ID ASC) AS RN
     FROM wp_posts
     WHERE post_parent = 94341; )
     UPDATE p SET menu_order = RN

    That’s not great code. In fact, it won’t run. I know that, but does an AI? Let’s see how Copilot does.

    This is part of a series of experiments with AI systems.

    The First Test

    I entered this prompt, but accidentally hit Enter. When I then pasted in the code and hit enter, I got this:

    2025-05_line0012

    That is just about what I would have sent the author to let them know this code doesn’t work. It’s good to see a GenAI LLM can recognize this.

    I then pasted in the entire prompt which was: “give me a table with the schema to match this code: WITH p AS ( SELECT ID, ROW_NUMBER() OVER (ORDER BY ID ASC) AS RN FROM wp_posts WHERE post_parent = 94341; ) UPDATE p SET menu_order = RN

    The Gen AI response was polite, with this answer:

    Certainly! Based on your SQL code, it looks like you need a table schema that matches the structure of wp_posts, particularly including ID, post_parent, and menu_order. Here’s a possible schema:

    I then had this code, with a copy button that I could copy/paste into SSMS.

    CREATE TABLE wp_posts (
         ID INT PRIMARY KEY,      -- Unique identifier for each post
         post_parent INT,         -- Parent post ID (for hierarchical structures)
         menu_order INT           -- Order value for arranging posts
    );

    That’s what I would have done to mock this up for testing. You might guess the next step: data.

    Here’s my prompt: create some test data for the table with Ids that increment but are not necessarily sequential and post_parent values that match the ID values

    That got my this response.

    2025-05_line0016

    That’s not bad, but it’s a limited set of data. Let’s ask for more.

    2025-05_line0031

    Below this the GenAI LLM gave me a summary that explains what it did.

    2025-05_line0032

    Next, I wanted a test. I used this prompt: write a tsqlt test to verify that the update statement works to reset the menu_order to sequential values for a particular post_parent

    I got a nice response and the code I’m showing below the image.

    2025-05_line0033

    Here is the code:

    -- Step 1: Create a test class
    EXEC tSQLt.NewTestClass 'TestMenuOrderUpdate';

    GO

     

    — Step 2: Define the test
    CREATE PROCEDURE TestMenuOrderUpdate.[test_UpdateMenuOrder_Sequential]
    AS
    BEGIN
    — Arrange: Fake the wp_posts table
    EXEC tSQLt.FakeTable ‘dbo.wp_posts’;

     

    INSERT INTO wp_posts (ID, post_parent, menu_order)
    VALUES
    (101, 94341, 5), (102, 94341, 3), (103, 94341, 8),
    (104, 94341, 1), (105, 94341, 7);

     

    — Act: Run the update logic
    WITH p AS (
    SELECT ID, ROW_NUMBER() OVER (ORDER BY ID ASC) AS RN
    FROM wp_posts
    WHERE post_parent = 94341
    )
    UPDATE wp_posts
    SET menu_order = p.RN
    FROM p
    WHERE wp_posts.ID = p.ID;

     

    — Assert: Check if menu_order is sequential
    EXEC tSQLt.AssertEqualsTable ‘ExpectedResults’, ‘wp_posts’;

     

    END;
    GO

     

    — Step 3: Create expected results table for assertion
    CREATE TABLE ExpectedResults (
    ID INT PRIMARY KEY,
    post_parent INT,
    menu_order INT
    );

     

    INSERT INTO ExpectedResults (ID, post_parent, menu_order)
    VALUES
    (101, 94341, 1), (102, 94341, 2), (103, 94341, 3),
    (104, 94341, 4), (105, 94341, 5);

     

    — Run the test
    EXEC tSQLt.Run ‘TestMenuOrderUpdate’;

    
    

    This is where I stopped. This code runs, though it’s brittle in that the Expected Results table is a real table and not a temp inside the test. I can easily edit that and likely quicker than the GenAI can. It’s copy/pasting some code for me from one spot to another. I also need to add a CREATE OR ALTER to the proc.

    Summary

    A quick use of an AI that easily saved me 5-10 minutes to mock of a scenario and show someone what they were doing wrong and also testing their code. I mock up things regularly to test them, and often do something like this to answer questions. This is a good place where AI can save some time, and might be worth using. I’m also glad to see it recognize and write some decent SQL code for me, especially the insert statement for test data.

  • Advice I Like: Take Two Trips

    If you have any doubt about being able to carry a load in one trip, do yourself a huge favor and make two trips – from Excellent Advice for Living

    As I get older, this tends to resonate more with me. Certainly I’ve learned not to strain my body because pushing past a limit is painful for days or weeks (or months).

    However, this “carry a load” can make sense in more than just the physical carrying-a-bunch-of-stuff situation. This is a similar situation is you’re trying to accomplish too much in a day, or a sprint, or committing to too many things in a short period of time. It also applies when you try to communicate too many things at once.

    I live my life in a busy fashion, usually having too much stuff on my list of things to do. I’m perpetually behind on fixing things on the ranch, taking care of the house, cooking meals, getting to the gym, improving my coaching skills, etc. I rarely take a day off from not doing something to make my (or someone else’s) life better. That’s a little of how I am built.

    However, I have learned to pace myself a bit more and be cautious about how many things I tackle in a day. I have projects that I might try to rush through in a day and perhaps not get them done the way I expected. Instead, I might break them up across two days. Or two sessions.

    I’ve also learned to communicate one thing and not try to get people to think about three things at once. I try to get myself, and others, to focus on the one important thing that we’re talking about at that moment.

    And, of course, I try not to carry too much at once. I find myself using carts or UTVs rather than piling everything into my arms.

    I’ve been posting New Words on Fridays from a book I was reading, however, a friend thought they were a little depressing. They should be as they are obscure sorrows. I like them because they make me think.

    To counter-balance those, I’m adding in thoughts on advice, mostly from Kevin Kelley’s book. You can read all these posts under the advice tag.

  • Checking Myself with GenAI

    I had a suggestion from somone on a place where AI helps them and I decided to try it. The person had an AI summarize their work and if the result wasn’t the intention of the author, then they know know their writing wasn’t clear.

    This post looks at how that worked for me.

    This is part of a series of experiments with AI systems.

    Checking an Editorial

    I wrote an editorial on database Devops that was published recently. I decided to have a few AIs summarize this and see if the result was what I intended. First up, Claude, with a simple prompt: summarize this text (insert here). See the top of the prompt here:

    2025-05_line0025

    The result is shown below and seems to be an accurate summary of the text. This is basically what I was trying to say in the piece. Of course, this isn’t much shorter than the text, but this gives me confidence here in the ability to recognize what I’ve written.

    2025-05_line0027

    In Perplexity, I got this result. This result is similar, but doesn’t mention the author. Instead, this is a summary of the text, not trying to give a voice to the author, which is interesting. Very close to the text above, but this seems slightly drier, taking the text as fact rather than opinion.

    2025-05_line0026

    Perplexity also had some related items at the bottom, which injected a prompt back into the LLM for more info.

    2025-05_line0029

    Last, Copilot. I have a dedicated key on my laptop for this and I pressed it and entered my prompt in the app. This result is shorter and to the point. There are some additional links to click that the bottom.

    2025-05_line0028

    Clicking on one of the items at the bottom injects the text and gets a new result.

    2025-05_line0030

    I tried this with a couple other piece of work, some of which aren’t published. In each case (3 attempts), the summary made sense. I don’t know if that means I am writing anything clearly, but it does help me get a sense of what I’ve written.