Re: zero char is returned as space

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Konstantin Izmailov <pgfizm(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: zero char is returned as space
Date: 2022-04-06 05:08:21
Message-ID: 2982424.1649221701@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Konstantin Izmailov <pgfizm(at)gmail(dot)com> writes:
> could you help me understand if this is an intended behaviour, or I'm
> incorrectly querying a "char" field?

We do not support '\0' as an element of a string value. You didn't
show how you're trying to insert this value, but I suspect that
Postgres saw it as an empty string which it then space-padded to
length 1 because that's what char(1) does.

Don't use a string field to store an integer. What with the need
for a length header, you wouldn't be saving any space compared to
"smallint" even if there weren't any semantic issues.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2022-04-06 05:19:40 Perform streaming logical transactions by background workers and parallel apply
Previous Message Jeff Davis 2022-04-06 05:02:43 Re: pg_walinspect - a new extension to get raw WAL data and WAL stats