pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Doc comments form <noreply@postgresql.org>
To: pgsql-docs@lists.postgresql.org
Cc: harry@harryclarke.me.uk
Subject: text and varchar are not equivalent
Date: Fri, 09 Feb 2024 11:18:22 +0000
Message-ID: <170747750218.3279716.17734031485916520031@wrigleys.postgresql.org> (raw)

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/16/datatype-character.html
Description:

The documentation implies that the data types text and varchar are
equivalent, but this is not the case with this test in Postgresql version
16.
CREATE TEMPORARY TABLE test(ch char, vc varchar, txt text, txt0 text);
INSERT INTO test VALUES (' ', ' ', ' ','');
SELECT ch = vc AS ch_vc, ch = txt AS ch_txt, ch = txt0 AS ch_txt0,
vc = ch AS vc_ch, vc = txt AS vc_txt, vc = txt0 AS vc_txt0, 
txt = ch AS txt_ch, txt = vc AS txt_vc, txt = txt0 AS txt_txt0,
txt0 = ch AS txt0_ch, txt0 = vc AS txt0_vc, txt0 = txt AS txt0_txt
FROM test;

ch_vc	ch_txt	ch_txt0	vc_ch	vc_txt	vc_txt0	txt_ch	txt_vc	txt_txt0	txt0_ch	txt0_vc	txt0_txt
TRUE	FALSE	TRUE	TRUE	TRUE	FALSE	FALSE	TRUE	FALSE	TRUE	FALSE	FALSE

The tests are showing that the space character is treated differently in a
one character string. Whilst varchar = text, the comparison with char is
treated differently with text and varchar


view thread (3+ messages)  latest in thread

Message-ID: <170747750218.3279716.17734031485916520031@wrigleys.postgresql.org>
Permalink:  ../170747750218.3279716.17734031485916520031@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/170747750218.3279716.17734031485916520031@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-docs@lists.postgresql.org, harry@harryclarke.me.uk
  Subject: Re: text and varchar are not equivalent
  In-Reply-To: <170747750218.3279716.17734031485916520031@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox