Press "Enter" to skip to content

Curated SQL Posts

Unicode Providers in PostgreSQL

Daniel Vérité checks the version:

With three locale providers (libc, icu and builtin), a PostgreSQL instance has potentially three different versions of Unicode at the same time.

When doing only store/retrieve or basic operations on UTF-8 strings, these versions don’t matter. Postgres checks that the bytes in the strings constitute valid UTF-8 sequences, but not whether the code points corresponding to these sequences are assigned or not.

It starts to matter when interpreting these code points as characters.

Read on to see which features might determine which Unicode provider you might be using.

Leave a Comment

Concatenation and UNISTR in SQL Server

Koen Verbeeck takes a peek at a pair of new features in SQL Server 2025:

Often new T-SQL functionality is released first in the Azure cloud environment, before it makes its way to the on-premises SQL Server product. Recently, a new T-SQL function and operator went general available in Azure SQL DB (and Azure SQL Managed Instance): UNISTR and the ANSI SQL string concat operator (||). In this tip, we’ll introduce you to both concepts.

Koen looks at these in Azure SQL Database, though if you have the public preview of SQL Server 2025, you can try both out there as well.

Leave a Comment

DBSCAN in SQL Server

Sebastiao Pereira is a mad lad and I love it:

Is it possible to have the DBSCAN algorithm in SQL Server without the use of external tools? If so, can you please provide a working example?

DBSCAN is a neat algorithm for clustering and it is reasonably popular in the literature. I cannot imagine that it would perform well at all in SQL Server on a large dataset, though in fairness, I did try out the Mail_Customers example Sebastiao noted. This dataset includes 196 rows after you eliminate four duplicate combinations of annual income and spending score, and the procedure returned in less than a second. Now, getting the execution plan for this took a while, but it was neat to see this working.

Leave a Comment

Tips for Technical Writing

Mike Robbins shares some guidance:

Passive voice hides the actor, making instructions vague or more difficult to follow. Instead, use active voice to clarify who performs the action. Active voice includes any sentence where the subject performs the action (e.g., You run the script).

  • Incorrect: When the font size is adjusted, the code becomes easier to read.
  • Correct: If you adjust the font size, your code becomes easier to read.

Active voice makes instructions direct and actionable.

I hate passive voice enough that I would link to this post even if it were the only piece of advice on there. There are very specific good uses for passive voice in English, particularly when you do not know who the actor was and the actor does not matter. The rest of the time, people primarily use passive voice when they want to weasel out of something or avoid assigning blame. And most of the time, even when you think this you have a good use case for passive voice, you probably don’t.

Case in point: “Archduke Franz Ferdinand’s assassination was a primary inciting factor for the Great War.” This is passive voice—we swapped a verb (assassinate) to a noun (assassination) in order to focus on the direct object at the expense of the subject. The general rule of thumb is that if you can ask “By whom?” when reading a sentence, there is a very good chance that the author used passive voice. And we may think at first that the actor does not matter, but I chose this example precisely because he does. In order to understand why the Austro-Hungarian government reacted the way it did, you have to know that the assassin was a Serbian nationalist, that the Russian government had a particularly close connection with Serbia, and that the Austro-Hungarian government had a very contentious relationship with the Balkans at that point (and I’m being kind by using the word “contentious” here). Granted, it’s not critical to fit all of this into the one sentence, but removing the subject turns into a game of “hide the ball” way too quickly.

In active tense, I’d rewrite the sentence to be something like: “A primary inciting factor for the Great War occurred when a Serbian nationalist assassinated Archduke Franz Ferdinand.”

Leave a Comment

SQL Firewall in Oracle

Brendan Tierney tries out the SQL Firewall feature in Oracle:

SQL Firewall allows you to implement a firewall within the database to control what commands are allowed to be run on the data. With SQL Firewall you can:

  • Monitor the SQL (and PL/SQL) activity to learn what the normal or typical SQL commands are being run on the data
  • Captures all commands and logs them
  • Manage a list of allowed commands, etc, using Policies
  • Block and log all commands that are not allowed. Some commands might be allowed to run

Read on to see how it works. It’s an interesting approach that can supplement traditional firewall and web application firewall systems.

Leave a Comment

Organizational Themes in Power BI

Boniface Muchendu takes a peek at a fairly new feature:

Keeping your Power BI reports consistent, clean, and on-brand just got a lot easier. With the new Organizational Themes feature released in June 2025, Power BI now allows organizations to centrally manage and distribute custom report themes across all users. No more manual theme imports or scattered design standards.

Read on to see how it works, and hopefully your organization does not have terrible standards.

Leave a Comment

Connecting to SQL Server when TempDB Transaction Log is Full

Garry Bargsley makes a connection:

Oh no.. my number one troubleshooting tool is not usable. Time to fire up a command prompt and connect via DAC, right?

Well, not so fast.

During a recent technical interview, I was introduced to a clever workaround that lets you connect to a distressed SQL Server using SSMS, even when it seems unresponsive.

Read on to see how you can connect without SSMS performing a bunch of background queries to retrieve data that end up using tempdb, and then resolve the issue.

Leave a Comment

Ingesting IoT Data into SQL Server via Python

Hristo Hristov builds an app:

MQTT is a lightweight Industrial IoT communications protocol allowing efficient communication to and from edge devices such as machines, sensors, and actuators. How can we get data from an MQTT on-premises or cloud broker and persist them in an SQL Server database? How can we leverage the newest features in SQL Server 2025 to make efficient query compilations and build a scalable solution for a data pipeline for permanently storing IoT data?

Read on for the code, most of which is in Python.

Comments closed

Finding Row Counts in Tables

Andy Brownsword wants a quick answer:

A question I ask myself often when exploring unfamiliar data sets. So here’s a quickie:

Click through for the script. This is a lot faster than SELECT COUNT(*), something that can really burn you when there are a few trillion rows in a table and your index scan interferes with ongoing operations. I’ve noticed that reading these counts from statistics is usually pretty solid, but generally, we’re interested in orders of magnitude, in which case 39,308,149 and 39,308,206 are close enough for purposes of understanding which tables are heftier.

Comments closed

The Readability Benefit of Splatting in Powershell

David Seis simplifies the code a bit:

Have you ever written a PowerShell command so long that it stretched across the screen? Or had to update a script and hunt through a long parameter list to change a single value? Splatting solves that problem by letting you pass multiple parameters to a command using a single variable.

Read on for some examples, including a good example of how to make similar cmdlet calls easier to read.

Comments closed