Re: BUG #1862: ECPG Connect, host variable trailing blanks - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: BUG #1862: ECPG Connect, host variable trailing blanks
Date
Msg-id 20050907071512.GA14687@winnie.fuhr.org
Whole thread Raw
In response to BUG #1862: ECPG Connect, host variable trailing blanks  ("James Gray" <jim.gray@bull.com>)
Responses Re: BUG #1862: ECPG Connect, host variable trailing blanks  (Jim.Gray@Bull.com)
List pgsql-bugs
On Tue, Sep 06, 2005 at 09:02:47PM +0100, James Gray wrote:
> The problem that we are having involves a connect statement with host
> variables:
>    EXEC SQL  CONNECT TO  :target  AS  :user
>
> Our problem is that we are passed Cobol strings which are blank padded.
> Our string strategy works fine for Oracle, but not for Postgres CONNECTs.
>
> For example, if we are trying to connect to:
>  - database:  demo
>  - user:      scott
>  - password:  tiger
> the strings must be "demo", "scott" and "tiger".
>
> With trailing blanks user "scott" will not match user "scott     ",
> which is what we will present if the user had defined the Cobol variable as
> PIC X(10).

In PostgreSQL, "scott" and "scott     " are distinct identifiers,
and both are valid.  See "Identifiers and Key Words" in the "SQL
Syntax" chapter of the documentation, especially the part that
discusses quoted identifiers:

http://www.postgresql.org/docs/8.0/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS

Although creating databases, users, tables, etc., with trailing
spaces is probably a bad idea, PostgreSQL does allow such names,
and the trailing spaces are significant.

> This only applies to CONNECT host variables, since trailing blanks in a
> CHAR column are ignored in comparisons for all other interactions with
> Postgres.
>
> Since this is inconsistent behavior, and also doesn't match Oracle's
> behavior, we are requesting a fix or an option.

Identifiers are NAME types, not CHAR types; the difference in
behavior is no more inconsistent than that between VARCHAR and CHAR.
If the strings have trailing spaces but the identifiers on the
server side don't, then strip the spaces on the client side.

--
Michael Fuhr

pgsql-bugs by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Serialization errors on single threaded request
Next
From: "Howard Brodale"
Date:
Subject: BUG #1863: Install won't work