Press "Enter" to skip to content

Curated SQL Posts

Calculating Exponential Moving Average in T-SQL

Rick Dobson watches the flow:

Exponential moving averages (emas) are a powerful means of detecting changes in time series data. However, if you are new to this task, you may be wondering how to choose from conflicting advice about how to calculate emas. This tip reviews several of the most popular methods for calculating moving averages. Additionally, this tip presents T-SQL code samples with common table expressions and stored procedures for generating emas from an underlying time series dataset.

“Emas don’t just track trends—they reveal momentum in motion.” That’s why they’re favored when recent values matter most—and why this tip focuses on helping you calculate them with precision.

Read on for the formula and a couple of lengthy scripts to generate it.

Leave a Comment

pg_statviz 0.8 Released

Jimmy Angelakos announces a new version of the pg_statviz extension:

I’m happy to announce release 0.8 of pg_statviz, the minimalist extension and utility pair for time series analysis and visualization of PostgreSQL internal statistics.

This release adds support for PostgreSQL 18, adapting to significant catalog view changes introduced in this release:

Read on to see what’s new. pg_statviz is a lightweight extension for observing internal PostgreSQL performance data, such as wait stats and I/O time.

Leave a Comment

Exporting Non-Downloadable Power BI Reports

Koen Verbeeck downloads a report:

Yes, you’re reading that right, we’re going to download a report that cannot be downloaded. Well, it cannot be downloaded from the user interface, that is. Suppose you have a report in a Power BI workspace (Pro, PPU, Fabric, it shouldn’t matter), and they’ve lost the original Power BI Desktop file. You try to download the report, but for some reason the GUI doesn’t let you:

Read on for reasons you might not be able to download the report, as well as what you can do if you do have access to the report but the download option is unavailable.

Leave a Comment

Running SQL against Fabric Warehouses via Python

Jared Westover builds a loop:

In a previous article, I ran a SQL script against a Fabric Warehouse 100 times without needing to click ‘Execute’ each time. A WHILE loop could work, but Query Insights treats it as a single execution. While using GO was an option, I wanted a different approach because I’m always trying to expand my skill set. I need a scalable way to run scripts for performance testing.

This is a pretty simple database connection and script execution. For the most part, it would work just fine for any other SQL Server family member, just with a somewhat different connection string depending on the product.

Leave a Comment

Comparing Sets of Data in T-SQL

Louis Davidson figured out which of these was not like the others, which of these just didn’t belong:

There are many occasions when we want to see the differences between two sets of data. Sometimes a whole table, a subset of a table, or even the results from a couple of queries, like in a unit test.

Maybe you want to see that two sets are exactly the same, for example domain table in DEV, PROD, or maybe even from source control. You might you have a orders table and an orders_history table and you want to see the overlap/changes over a given period of time, like for example, to clean out any useless history.

No matter what the reason, there is a query pattern that will work for you. In this blog I will demonstrate several of these techniques and why you might want to use them in different places.

Click through for those techniques. I am particularly fond of INTERSECT/EXCEPT because of how it handles missing data and typically performs quite well.

Leave a Comment

Deleting Default Semantic Models in Microsoft Fabric

Pradeep Srikakolapu says good riddance:

In our earlier announcement, we shared that newly created data warehouses, lakehouses and other items in Microsoft Fabric would no longer automatically generate default semantic models. This change allows customers to have more control over their modeling experience and to explicitly choose when and how to create semantic models.

Starting November 20, 2025, Power BI *default* semantic models are disconnected from their item and become independent semantic models.

Click through for an overview of those changes and how you can get rid of the default models you may still have hanging around.

Leave a Comment

Exploiting Database as a Service SQL Server

Fabiano Amorim has a post-mortem of a nasty privilege escalation bug in SQL Server:

This article explores a serious flaw in this security model – a SQL Injection vulnerability in sys.sp_help_spatial_geography_histogram that allowed a standard user on managed SQL Server instances (AWS, GCP, Alibaba, Azure) to completely bypass these restrictions, gain access to privileged user data, and decrypt the source code of internal management stored procedures.

It was fixed in SQL Server 2022 CU20 (KB5063814), but this article explains how the exploit worked and the process of eliminating it.

Click through for the details and make sure your on-premises SQL Server instances are patched.

Leave a Comment

Windows Clustering for the DBA

Sandra Delany is perilously close to running afoul of Betteridge’s Law of Headlines:

Should a SQL Server DBA know how a Windows cluster works, and or how to create a Windows cluster, or troubleshoot a cluster? Or should we, as DBAs, stay in our lane? In some organizations, a line is drawn between what a DBA can and can’t do and the System Administrator (SA) has the Infrastructure roles and responsibilities. This is fine, but that doesn’t mean a DBA shouldn’t know how to troubleshoot a FCI (Failover Cluster Instance) or AG (Availability Group) issue after an unplanned cluster-level failover.  (Yes – you can create an AG without a cluster, but that will not be taken into consideration here.)

Read on for some quick tips to get ramped up on what is available in a Failover Cluster Instance.

Leave a Comment

Azure Tenants and Microsoft Fabric

Andy Cutler begins a new series on Microsoft Fabric architecture:

Our Fabric Architecture journey starts with Azure Tenants (the kick-off blog in this series is here with a few jumping-off links to get started with thinking about Fabric Architecture). If you’re ready to spent time sketching out your Fabric Capacity planning, workspace strategy, domain topology, lakehouse/warehouse creation, data loading processes…you might want to stop for a minute and think about tenants. The question I’d like you to consider is What do I need to know when working with a single or a multi-tenancy approach? Let’s unpack this question because while it might sound like a simple list, it actually shapes your governance, scalability, and Fabric operational model. If you’re a seasoned Azure Architect veteran then you already know how to decide between single and multi-tenant cloud rollouts (also, please comment if you have anything to add please), if you work with Fabric/Data and don’t really dive into Azure architecture on a daily basis then please stick around. Hopefully this blog gets you thinking about single/multi-tenant architectures and the benefits/costs.

Read on for a dive into what tenants are, the benefits of single- versus multi-tenancy, and how it all ties into Fabric.

Leave a Comment

Function Volatility and PostgreSQL Partition Performance

Deepak Mahto covers how function volatility can affect how queries on partitioned data perform:

In one of our earlier blogs, we explored how improper volatility settings in PL/pgSQL functions — namely using IMMUTABLESTABLE, or VOLATILE — can lead to unexpected behavior and performance issues during migrations.

Today, let’s revisit that topic from a slightly different lens. This time, we’re not talking about your user-defined functions, but the ones PostgreSQL itself provides — and how their volatility can quietly shape your query performance, especially when you’re using partitioned tables.

Click through for one example using date-based partitioning and date functions.

Leave a Comment