{"id":3339,"date":"2026-11-28T16:11:23","date_gmt":"2026-11-28T16:11:23","guid":{"rendered":"https:\/\/danieldreitberg.com\/?p=3339"},"modified":"2026-11-28T16:11:23","modified_gmt":"2026-11-28T16:11:23","slug":"dr-ai-b06f6957908ef060aaf5","status":"publish","type":"post","link":"https:\/\/danieldreitberg.com\/index.php\/2026\/11\/28\/dr-ai-b06f6957908ef060aaf5\/","title":{"rendered":"Do Not Treat a Query Copy as a Clone of an Editorial Database"},"content":{"rendered":"<p>An editor creates a local table from an existing query to inspect a set of articles. The result contains the same rows, so a teammate assumes it also inherited the old table\u2019s rules. That assumption can make a working read-only snapshot a poor substitute for the real schema.<\/p>\n<p>Reference: <a href=\"https:\/\/www.sqlite.org\/lang_createtable.html\">SQLite CREATE TABLE<\/a>. SQLite documents when CREATE TABLE AS SELECT creates a table and what it does not bring over.<\/p>\n<h2>Isolate and Inspect Keys<\/h2>\n<p>SQLite\u2019s CREATE TABLE AS SELECT builds a new table from the query result. The created table does not carry over source constraints such as the primary key, and its defaults are not copied as source declarations. Treat that table as a derived set of rows. If the task requires equivalent constraints, define and verify the target schema deliberately before copying data. If the task requires recovery instead, use the project&#8217;s approved backup and restore method. A query result alone does not capture the full database.<\/p>\n<h2>Verify Constraints Separately<\/h2>\n<p>In an isolated fictional database, create a source table with a documented key and a required title. Copy its rows into a separate test table through a query. Confirm the copied values and inspect the new schema separately. In that test copy, try a duplicate key value or a null title under controlled conditions. The copy can accept data the source would reject because it did not receive the source constraints. Verify that nothing in the production database was changed during the exercise.<\/p>\n<p>Record what the snapshot is for and which properties it lacks. An assistant can summarize its rows without representing it as a validated replacement for the source.<\/p>\n<p>Include a check of defaults and data types if a later task will write to the derived table.<\/p>\n<p>Give the snapshot a name that conveys its scope and date. That reduces the chance that a later query mistakenly treats it as the maintained source.<\/p>\n<p><!-- drai-run:b06f6957908ef060aaf5 --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating a table from a query can give you a useful snapshot without the source constraints.<\/p>\n","protected":false},"author":5,"featured_media":3340,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts\/3339"}],"collection":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/comments?post=3339"}],"version-history":[{"count":1,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts\/3339\/revisions"}],"predecessor-version":[{"id":3341,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts\/3339\/revisions\/3341"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/media\/3340"}],"wp:attachment":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/media?parent=3339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/categories?post=3339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/tags?post=3339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}