From: jorsol@gmail.com
To: pgsql-bugs@postgresql.org
Cc: jorsol@gmail.com
Subject: BUG #14920: TEXT binding not works correctly with BPCHAR
Date: Wed, 22 Nov 2017 00:25:43 +0000
Message-ID: <20171122002543.1468.39211@wrigleys.postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 14920
Logged by: Jorge Solorzano
Email address: jorsol@gmail.com
PostgreSQL version: 10.1
Operating system: Ubuntu 16.04
Description:
TEXT type is the preferred data type for the category String, but I'm having
a hard time using it with bpchar:
The reproducible use case is here:
1. Create a table with a bpchar(3).
2. Insert a tuple with trailing space.
3. If I select the values using varchar, it works fine with and without
trailing space.
4. If I select the values using text, it only works without trailing
space.
This behavior is odd and is not documented (at least I not found it). This
can be a limiting factor to use the text data type for strings instead of
varchar.
------------------------------------------
DROP TABLE IF EXISTS texttable;
CREATE TABLE texttable (
ch bpchar(3), te text, vc varchar(3)
);
PREPARE fooplaninsert (text, text, text) AS
INSERT INTO texttable (ch, te, vc) VALUES ($1, $2, $3);
EXECUTE fooplaninsert('c ', 'c ', 'c ');
-- USING VARCHAR
PREPARE fooplanselectvc (varchar, varchar, varchar) AS
SELECT ch, te, vc FROM texttable WHERE ch=$1 AND te=$2 AND vc=$3;
-- THIS WORKS WITH AND WITHOUT TRAILING SPACE
EXECUTE fooplanselectvc('c ', 'c ', 'c ');
EXECUTE fooplanselectvc('c', 'c ', 'c ');
-- USING TEXT
PREPARE fooplanselecttx (text, text, text) AS
SELECT ch, te, vc FROM texttable WHERE ch=$1 AND te=$2 AND vc=$3;
-- THIS NOT WORKS WITH TRAILING SPACE
EXECUTE fooplanselecttx('c ', 'c ', 'c ');
-- THIS WORKS WITHOUT TRAILING SPACE
EXECUTE fooplanselecttx('c', 'c ', 'c ');
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: jorsol@gmail.com
Subject: Re: BUG #14920: TEXT binding not works correctly with BPCHAR
In-Reply-To: <20171122002543.1468.39211@wrigleys.postgresql.org>
References: <20171122002543.1468.39211@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