Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vst8i-006g6M-2v for pgsql-admin@arkaria.postgresql.org; Thu, 19 Feb 2026 01:47:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vst8g-001GSP-0D for pgsql-admin@arkaria.postgresql.org; Thu, 19 Feb 2026 01:47:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vst8f-001GSH-25 for pgsql-admin@lists.postgresql.org; Thu, 19 Feb 2026 01:47:33 +0000 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vst8c-000000004D1-2HPL for pgsql-admin@lists.postgresql.org; Thu, 19 Feb 2026 01:47:33 +0000 Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-89577f866d6so6508836d6.0 for ; Wed, 18 Feb 2026 17:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771465649; x=1772070449; darn=lists.postgresql.org; h=to:message-id:subject:date:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=Yaxl5ir6YQYPLcF6r2VlgJRTHrEIqelWdR84ATRBQ+k=; b=QXsmMv6T01jC7xzSglz/IUalf/RhSD3+QiClP7epYJt4pbiWz/6/9Argx9tj+rzSU3 WEjZxI3cnLYnKQldOK1HZDghYXFN27fOS3yf7iWDgoleCtse0CLW3ivJWFyon2iautxD t6U/CKGaaGVYHokDjeC31UDSD1NXJm0/+wIur6KYedHpvbLfyfv/H49Hzfqg/vxdsm/8 9DjulZWJusw9cSgJBtl2CoRl1q/paDCZjJugTOU0tSGkNAYKmY7elNDQSMA1Phn9HkIg +g9GRQWLgQLwwpZ8cD4bnzF2oAPSNKiHO1plS1uEK0QKqVHNJTheoS4f8coR6ULtRhX1 k9Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771465649; x=1772070449; h=to:message-id:subject:date:mime-version:content-transfer-encoding :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Yaxl5ir6YQYPLcF6r2VlgJRTHrEIqelWdR84ATRBQ+k=; b=jI5kqiYkAtv6HkLNVFimZprD4Vz/O5+8tuvgRwtAf4XoyMOednyak0by5L54H0TPZC rBJoZq0tm5Oeiui1eAnVnjA2kGUvLXKPwly2s243QML5UJVQ8ap38arXyqrYzVAVq59V kf19f7j6gKKrmD5gJkPe0NXbXdpGQ+RDwFRdBdrrWtWYYwqf0qUtINig3MOnz2kfMprP dO2qhNPRfc2iIZCpsTsKUIPub0vQWjb9JFZ7/sx6gqUGDpQN5XVSQYP1UdhXYhAqmZTS GDOOKteMpe9NKTFwIp/CJl5HBSuJ+kAxBRARIxung+jULrA3wc7KE1+IMmTvICZqY8CO 9lQQ== X-Gm-Message-State: AOJu0YyKMeLmOGifxNz/rvcgJh7QobF3rWai5foNAYKUNg0rQ9HR+Iwg vf/1h7OwKnHJj+7rEwa1b9M1kFlRe45ZHi4dafZ9/Kruo4Z2dfEP3zDUhs69tA== X-Gm-Gg: AZuq6aLu8NPt2iXpX8ew9brG57Nuai9Fy9D8RBSiLUbcpd7AZhShfs/eBi5jAQinMbc gKsrLeV5bKEVG2GXArRklx+bM4qzwbiy15SyUCkSEap9PNGiJOEBFZzccmDE+N8DcGU7PDLRFos HjyJ6DCM7beNHlLKPYd0jbLEwEsyfB6Yal8CG/Uo/xMqcfda56zheKorOpFnst14YQCJCIyZBZK QMYKPh/Ognd6RJUx/kHfBJlPfFz8E/xO2MLQg8ooBH+sOqn+15SO5vsOup8kaI24wxmXZUTZIAP SCHWgb84QpTy4WSRo2u+uLp4dplGA2hhe5YMfoDYsWqQd50pHZ4jRGgaoFAhiDITtnH8SP8jNmb 33gEF0netMuw8Cnc6INcGndFQqIFfQpHpFU2ofvbUO8xcNIzFR153Aw4IwPyhC5wuxzR0dFWZa4 Z1oWWS/gR9IOKAMHcEW0SQw4gfpJ9DgfdevPTXQ7dEGRgeNBLd00qPPd0E909ZXtLdl2uP2qpy7 1+2B21CVYJPBSpgGWYQ6mMrlAEDkQ== X-Received: by 2002:a05:6214:5187:b0:894:5d38:2e38 with SMTP id 6a1803df08f44-89965b454femr3749306d6.18.1771465649223; Wed, 18 Feb 2026 17:47:29 -0800 (PST) Received: from ?IPv6:2601:14b:4100:214f:f0d6:b323:7a31:b1b2? ([2601:14b:4100:214f:f0d6:b323:7a31:b1b2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8971cc7f82csm204886846d6.4.2026.02.18.17.47.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Feb 2026 17:47:28 -0800 (PST) From: Ed Sabol Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.7\)) Date: Wed, 18 Feb 2026 20:47:27 -0500 Subject: Duplicate key value violates unique constraint "pg_type_typname_nsp_index" error Message-Id: <1D3D88D6-5E8C-4144-BF79-DB531FE4FE39@gmail.com> To: Pgsql-admin X-Mailer: Apple Mail (2.3445.9.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Using PostgreSQL 15.16, I have some SQL for creating a materialized view = that's inside a larger transaction which randomly emits the following = error: ERROR: duplicate key value violates unique constraint = "pg_type_typname_nsp_index" DETAIL: Key (typname, typnamespace)=3D(largetable, 20488) already = exists. The error doesn't happen 100% of the times I try to execute this = transaction. Maybe 30% of the time? Also, I've had it happen on multiple = separate PostgreSQL servers. I'm not entirely sure how to interpret these ERROR and DETAIL messages. = Can someone explain it? I've tried the following queries to try to figure out what typnamespace = =3D 20488 refers to: SELECT nspname FROM pg_namespace WHERE oid =3D 20488; SELECT count(*) FROM pg_catalog.pg_type WHERE typname =3D 'targetable' = AND typnamespace =3D 20488; Neither query provides any useful information. The latter always returns = zero immediately immediately prior to the SQL error. Here's the (slightly sanitized) SQL which causes the error: CREATE MATERIALIZED VIEW someschema.largetable AS ( SELECT=20 row_number() OVER () AS __row, sub.*, public.somefunc1(afield) AS s_result1, public.somefunc2(anotherfield) AS s_result2, public.somefunc3(somefield1, somefield2) AS s_result3 FROM ( SELECT * FROM someschema.largetable_upd_1 UNION ALL SELECT * FROM someschema.largetable_upd_2 UNION ALL SELECT * FROM someschema.largetable_upd_3 UNION ALL SELECT * FROM someschema.largetable_upd_4 UNION ALL SELECT * FROM someschema.largetable_upd_5 UNION ALL SELECT * FROM someschema.largetable_upd_6 UNION ALL SELECT * FROM someschema.largetable_upd_8 UNION ALL SELECT * FROM someschema.largetable_upd_9 UNION ALL SELECT * FROM someschema.largetable_upd_10 ) sub ); public.somefunc1, public.somefunc2, and public.somefunc3 return three = types defined in PgSphere. I have the latest PgSphere installed. Any ideas as to how to eliminate the error? My first thought was to change the asterisks to explicit lists of = columns. Any assistance would be appreciated! Thanks, Ed