Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eq6X3-0000Ws-4o for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Feb 2018 00:20:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eq6X0-000596-8L for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Feb 2018 00:20:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eq6Wz-00058x-Q7 for pgsql-bugs@lists.postgresql.org; Mon, 26 Feb 2018 00:20:38 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eq6Wv-0006xh-D5 for pgsql-bugs@lists.postgresql.org; Mon, 26 Feb 2018 00:20:36 +0000 Received: by mail-wm0-x244.google.com with SMTP id 139so876794wmn.2 for ; Sun, 25 Feb 2018 16:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=pRU2LTn1wHbVC7mGJ6PX1aR2f6T9dBEMe1/NWZ+jgJ8=; b=Bl7Bz/oLottH2HLkGez44YsgDIsRc2fCSupGCilvmBAGLva4TlNELrL4bLkX2JA+M0 nwwzPLpkv+Yj7n6CUVZlwuQj7LZ+Mk2yAedZZcH8LJjIHjzPJBIkTjTTrtF8zLhtkQm9 KLGhuJbIGvR178BP17EcF78euC8hMRMRH4/JQV/hCuACd058gg7KVGIhPDOYasoBUW2/ lrNXvkApDQUB6JD1FWcDh4JDV+JV2jgUt/nBuU0I9BOSP/02j4FVCferfKZQMoRDMB7W 2DC6SwV25c2+MWS15Zr/2PMAV1Hdepi+J6m57gZebfLG5KOJU+1u4Eo17MMS0MIs8un7 Dlyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=pRU2LTn1wHbVC7mGJ6PX1aR2f6T9dBEMe1/NWZ+jgJ8=; b=ViOBPuUudqS25zjuW2bSg11y0GGAPTrAxxq7uL4V7kxw8esYZBxY8WhXJ7f3OfD9Z4 W/XUr8JcYtOzBfrK4lh5/ljqc32ErRZ0wnBOvwaBXLb+/0vYQSfIeFVHRZMtWtNdGVec mh84OwU7DjtoOTY/EyClg3zMnn7wSnIskbgMk/lh8O1PdyGB6RGg9UNG0sRlHdI7/JQ+ Bt+FfpL5751pZ9j3TX7ZsCGWj1pYcE2Rfje3DNT6+rDOak9MrWZpKrn71oMh4q6/0xwH AT5nGQUGKVrvA1cSGglDzsQzXvjRSO1szGDJxXMKmlnpZeyw58xf7SeURmoChhKdNIup CLYg== X-Gm-Message-State: APf1xPBaIokzzVRU5msg0AyLIj3adHr20i6CmBSLUjE2oJ5TO1Jc0+uu OV7ur2T07+U+aRbtW3zz4iLOOg== X-Google-Smtp-Source: AG47ELua14iRlggOvgOi7lfeHbI+3b/DAbDMGwpDC8TYdJM4Oz7+FOjRSaXFW7q0vLOH6CNKggfF9Q== X-Received: by 10.28.10.206 with SMTP id 197mr6652659wmk.61.1519604429951; Sun, 25 Feb 2018 16:20:29 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id q186sm8009058wmb.33.2018.02.25.16.20.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Feb 2018 16:20:29 -0800 (PST) Subject: Re: BUG #15087: ALTER INDEX RENAME renames table if matches To: etolnay@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <151960070775.21248.1471444285595717214@wrigleys.postgresql.org> From: Tomas Vondra Message-ID: <3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com> Date: Mon, 26 Feb 2018 01:20:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <151960070775.21248.1471444285595717214@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/26/2018 12:18 AM, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 15087 > Logged by: Ezequiel Tolnay > Email address: etolnay@gmail.com > PostgreSQL version: 10.0 > Operating system: Windows 10 > Description: > > A table name mytable can be renamed to newtable via: > > ALTER INDEX mytable RENAME TO newtable > > This is probably incorrect. It should either raise an error (as it does with > ALTER TABLE if the name supplied is that of an index), or better, when > specified IF EXISTS, simply do nothing. > Hmmm, I agree that seems suspicious and surprising. But looking at the code, I see that RangeVarCallbackForAlterRelation does this: /* * For compatibility with prior releases, we allow ALTER TABLE to * be used with most other types of relations (but not composite * types). We allow similar flexibility for ALTER INDEX in the case * of RENAME, but not otherwise. Otherwise, the user must select * the correct form of the command for the relation at issue. */ ... /* * Don't allow ALTER TABLE on composite types. We want people to * use ALTER TYPE for that. */ if (reltype != OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is a composite type", rv->relname), errhint("Use ALTER TYPE instead."))); So the behavior seems intentional, because of backwards compatibility. I personally wouldn't mind changing it - it certainly seems surprising, and singling out RENAME seems strange. But maybe it'd break more things than I imagine. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services