<?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"><channel><title><![CDATA[SqlOtter | SQL and Database Workflows]]></title><description><![CDATA[SqlOtter | SQL and Database Workflows]]></description><link>https://sqlotter.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 00:16:32 GMT</lastBuildDate><atom:link href="https://sqlotter.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[PostgreSQL NOT NULL Check: Count Existing NULLs Before a Schema Change]]></title><description><![CDATA[Before adding a PostgreSQL NOT NULL constraint, count NULLs across the full table with SQL. SqlOtter Column Statistics helps inspect selected or loaded…]]></description><link>https://sqlotter.hashnode.dev/postgresql-not-null-check-count-existing-nulls-before-a-schema-change</link><guid isPermaLink="true">https://sqlotter.hashnode.dev/postgresql-not-null-check-count-existing-nulls-before-a-schema-change</guid><category><![CDATA[SqlOtter]]></category><category><![CDATA[PostgreSQL]]></category><dc:creator><![CDATA[SqlOtter]]></dc:creator><pubDate>Fri, 04 Dec 2026 01:53:02 GMT</pubDate><content:encoded><![CDATA[<p>Before adding a PostgreSQL NOT NULL constraint, count every NULL in the target column with SQL. SqlOtter's Column Statistics panel can quickly inspect the selected rows or rows currently loaded in the table grid, but that view is not a whole-table preflight. Use both views for their proper jobs: inspect a sample in the UI, then run a full-table query before changing the schema.</p>
<h2>1. Count NULL values across the full PostgreSQL table</h2>
<p>For example, before requiring every customer to have an email address:</p>
<pre><code class="language-sql">SELECT COUNT(*) AS null_count
FROM public.customer
WHERE email IS NULL;
</code></pre>
<p>If the result is greater than zero, identify a valid cleanup or backfill rule before adding the constraint. Do not replace missing values with a placeholder unless that value is valid for your application.</p>
<p>For a large production table, consider the scan cost, locking behavior, deployment sequence, and rollback plan for your PostgreSQL version. Apply the constraint only after the data and operational plan are ready.</p>
<h2>2. Inspect the current table view in SqlOtter</h2>
<ol>
<li>Connect to the intended PostgreSQL database and open the target table's <strong>Table Content</strong> view.</li>
<li>Select the rows you want to inspect, or clear the selection to use the rows currently loaded in the grid.</li>
<li>Right-click the target column header and choose <strong>Column Statistics</strong>.</li>
<li>Check <strong>NULL Count</strong> and <strong>NULL</strong> percentage, and confirm which column and record scope the panel reports.</li>
</ol>
<p><img src="https://www.sqlotter.com/assets/product-screenshots/table-data/column-statistics-detail.webp" alt="SqlOtter Column Statistics panel with count, distinct count, NULL count and numeric summary for three selected rows" /></p>
<p><em>The published SqlOtter example shows statistics for three selected rows. The values describe that selection, not the full table or all rows in a paged result.</em></p>
<h2>3. Verify with SQL before the schema change</h2>
<p>The UI statistics help inspect the current grid. For a definitive PostgreSQL preflight, run the COUNT query against the full table and review the returned count. After a valid cleanup, check again; only then plan the constraint migration.</p>
<p>SqlOtter's Table Content tools and Column Statistics are documented here: <a href="https://www.sqlotter.com/#/docs/table-data/column-statistics">PostgreSQL table data and column statistics in SqlOtter</a>. Explore the product at <a href="https://www.sqlotter.com/">SqlOtter</a>.</p>
<p><strong>Disclosure:</strong> This article is published by the SqlOtter project team.</p>
<p>Tags: SqlOtter, PostgreSQL, SQL, Database</p>
]]></content:encoded></item><item><title><![CDATA[Turn a Few PostgreSQL Rows into a Test Fixture with INSERT SQL]]></title><description><![CDATA[Copy selected PostgreSQL rows as INSERT SQL, then test NULL and empty values safely in a temporary fixture.]]></description><link>https://sqlotter.hashnode.dev/turn-a-few-postgresql-rows-into-a-test-fixture-with-insert-sql</link><guid isPermaLink="true">https://sqlotter.hashnode.dev/turn-a-few-postgresql-rows-into-a-test-fixture-with-insert-sql</guid><category><![CDATA[SqlOtter]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[SQL]]></category><dc:creator><![CDATA[SqlOtter]]></dc:creator><pubDate>Thu, 03 Dec 2026 02:15:55 GMT</pubDate><content:encoded><![CDATA[<p>When a bug depends on two or three rows, a small reproducible fixture is easier to review than a whole dump. Select the relevant rows in a table grid, copy them as INSERT SQL, then retarget the statement to a disposable PostgreSQL table. Check the target, explicit columns, NULL values, and primary keys before reusing it.</p>
<h2>Copy only the rows that reproduce the issue</h2>
<p>In the SqlOtter table grid, select the relevant rows, right-click, and choose <strong>Copy INSERT Statement</strong> when that action is available. Paste the generated statement into a scratch editor and inspect its columns and values. Copying does not write to the database.</p>
<p><img src="https://www.sqlotter.com/assets/product-screenshots/table-data/copy-values-menu.webp" alt="SqlOtter table grid with selected rows and Copy INSERT Statement visible in its context menu" /></p>
<p>This historical MySQL screenshot shows where the command appears. The SQL below is a separate PostgreSQL example using synthetic values. Remove personal data before sharing a fixture or bug report.</p>
<h2>Test NULL versus an empty string safely</h2>
<p>Suppose an application treats a missing note and an empty note as the same value. The nullable note column should preserve that difference. Run this example in one session on a test connection:</p>
<pre><code class="language-sql">BEGIN;
CREATE TEMP TABLE order_fixture (
    id integer PRIMARY KEY,
    status text NOT NULL,
    note text
);
INSERT INTO pg_temp.order_fixture (id, status, note) VALUES
    (101, 'pending', NULL),
    (102, 'pending', '');

