Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgX4k-0002rJ-T0 for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Oct 2021 18:58:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mgX4j-0007VC-Ej for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Oct 2021 18:58:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgX4i-0007V3-Oz for pgsql-bugs@lists.postgresql.org; Fri, 29 Oct 2021 18:58:01 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mgX4e-0006MW-5Z for pgsql-bugs@lists.postgresql.org; Fri, 29 Oct 2021 18:57:59 +0000 Received: by mail-pl1-x62a.google.com with SMTP id t21so7409290plr.6 for ; Fri, 29 Oct 2021 11:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=jEKN+wwAaUBO5ICc8f6mLboFrhDMGaGMobo48JJYDMs=; b=KxaDrCxlDe7AVxrsq6dyi0v/Livf2C6JG2Rsf/29x9HkLT5I43bHPBCWpRaOcVcner YljtKfErSK6QxJudUY/vnkN9TKfN7kim42rIA0sVJr4lWfJ4qa6evtkGGTcbxdyH4pkH oJ7CcUUCYD6lHflhc03GMzXJ8OqoTz7J6h+t/PLNRxgE+qPH+xYY/hof/K6gqfjwqb2f 82tcEWHYh6qeXauCILgL40DiZMfo/GY6QrOAx+V2KiEH1CToUh3SixyiYc7P8OeRR8Ub ibflLv3G5NVuqEmoJvLvcSU81mU1IcfwTX3AyBGY5I+Uhu9nXPoJpmfbrb9Li5KiPIcC Df3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=jEKN+wwAaUBO5ICc8f6mLboFrhDMGaGMobo48JJYDMs=; b=PlnyvIkI2w0/TI/7z//85J+BaiH22kTnsQtZoakgW/vffylp+wVfFLZtl7QY9NXYD9 mgP+WKOn46ODSzCsToGIf8c58GNke3IA8L+YkeUnbuNeNW5KGL9OwWgxya8QjjLwFxIo d3UFAVF/29RCOhj79cjEuUgYLCox353+NsWsixda4Xgaqpz1+/L67m6+5HjcebDUcdgR hdSoz/MiR7tpUh9Z+2nsfT2Nopkdgg15yTHXwe+AztDf0Go7e1YcH0Zjfo18laPgThx/ doKCXfvDkyuPI2f+Cxye01cqPOmrwMv1BvSrgxI5TvvhLBLGninLbf3Ojhdv3YztYdiV FNzw== X-Gm-Message-State: AOAM530XrARwLC2HzAstlmIA8d3fv5GCnKSEPNTyCEPsGt9L6X6T6CaU YIM6IoydjkCciNxI215SngnovhTmcHVcRiioK2AQKsmPzgRk7FtpYhkP6pHTJ4cyvKqujw7opCC x5zdxc7zBqCVoqyfK3JMB2UVwvsqa3SQ7qubRouUbAzUwxHT6yT8alRvv8IOW/kRX92BgXC/z1e cI6FtFfiXJFkSZAw9ZXKVCHJFlrEqFWFMPIDel9H+nL5eUhzJqn7v5 X-Google-Smtp-Source: ABdhPJzz3YgXIAn6L9EuyP0YxBQtUm/Bp/deZs6ZC8kTcGgnmKEgDlJZ2xmgvkMeg8HmaKNDcg23ZA== X-Received: by 2002:a17:90b:3b52:: with SMTP id ot18mr13570224pjb.245.1635533872960; Fri, 29 Oct 2021 11:57:52 -0700 (PDT) Received: from laptop280-ma-us.hitronhub.home (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id nu3sm11697169pjb.25.2021.10.29.11.57.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Oct 2021 11:57:52 -0700 (PDT) From: Mark Dilger Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: BUG #17258: Unexpected results in CHAR(1) data type Date: Fri, 29 Oct 2021 11:57:51 -0700 References: <17258-a7c164c5fb955221@postgresql.org> To: david@calascibetta.com, PostgreSQL mailing lists In-Reply-To: <17258-a7c164c5fb955221@postgresql.org> Message-Id: <19D58355-E7C3-47D7-9C87-51EC751AE2BB@enterprisedb.com> X-Mailer: Apple Mail (2.3608.120.23.2.7) X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Oct 29, 2021, at 11:14 AM, PG Bug reporting form = wrote: >=20 > select length(substr(' '::varchar,1,1)), ascii(substr(' =20 > '::varchar,1,1)); > produces=3D=3D> 1 32 (as expected) >=20 > select length(substr(' '::char,1,1)), ascii(substr(' = '::char,1,1)); > produces=3D=3D> 0 0 (not as expected) There are four substr() functions defined in the standard distribution. = They are: substr(text, int4, int4) substr(text, int4) substr(bytea, int4, int4) substr(bytea, int4) There is none defined directly for char(n). Since "text" is the = preferred type (not "bytea"), I expect a cast of your ' '::char to text = before entry to the function. So the question is why casting ' '::char = to text is different than ' '::text. The answer is that cast is = implemented using rtrim1, which trims trailing space. =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company