<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rodrigo Ferreira on Medium]]></title>
        <description><![CDATA[Stories by Rodrigo Ferreira on Medium]]></description>
        <link>https://medium.com/@ravf_60952?source=rss-12280ec54b51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wthjBXexw_e0YqxkJVyFHg.png</url>
            <title>Stories by Rodrigo Ferreira on Medium</title>
            <link>https://medium.com/@ravf_60952?source=rss-12280ec54b51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 22:05:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravf_60952/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up a local SQL playground]]></title>
            <link>https://medium.com/@ravf_60952/setting-up-a-local-sql-playground-8498c35f1960?source=rss-12280ec54b51------2</link>
            <guid isPermaLink="false">https://medium.com/p/8498c35f1960</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[dbeaver]]></category>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Rodrigo Ferreira]]></dc:creator>
            <pubDate>Mon, 14 Sep 2026 17:34:35 GMT</pubDate>
            <atom:updated>2026-09-14T17:34:35.493Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.rodrigoavf.dev/projects/fabric-pbi-monitoring"><em>https://www.rodrigoavf.dev</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnJYCqogwVmPjOCONLmM4g.png" /></figure><h3><strong>The problem</strong></h3><p>When I started learning SQL, one of the things that felt like it was holding me back the most was not having a place where I could practice absolutely any command without worrying about the consequences. I wanted to run a DELETE without a WHERE clause and watch what happened. I wanted to DROP a table just to see what broke afterward. I wanted to be able to run any CREATE TABLE or CREATE VIEW command. Every tutorial pointed to some shared demo database, or an online sandbox that reset itself every session, or a company database I was way too scared to touch.</p><p>If you’re in that same spot, the fix is simple: put a database on your own computer that answers to nobody but you. Nothing you do to it matters to anyone but you, and that’s exactly the point. You can create tables, break them, drop the whole schema, and start over in seconds.</p><p>I will show you two databases types, for two different reasons, and for both we are going to use DBeaver.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXyMZufYCurA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXyMZufYCurA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXyMZufYCurA%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/76359155a0c44d92ed9126a6e1a31855/href">https://medium.com/media/76359155a0c44d92ed9126a6e1a31855/href</a></iframe><h3><strong>Installing DBeaver</strong></h3><p>DBeaver is a free desktop client that can connect to pretty much any database. Download the free Community edition from <a href="https://dbeaver.io/download">https://dbeaver.io/download</a> install it like any other app, and open it. The first time it launches, it’ll ask if you want to create a sample database, which is already very good, it is a database that lives in your computer, completely under your control and already populated. But we will build our own too.</p><h3><strong>Option 1: SQLite, a database that’s just a file</strong></h3><p>SQLite doesn’t run as a server. There’s no process listening on a port, no service to start or stop. The entire database is one file sitting on your disk, and DBeaver reads and writes to that file directly. This is what makes it “not really live”: when you close DBeaver, the database isn’t running anywhere, it’s just sitting there as a file, exactly like a .csv or a .docx.</p><p>That also makes it the lowest-friction option to start with. To connect:</p><p>1. Click <strong>New Database Connection</strong> in DBeaver.</p><p>2. Search for <strong>SQLite </strong>and select it.</p><p>3. Choose a path for a new file (or point it at an existing .db/.sqlite file).</p><p>4. Click <strong>Test Connection</strong>, then <strong>Finish</strong>.</p><p>That’s it, no username, no password, no host. You now have a blank database to throw SQL at:</p><pre>-- Creates a table called `students` with three columns: `id`, `name`, and `grade`.<br>create table students (<br>  id integer primary key autoincrement, -- SQLite<br>  -- id serial primary key, -- PostgreSQL<br>  name text not null,<br>  grade integer<br>);<br><br>-- Populates the table with two rows of data.<br>insert into students (name, grade) values (&#39;Ana&#39;, 9), (&#39;Marco&#39;, 10);<br><br>-- Retrieves all rows from the `students` table.<br>select * from students;<br><br>-- Deletes rows from the `students` table where the grade is 9.<br>delete from students where grade = 9;</pre><h3><strong>The sample database</strong></h3><p>DBeaver ships with a demo dataset based on Chinook (a music store schema with artists, albums, tracks, invoices) that it can build for you as a SQLite file. You can create it during the first launch, and it can also be added at any time afterward. If you skipped it on install, go to <strong>Help → Create Sample Base</strong> in the menu, and DBeaver will set it up as a new connection. It’s a good option if you want to practice queries against a more complex schema than the one you just created, and it can be deleted and recreated at any time.</p><h3><strong>Option 2: PostgreSQL, a database that’s actually running</strong></h3><p>SQLite is great for getting comfortable with syntax, but it hides a big part of what working with a real database feels like: there’s no server process, no connections to manage, no concurrency to think about. PostgreSQL fixes that, because it genuinely runs as a service on your machine, the same way it would on a company’s server.</p><p>Installing it depends on your OS:</p><p><strong>macOS (with Homebrew)</strong></p><pre>brew install postgresql@16<br>brew services start postgresql@16</pre><p><strong>Ubuntu/Debian</strong></p><pre>sudo apt install postgresql postgresql-contrib<br>sudo systemctl start postgresql</pre><p>On Windows, grab the installer from <a href="https://www.postgresql.org/download/windows/">https://www.postgresql.org/download/windows/</a> and run it. It’ll ask you to set a password for the default `postgres` user during setup, keep that, you’ll need it in a second. It also bundles pgAdmin, but you can ignore that since we’re using DBeaver for everything.</p><p>Once it’s installed and running, connect from DBeaver:</p><p>1. Click <strong>New Database Connection </strong>and choose <strong>PostgreSQL</strong>.</p><p>2. Host: localhost, Port: 5432.</p><p>3. Database: postgres, Username: postgres, and the password you set during install.</p><p>4. <strong>Test Connection</strong>, then <strong>Finish</strong>.</p><p>I chose PostgreSQL because it’s the most common open-source database in the wild, and it has a lot of features that SQLite doesn’t. But you could also use MySQL, SQL Server, or any other database that DBeaver supports. The steps are similar: install the server, start it, and connect to it from DBeaver.</p><h4><strong>Why bother with this over the SQLite option?</strong></h4><p>A few things open up once there’s an actual server behind the database instead of a file:</p><ul><li><strong>More than one connection at a time.</strong> Two terminals, two apps, or you and a script can all query it at once, which is how real systems behave and SQLite genuinely struggles with.</li><li><strong>Other tools can talk to it too.</strong> This is the big one for me: you can point Power BI straight at your local Postgres instance as a live data source, build a report against it, and refresh it, something you can’t cleanly do with a SQLite file sitting on disk, not without a lot of extra work anyway.</li><li><strong>Closer to what you’d meet at a job.</strong> Schemas, roles and permissions, indexes beyond the basics, proper transactions. SQLite supports a version of some of this, but Postgres is what most companies actually run.</li></ul><h3><strong>What’s still rough</strong></h3><p>None of this fully replicates a production environment. Postgres running locally has to be started manually unless you set it to launch on boot, and it does sit in the background using memory even when you’re not touching it, which the SQLite file never does. It also won’t teach you anything about network latency, backups, or the quirks of a managed service like RDS or Azure Database for PostgreSQL.</p><p>But for the actual goal, a place to run any SQL command without fear, both cover it. I use the SQLite file for quick one-off syntax checks, and the local Postgres server for anything that needs to feel like a real project.</p><p><em>Originally published at </em><a href="https://www.rodrigoavf.dev/projects/fabric-pbi-monitoring"><em>https://www.rodrigoavf.dev</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8498c35f1960" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Removing All DAX Comments From a Model in One Pass]]></title>
            <link>https://medium.com/@ravf_60952/removing-all-dax-comments-from-a-model-in-one-pass-2a313727e20d?source=rss-12280ec54b51------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a313727e20d</guid>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[tabular-editor]]></category>
            <category><![CDATA[dax]]></category>
            <dc:creator><![CDATA[Rodrigo Ferreira]]></dc:creator>
            <pubDate>Mon, 31 Aug 2026 00:00:16 GMT</pubDate>
            <atom:updated>2026-09-14T17:36:34.090Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.rodrigoavf.dev/writing/remove-comments-tabular-editor"><em>https://www.rodrigoavf.dev</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udklL7u_5fNlchTZzpSE1Q.png" /></figure><h3>The Problem</h3><p>Every measure I write picks up comments as I go. A //note about why a filter is there, a /* */ block I used to disable half a while debugging, a CALCULATE() leftover reminder to fix something later. That’s fine during development, it’s how DAX thinking usually happens for me.</p><p>The problem shows up later, when the model is done and I want to hand it off, publish it, or just look at it with fresh eyes. Dozens of measures, each with a few lines of scratch notes mixed into the actual logic. Going through them one at a time in Tabular Editor’s expression editor to delete comments by hand is slow, and it’s exactly the kind of repetitive task I’d rather not do manually.</p><p>Tabular Editor doesn’t have a built-in “strip comments” action. There’s no menu item for this, no DAX function. The only option was doing it by hand, or writing something to do it for me.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DB1vv7WAUBaA&amp;type=text%2Fhtml&amp;schema=youtube&amp;display_name=YouTube&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FB1vv7WAUBaA" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/575a4b3aa3fcfef2eb303c1920f544ed/href">https://medium.com/media/575a4b3aa3fcfef2eb303c1920f544ed/href</a></iframe><h3>What I built</h3><p>Tabular Editor has an Advanced Scripting window that runs plain C# against the model, with model already in scope. That’s the natural place for a one-off cleanup script like this: paste it in, run it once, done.</p><p>The naive version is a couple of regex replacements for//.*$ and /\*.*?\*/. That breaks the moment a measure has a text string containing something that looks like a comment, which happens more often than you’d think. A measure returning a status label like &quot;In Progress // Review” would get silently mangled, and that’s worse than not touching it at all.</p><p>So instead of regex, the script walks each expression character by character and only strips comments when it’s outside of a double-quoted string:</p><pre>// Removes comments from the DAX expressions of SELECTED measures, <br>// SELECTED calculated columns, AND all measures/columns inside SELECTED TABLES.<br>//<br>// Handles //, -- and /* */ comments.<br>// Preserves text inside double-quoted DAX strings (including escaped &quot;&quot; quotes).<br>//<br>// Comments that start with the string in `keepCommentPrefix` (after trimming<br>// leading whitespace inside the comment) are LEFT IN PLACE instead of removed.<br>// Leave `keepCommentPrefix` empty (&quot;&quot;) to remove ALL comments.<br> <br>using System;<br>using System.Text;<br>using System.Linq;<br>using System.Collections.Generic;<br>using TabularEditor.TOMWrapper;<br> <br>// ==================== CONFIGURATION ====================<br>// Comments starting with this string are preserved. Case-sensitive.<br>// Example: &quot;KEEP:&quot; will preserve &quot;// KEEP: don&#39;t touch this&quot;<br>// Leave as &quot;&quot; to delete every comment.<br>string keepCommentPrefix = &quot;KEEP:&quot;;<br>// =========================================================<br> <br>int changed = 0;<br> <br>Func&lt;string, string, string&gt; RemoveComments = (input, keepPrefix) =&gt;<br>{<br>    var sb = new StringBuilder(input.Length);<br>    int i = 0;<br>    int n = input.Length;<br>    bool inString = false;<br>    bool commentRemoved = false; // Tracks if we actually deleted anything<br> <br>    while (i &lt; n)<br>    {<br>        char c = input[i];<br> <br>        if (inString)<br>        {<br>            sb.Append(c);<br>            if (c == &#39;&quot;&#39;)<br>            {<br>                // Escaped double quote inside DAX string (&quot;&quot;)<br>                if (i + 1 &lt; n &amp;&amp; input[i + 1] == &#39;&quot;&#39;)<br>                {<br>                    sb.Append(&#39;&quot;&#39;);<br>                    i += 2;<br>                    continue;<br>                }<br>                inString = false;<br>                i++;<br>                continue;<br>            }<br>            i++;<br>            continue;<br>        }<br> <br>        // Start of string?<br>        if (c == &#39;&quot;&#39;)<br>        {<br>            inString = true;<br>            sb.Append(c);<br>            i++;<br>            continue;<br>        }<br> <br>        // Line comment: // ... or -- ... (until newline)<br>        bool isSlashComment = (c == &#39;/&#39; &amp;&amp; i + 1 &lt; n &amp;&amp; input[i + 1] == &#39;/&#39;);<br>        bool isDashComment = (c == &#39;-&#39; &amp;&amp; i + 1 &lt; n &amp;&amp; input[i + 1] == &#39;-&#39;);<br> <br>        if (isSlashComment || isDashComment)<br>        {<br>            int start = i;<br>            i += 2;<br>            int contentStart = i;<br>            while (i &lt; n &amp;&amp; input[i] != &#39;\n&#39; &amp;&amp; input[i] != &#39;\r&#39;) i++;<br>            int contentEnd = i;<br> <br>            string commentBody = input.Substring(contentStart, contentEnd - contentStart);<br>            bool keep = !string.IsNullOrEmpty(keepPrefix) &amp;&amp;<br>                        commentBody.TrimStart().StartsWith(keepPrefix, StringComparison.Ordinal);<br> <br>            if (keep) <br>            {<br>                sb.Append(input.Substring(start, i - start));<br>            } <br>            else <br>            {<br>                commentRemoved = true; // We successfully stripped a comment<br>            }<br> <br>            continue;<br>        }<br> <br>        // Block comment: /* ... */<br>        if (c == &#39;/&#39; &amp;&amp; i + 1 &lt; n &amp;&amp; input[i + 1] == &#39;*&#39;)<br>        {<br>            int start = i;<br>            i += 2;<br>            int contentStart = i;<br>            while (i + 1 &lt; n &amp;&amp; !(input[i] == &#39;*&#39; &amp;&amp; input[i + 1] == &#39;/&#39;)) i++;<br>            int contentEnd = i; // exclusive of closing */<br>            bool hasClosing = (i + 1 &lt; n);<br>            if (hasClosing) i += 2; // skip closing */<br>            else i = n;<br> <br>            string commentBody = input.Substring(contentStart, contentEnd - contentStart);<br>            bool keep = !string.IsNullOrEmpty(keepPrefix) &amp;&amp;<br>                        commentBody.TrimStart().StartsWith(keepPrefix, StringComparison.Ordinal);<br> <br>            if (keep) <br>            {<br>                sb.Append(input.Substring(start, i - start));<br>            }<br>            else <br>            {<br>                commentRemoved = true; // We successfully stripped a comment<br>            }<br> <br>            continue;<br>        }<br> <br>        // Regular char<br>        sb.Append(c);<br>        i++;<br>    }<br>    <br>    // If no comments were stripped, return the exact original DAX (trailing spaces and all)<br>    if (!commentRemoved) <br>    {<br>        return input;<br>    }<br> <br>    // Tidy up ONLY if comments were removed: trim trailing spaces per line &amp; collapse consecutive blank lines<br>    var withoutComments = sb.ToString();<br>    var lines = withoutComments.Replace(&quot;\r\n&quot;, &quot;\n&quot;).Replace(&quot;\r&quot;, &quot;\n&quot;).Split(&#39;\n&#39;);<br>    var outSb = new StringBuilder(withoutComments.Length);<br>    bool lastBlank = false;<br>    bool firstLine = true;<br> <br>    for (int k = 0; k &lt; lines.Length; k++)<br>    {<br>        string line = lines[k].TrimEnd();<br>        bool isBlank = (line.Length == 0);<br> <br>        if (isBlank)<br>        {<br>            if (!lastBlank)<br>            {<br>                if (!firstLine) outSb.Append(&#39;\n&#39;);<br>                lastBlank = true;<br>                firstLine = false;<br>            }<br>        }<br>        else<br>        {<br>            if (!firstLine) outSb.Append(&#39;\n&#39;);<br>            outSb.Append(line);<br>            lastBlank = false;<br>            firstLine = false;<br>        }<br>    }<br> <br>    return outSb.ToString();<br>};<br> <br>// ======================================================================<br>// GATHER TARGET OBJECTS<br>// We use a HashSet to avoid processing the same object twice.<br>// ======================================================================<br> <br>var targetMeasures = new HashSet&lt;Measure&gt;();<br>var targetColumns = new HashSet&lt;CalculatedColumn&gt;();<br> <br>// 1. Add explicitly selected measures &amp; columns<br>foreach (var m in Selected.Measures) targetMeasures.Add(m);<br>foreach (var col in Selected.Columns.OfType&lt;CalculatedColumn&gt;()) targetColumns.Add(col);<br> <br>// 2. Add all measures &amp; columns from explicitly selected tables<br>foreach (var table in Selected.Tables)<br>{<br>    foreach (var m in table.Measures) targetMeasures.Add(m);<br>    foreach (var col in table.Columns.OfType&lt;CalculatedColumn&gt;()) targetColumns.Add(col);<br>}<br> <br>// ======================================================================<br>// PROCESS TARGET OBJECTS<br>// ======================================================================<br> <br>// ---- Process measures ----<br>foreach (var m in targetMeasures)<br>{<br>    var input = m.Expression;<br>    if (string.IsNullOrEmpty(input)) continue;<br> <br>    var cleaned = RemoveComments(input, keepCommentPrefix);<br>    if (input != cleaned)<br>    {<br>        m.Expression = cleaned;<br>        changed++;<br>    }<br>}<br> <br>// ---- Process calculated columns ----<br>foreach (var col in targetColumns)<br>{<br>    var input = col.Expression;<br>    if (string.IsNullOrEmpty(input)) continue;<br> <br>    var cleaned = RemoveComments(input, keepCommentPrefix);<br>    if (input != cleaned)<br>    {<br>        col.Expression = cleaned;<br>        changed++;<br>    }<br>}<br> <br>Info(&quot;Removed comments from &quot; + changed + &quot; object(s).&quot;);</pre><p>The inString flag is the whole trick. Once the parser hits an opening &quot;, everything gets copied through untouched, including a // or /* sitting inside the string, until it finds the matching closing &quot;. It also checks for &quot;&quot;, which is how DAX escapes a literal quote character inside a string, so it doesn&#39;t close the string one character too early on something like &quot;She said &quot;&quot;hello&quot;&quot;&quot;.</p><p>Stripping comments leaves gaps behind: blank lines where a // note used to sit on its own line, trailing spaces where a comment used to trail a code line. The second pass cleans that up, trimming trailing whitespace on every line and collapsing runs of blank lines down to one, so the result reads like a measure written clean rather than one that had text torn out of it.</p><p>It only rewrites m.Expression when the cleaned version actually differs from the original, and keeps a count of how many measures changed. Running it on a model prints something like:</p><pre>Removed comments from 14 measure(s).</pre><p>To use it: open the model in Tabular Editor 2, open the <strong>Advanced Scripting</strong> window, paste the script in, hit run. No selection needed, it walks every measure in the model on its own.</p><h3>What’s still rough</h3><p>Since it writes to m.Expression directly, undo relies entirely on Tabular Editor&#39;s own undo history rather than anything the script itself provides. Worth keeping a saved copy of the model before running it on anything you can&#39;t easily revert.</p><p><em>Originally published at </em><a href="https://www.rodrigoavf.dev/writing/remove-comments-tabular-editor"><em>https://www.rodrigoavf.dev</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a313727e20d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>