Mysterious ::text::char cast: ascii(chr(32)::char) = 0

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Mysterious ::text::char cast: ascii(chr(32)::char) = 0
Date: 2021-02-21 05:46:56
Message-ID: c69f69f7-61d6-4f56-a0ac-e19fdbef3fa5@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

In testing the regex engine, I found a strange case that puzzles me.

When a text string of a single space character is casted to a character,
I would assume the result to be, a space character,
but for some reason it's the null character.

Trying to produce a text with null character gives an error, like expected:

SELECT chr(0);
ERROR: null character not permitted

SELECT c = ascii(chr(c)::char), COUNT(*) FROM generate_series(1,255) AS c GROUP BY 1;
f | 1
t | 254

SELECT * FROM generate_series(1,255) AS c WHERE c <> ascii(chr(c)::char);
32

It's only character 32 that has this "special effect".

/Joel

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2021-02-21 06:00:21 Use pgstat_progress_update_multi_param instead of single param update
Previous Message Vik Fearing 2021-02-21 02:09:05 Re: TRIM_ARRAY