SELECT id, note IS NULL AS missing, length(note) AS note_length
FROM pg_temp.order_fixture
ORDER BY id;
ROLLBACK;
</code></pre>
<p>Row 101 returns missing = true and note_length = NULL. Row 102 returns missing = false and note_length = 0. The explicit pg_temp target keeps the insert and verification query pointed at the temporary fixture; ROLLBACK removes it.</p>
<p>Before reusing copied SQL, check for duplicate primary keys and generated or identity columns. An omitted column can receive its default; an explicit NULL is still supplied. When copying between database engines, review quoting, literals, and engine-specific syntax.</p>
<p>Disclosure: this article is published by the SqlOtter project account.</p>
<p><a href="https://www.sqlotter.com/#/docs/table-data/copy-values">SqlOtter copy actions</a> · <a href="https://www.postgresql.org/docs/16/sql-insert.html">PostgreSQL INSERT</a> · <a href="https://www.postgresql.org/docs/16/sql-createtable.html">PostgreSQL CREATE TABLE</a></p>
]]></content:encoded></item><item><title><![CDATA[Preview PostgreSQL Table Renames Before Running ALTER TABLE]]></title><description><![CDATA[Preview PostgreSQL table renames with a read-only query. Check duplicate targets, existing names, identifier length, and the SqlOtter mapping.]]></description><link>https://sqlotter.hashnode.dev/preview-postgresql-table-renames-before-running-alter-table</link><guid isPermaLink="true">https://sqlotter.hashnode.dev/preview-postgresql-table-renames-before-running-alter-table</guid><category><![CDATA[PostgreSQL]]></category><category><![CDATA[SQL]]></category><dc:creator><![CDATA[SqlOtter]]></dc:creator><pubDate>Wed, 02 Dec 2026 03:15:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0a45eb4338ea63448ab00b/dcd246c8-a6fc-4a6c-b674-bf50477ba7a2.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When a batch rename replaces text in table names, preview each old and new name before executing DDL. Two source names can map to the same destination. A destination may also belong to a relation you did not select. This read-only PostgreSQL check surfaces both cases.</p>
<h2>Build the rename list with SELECT</h2>
<p>This example targets the <code>staging</code> schema and replaces every literal occurrence of <code>test</code> with <code>copy</code>. Start with the names you intend to rename, using the exact case shown in the object tree.</p>
<pre><code class="language-sql">WITH selected(old_name) AS (
    VALUES ('test_orders'), ('test_payments'), ('test_test_labels')
), proposed AS (
    SELECT old_name, replace(old_name, 'test', 'copy') AS new_name
    FROM selected
), counted AS (
    SELECT *, count(*) OVER (PARTITION BY new_name) AS target_count
    FROM proposed
)
SELECT old_name, new_name,
       CASE
           WHEN old_name = new_name THEN 'unchanged'
           WHEN new_name = '' THEN 'empty name'
           WHEN octet_length(new_name) &gt; current_setting('max_identifier_length')::int
               THEN 'name too long'
           WHEN target_count &gt; 1 THEN 'duplicate target'
           WHEN EXISTS (
               SELECT 1
               FROM pg_catalog.pg_class AS c
               JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
               WHERE n.nspname = 'staging' AND c.relname = counted.new_name
           ) THEN 'target already exists'
           ELSE 'check source and dependencies'
       END AS review
