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 1q6ZoW-0006SX-0l for pgsql-docs@arkaria.postgresql.org; Tue, 06 Jun 2023 16:45:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q6ZoU-00057i-Li for pgsql-docs@arkaria.postgresql.org; Tue, 06 Jun 2023 16:45:42 +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 1q6ZoU-00057V-9v for pgsql-docs@lists.postgresql.org; Tue, 06 Jun 2023 16:45:42 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q6ZoR-000cCS-0Y for pgsql-docs@lists.postgresql.org; Tue, 06 Jun 2023 16:45:41 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-97000a039b2so1015471366b.2 for ; Tue, 06 Jun 2023 09:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20221208.gappssmtp.com; s=20221208; t=1686069938; x=1688661938; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CXjBURhU8OYWcANY0Nd/iQhlo00YAThexMzKOdctWvw=; b=CxsM1CMOcxoSf5quNAjcHsFEdtt1XDsHYBxNDGMLaxvjLCO3pvoIonrFGCmmNe967B 6EJ+qTVgjS2Qa3fh007ng33MaSbGfnOIsKByB4uzZDb4qdAwZBcAn33GY+IlLOD+5w8d b0grN4M0LSBw74mgwLXH0y7yLj0co2uCTXiBA971KyCZFhC19XdF+Ic3HxOtg3wh0sx+ SwtBpU+ADk/d2TG1oQbfjXNo6sDCCA3o6yix8u+Ecxw/CffrRZYLIwlCxi8lfDe3tCbA dbyYgz1SEnTS4xZ2Ikd6zb3XlN8eMzK5L96/Z/EprEuKBnu/tn3cKdWnrheaY5NmPv1m vPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686069938; x=1688661938; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CXjBURhU8OYWcANY0Nd/iQhlo00YAThexMzKOdctWvw=; b=eW8s+NQla8APPo6TXrs+e3QQVRkkLHdECaKJVj7nTOv6EGY1h5C4VN83pzYlNHB85F WnujciS4PDOCEqVeVGqq8wLzswxgNcM3hdIJapaplBDkCkiPkuE1PN5IfxeEkABA0OwB OTATfbAkEi8gjamAuzTnI/Z1yDEi4Clgckbn8gxrLZ6Aps/LLGafffuAyLvhHTYNyOAg w0GOgw8lWQ0SdIbOVFF4vcitKQvqDV+TptRD0/dZQ8MHoJclAEr1rr6KB5uIWgFlR+Ns R6xW3nNmBf8QCW11zZGWQ7egRLZIe9mvzizlPF9rsacZabKWkry6LQFCxMW9fQsQRo6G HUAQ== X-Gm-Message-State: AC+VfDz6MAkrM1XRG9YPrlwoPnX8OIvJ0IVyBcnPcy973lybVr8mWjZM PJHVzmvaTy6hhU8dD6qZWjHhWA== X-Google-Smtp-Source: ACHHUZ56oDi6JAUz2s3ywvOsXNmkjbnoh33izEUgh1XiB98onXyNI0rnAr7e2vA7km7XGkbG1Lwnkg== X-Received: by 2002:a17:907:6d8a:b0:973:ae80:a145 with SMTP id sb10-20020a1709076d8a00b00973ae80a145mr3660871ejc.43.1686069937957; Tue, 06 Jun 2023 09:45:37 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:379e:8bed:2c85:e152:bc3a]) by smtp.gmail.com with ESMTPSA id ci17-20020a170906c35100b009787ad3157bsm1392ejb.39.2023.06.06.09.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 09:45:37 -0700 (PDT) Message-ID: <35ea9d87b9d1d9715989e00afba1aad75b5b0931.camel@cybertec.at> Subject: Re: bpchar datatype is not equal to character(1) data type From: Laurenz Albe To: yanliang lei , pgsql-docs@lists.postgresql.org Date: Tue, 06 Jun 2023 18:45:37 +0200 In-Reply-To: <5ec1dd7b.54a7.188911e35c3.Coremail.msdnchina@163.com> References: <5ec1dd7b.54a7.188911e35c3.Coremail.msdnchina@163.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2023-06-06 at 22:30 +0800, yanliang lei wrote: > in the documents (https://www.postgresql.org/docs/current/typeconv-query.= html),there is the following descrition: > =E2=80=9Cblank-padded char=E2=80=9D, the internal name of the character d= ata type. > =3D=3D=3D>>so bpchar datatype is equal to character data type >=20 > in the documents (https://www.postgresql.org/docs/15/datatype-character.h= tml),there is the following descrition: > =C2=A0character without length specifier is equivalent to character(1). > =3D=3D=3D>>so character data type is equal to character(1) data type >=20 > Based on the above description, there is a deduction as follows: > =C2=A0bpchar datatype is equal to character(1) data type >=20 > but the following test tells us that:=C2=A0 bpchar datatype is=C2=A0 not = equal to character(1) data type. > I want to know why? Maybe the document has error? > > [...] > > postgres=3D# create table xxx3(c1 bpchar,c2 int); > CREATE TABLE > postgres=3D# insert into xxx3 values('aaaaa',1); > INSERT 0 1 > postgres=3D# \d+ xxx3; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Table "public.xxx3" > =C2=A0Column |=C2=A0 Type=C2=A0 =C2=A0| Collation | Nullable | Default | = Storage=C2=A0 | Compression | Stats target | Description=C2=A0 > --------+---------+-----------+----------+---------+----------+----------= ---+--------------+------------- > =C2=A0c1=C2=A0 =C2=A0 =C2=A0| bpchar=C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0| extended |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 > =C2=A0c2=C2=A0 =C2=A0 =C2=A0| integer |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0| plain=C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 > Access method: heap >=20 > postgres=3D# select * from xxx3; <<<<----please note this result. > =C2=A0 c1=C2=A0 =C2=A0| c2=C2=A0 > -------+---- > =C2=A0aaaaa |=C2=A0 1 > (1 row) There is some special case code in "gram.y" that treats column definitions = of CHAR or BIT special, since the standard requires that that means a length o= f 1. See the following source comment: /* We have a separate ConstTypename to allow defaulting fixed-length * types such as CHAR() and BIT() to an unspecified length. * SQL9x requires that these default to a length of one, but this * makes no sense for constructs like CHAR 'hi' and BIT '0101', * where there is an obvious better choice to make. * Note that ConstInterval is not included here since it must * be pushed up higher in the rules to accommodate the postfix * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle * the generic-type-name case in AexprConst to avoid premature * reduce/reduce conflicts against function names. */ So the standard demands that behavior for CHAR or BIT, but it does not define the behavior of "bpchar", so we have no special case code for that. If you read the documentation carefully, it says that "bpchar is the intern= al name of the character data type", but it doesn't say that the behave identi= cal. "bpchar" is not even mentioned in https://www.postgresql.org/docs/current/datatype-character.html , so I think it is OK to consider it an internal thing that should not be use= d by users directly. I think that there is no need to document that small behavior difference. Yours, Laurenz Albe