Re: PostgreSQL vs SQL Standard

From: Brad DeJong <bpd0018(at)gmail(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PostgreSQL vs SQL Standard
Date: 2018-06-30 16:42:44
Message-ID: CAJnrtnxrV_Nbfs1SZD6CmfB0dfAtGfKGLmLOED02M47RzdOZwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Jun 9, 2018 at 8:37 PM, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
wrote:
> I think I got all the issues I currently know of, but there may be
> more, and others may disagree with my classification of issues or the
> rationales for violating the spec. Any feedback?

Related to, but I think distinct from

"Trailing spaces in character(n)"
Trailing spaces in char(n) values are removed in contexts where the
spec requires they be kept.

E021-03 Character literals subclause 5.3, "<literal>": <quote> [ <character
representation>... ] <quote>

In subclause 5.3 (SQL standard 2011 part 2: foundation), <character string
literal> is defined (ignoring
the character set specifier and the weird multi-line continuations) as

<character string literal> ::= <quote> [ <character representation>...
] <quote>

syntax rule 17 states

"The declared type of a <character string literal> is fixed-length
character string."

In PostgreSQL, the same syntax (<quote> [ <character representation>... ]
<quote>) is a string constant and in
the PostgreSQL documentation, section 4.1.2 constants, it says that string
constants are one
of the three kinds of implicitly typed constants.

Where you see the difference is that trailing spaces in a string constant
are retained when the type
is resolved to text, but if the constant was typed as bpchar and then cast
to text, the trailing spaces
would be trimmed.

https://www.postgresql.org/message-id/28069.1501269327%40sss.pgh.pa.us
https://www.postgresql.org/message-id/9524.1511311751%40sss.pgh.pa.us

You also see that the type of a string constant is implicit in cases where
PostgreSQL is
unable to determine the type of a string constant from its context.

https://www.postgresql.org/message-id/1405965382386-5812247.post%40n5.nabble.com

I could be reading some of this incorrectly, but putting it all together,
it looks to me like
PostgreSQL does not meet a strict interpretation of E021-03.

I'd put it in the WONTFIX section.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2018-06-30 17:56:37 Re: Fix to not check included columns in ANALYZE on indexes
Previous Message Arseny Sher 2018-06-30 15:00:21 Re: pgsql: Fix "base" snapshot handling in logical decoding