FROM counted
ORDER BY old_name;
</code></pre>
<p>In this example, <code>test_test_labels</code> maps to <code>copy_copy_labels</code>. If <code>staging.copy_orders</code> already exists, the <code>test_orders</code> row is flagged. The query treats any occupied target as a collision. If your plan depends on freeing a name first, review the operation order separately. Check that every source exists, then look for application queries and scheduled jobs that refer to the old names. The catalog check is a point-in-time observation.</p>
<h2>Check the same mapping visually in SqlOtter</h2>
<p>I work on SqlOtter. In the object tree, select the intended tables in the same database and schema, open <strong>Rename Table</strong>, then choose <strong>Find and replace</strong>. Enter <code>test</code> and <code>copy</code>, and compare <strong>Original name</strong> and <strong>New name</strong> for every row. The screen highlights the matching text in yellow and the replacement in green. Use the mapping to review the scope before clicking <strong>OK</strong>.</p>
<p><img src="https://www.sqlotter.com/assets/product-screenshots/table-structure/batch-rename-tables.png" alt="Official SqlOtter screenshot of the batch rename preview" /></p>
<p>The screenshot uses sample names and shows the preview before submitting. SqlOtter runs the selected renames in sequence. If a rename fails partway through, refresh the same schema and inspect which names changed before retrying. The SQL above only previews candidate names. It issues no ALTER TABLE statements.</p>
<p><a href="https://www.postgresql.org/docs/current/sql-syntax-lexical.html">PostgreSQL identifier rules</a> · <a href="https://www.postgresql.org/docs/current/catalog-pg-class.html">PostgreSQL pg_class</a> · <a href="https://www.sqlotter.com/#/docs/table-structure/rename-tables">SqlOtter rename guide</a></p>
]]></content:encoded></item><item><title><![CDATA[PostgreSQL JSONB: Tell a Missing Key from JSON null]]></title><description><![CDATA[Use PostgreSQL’s JSONB path operator and jsonb_typeof() to distinguish a missing key, JSON null, and the string "null" in five example rows.]]></description><link>https://sqlotter.hashnode.dev/postgresql-jsonb-tell-a-missing-key-from-json-null</link><guid isPermaLink="true">https://sqlotter.hashnode.dev/postgresql-jsonb-tell-a-missing-key-from-json-null</guid><category><![CDATA[PostgreSQL]]></category><category><![CDATA[SQL]]></category><dc:creator><![CDATA[SqlOtter]]></dc:creator><pubDate>Tue, 01 Dec 2026 14:11:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0a45eb4338ea63448ab00b/492181fb-488c-4583-affd-c80a2404f79d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When a PostgreSQL JSONB field contains an explicit <code>null</code>, <code>#&gt;&gt;</code> produces the same SQL <code>NULL</code> you get from a missing path. To tell them apart, keep the extracted value as JSONB with <code>#&gt;</code> and check it with <code>jsonb_typeof()</code>.</p>
<p>Imagine you are reviewing a retry log. If the <code>request</code> object is present, an absent <code>retry</code> key and an explicitly null <code>retry</code> key tell you different things about what the producer sent. An event whose <code>request</code> is a string needs a separate shape check.</p>
<h2>Show the original payload beside both extractions</h2>
<p>This query uses synthetic records and reads only the rows defined in the query.</p>
<pre><code class="language-sql">WITH sample(id, payload) AS (
    VALUES
        (1, '{"request":{"retry":2}}'::jsonb),
        (2, '{"request":{"retry":null}}'::jsonb),
        (3, '{"request":{}}'::jsonb),
        (4, '{"request":{"retry":"null"}}'::jsonb),
        (5, '{"request":"unavailable"}'::jsonb)
)
SELECT id,
       payload,
       payload #&gt;&gt; '{request,retry}' AS retry_text,
       jsonb_typeof(payload #&gt; '{request,retry}') AS retry_json_type,
       CASE
         WHEN jsonb_typeof(payload -&gt; 'request') IS DISTINCT FROM 'object'
           THEN 'request is missing or not an object'
         WHEN (payload #&gt; '{request,retry}') IS NULL THEN 'missing key'
         WHEN jsonb_typeof(payload #&gt; '{request,retry}') = 'null' THEN 'JSON null'
         ELSE 'has value'
       END AS retry_state
FROM sample
ORDER BY id;
</code></pre>
<p>Check these values in the result grid:</p>
<table>
<thead>
<tr>
<th><code>id</code></th>
<th><code>retry_text</code></th>
<th><code>retry_json_type</code></th>
<th><code>retry_state</code></th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Text <code>2</code></td>
<td>Text <code>number</code></td>
<td><code>has value</code></td>
</tr>
<tr>
<td>2</td>
<td>SQL <code>NULL</code></td>
<td>Text <code>null</code></td>
<td><code>JSON null</code></td>
</tr>
<tr>
<td>3</td>
<td>SQL <code>NULL</code></td>
<td>SQL <code>NULL</code></td>
<td><code>missing key</code></td>
</tr>
<tr>
<td>4</td>
<td>Text <code>null</code></td>
<td>Text <code>string</code></td>
<td><code>has value</code></td>
</tr>
<tr>
<td>5</td>
<td>SQL <code>NULL</code></td>
<td>SQL <code>NULL</code></td>
<td><code>request is missing or not an object</code></td>
</tr>
</tbody></table>
<p>Rows 3 and 5 look identical in the two extraction columns. The parent check keeps a malformed <code>request</code> out of the missing-<code>retry</code> count. If a SQL <code>NULL</code> payload needs a separate label in your audit, check <code>payload IS NULL</code> before the parent check.</p>
<h2>Inspect one unexpected row in the grid</h2>
<p>For a single complex record, find that row in its source table by its identifier. In SqlOtter, the desktop database client we build, open the selected cell’s field editor. If it offers <strong>Edit Mode → JSON Mode</strong>, switch to it and expand <code>request</code> to see whether <code>retry</code> is absent, <code>null</code>, or the string <code>"null"</code>. Close with <strong>Cancel</strong> when you only need to inspect it. The editor entry depends on the build, field type, and permissions. Use the SQL query to classify rows in bulk.</p>
<p><a href="https://www.postgresql.org/docs/current/functions-json.html">PostgreSQL JSON functions and operators</a> · <a href="https://github.com/superadmini/SqlOtter/blob/main/postgresql-jsonb-field-inspection.md">SqlOtter field editor walkthrough</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Find Text in a SQL Table Grid with SqlOtter]]></title><description><![CDATA[Find text in a loaded SQL table grid with SqlOtter. Pin a keyword, jump between highlighted matches, and locate them with scrollbar markers.]]></description><link>https://sqlotter.hashnode.dev/how-to-find-text-in-a-sql-table-grid-with-sqlotter</link><guid isPermaLink="true">https://sqlotter.hashnode.dev/how-to-find-text-in-a-sql-table-grid-with-sqlotter</guid><dc:creator><![CDATA[SqlOtter]]></dc:creator><pubDate>Sat, 28 Nov 2026 03:15:11 GMT</pubDate><content:encoded><![CDATA[<p>If a database table is already open and you need to find a value such as <strong>pdf</strong>, open <strong>Table Content</strong> in SqlOtter and type it into <strong>Content Filter</strong>. The desktop database client highlights matching cells in the loaded grid so you can inspect them in place.</p>
<h2>Pin a keyword and jump between matches</h2>
<ol>
<li>Type <code>pdf</code> in <strong>Content Filter</strong>. With the history dropdown closed, press <strong>Enter</strong> to pin the keyword. If Enter selected a history entry, press Enter again after the dropdown closes.</li>
<li>Click the keyword tag to move to the next match. Use <strong>Ctrl-click</strong> on Windows or Linux, or <strong>Command-click</strong> on macOS, to move to the previous match.</li>
<li>Read the tag as current match / total matching cells. In this example, <code>pdf (2/2)</code> means the second of two matching cells is selected.</li>
</ol>
<p><img src="https://www.sqlotter.com/assets/product-screenshots/table-data/content-highlights-matches.webp?v=20261108-reviewed-artwork2" alt="SqlOtter Content Filter highlighting two cells with the pdf keyword" /></p>
<h2>Locate matches in a long grid</h2>
<p>Look for colored markers along the right-hand scrollbar. They show where matches sit on the loaded page. Click a marker to jump to its match. Multiple matches on one row can share a marker.</p>
<p><img src="https://www.sqlotter.com/assets/product-screenshots/table-data/content-highlights-overlay.webp?v=20261108-reviewed-artwork2" alt="Annotated SqlOtter screenshot showing two scrollbar markers" /></p>
<p><em>The red annotation points to the markers in a historical product screenshot. Some icons have since changed.</em></p>
<h2>Which rows are searched?</h2>
<p>Content Filter searches text in the cells already loaded in the grid. Use <strong>SQL Query Filter</strong> when you need the database to return a narrower set of records.</p>
<p>Published by the SqlOtter project. <a href="https://www.sqlotter.com/#/docs/table-data/content-highlights">Official guide</a> · <a href="https://youtu.be/ZbflsvSdaUA">47-second walkthrough</a></p>
]]></content:encoded></item></channel></rss>