Re: Strange CREATE VIEW behavior?? - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Strange CREATE VIEW behavior??
Date
Msg-id 16780.992500654@sss.pgh.pa.us
Whole thread Raw
In response to Strange CREATE VIEW behavior??  (pgsql-bugs@postgresql.org)
List pgsql-bugs
pgsql-bugs@postgresql.org writes:
> View definition: SELECT zz.ff AS "user", zz.ss AS num FROM zz;

> View definition: SELECT zz.ff AS user1, zz.ss AS num FROM zz;

> Why in the first case column has name "user" (with '"') ?

USER is a keyword.  It happens not to be reserved, so you can use it for
an AS name without quoting it, but the view decompiler doesn't want to
take any chances so it quotes it anyway.

It would be correct and 100% safe for Postgres to display these rules
with all identifiers quoted:

View definition: SELECT "zz"."ff" AS "user1", "zz"."ss" AS "num" FROM "zz";

but since that's pretty unreadable, we try to suppress the quotes where
they're not essential.  The decompiler just errs on the side of safety
when it sees that the identifier matches a keyword: rather than trying
to figure out if the keyword is reserved in this particular context,
it just adds the quotes always.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Mister X
Date:
Subject: ODBC Interface version 07_01_0005, problem with C++ exceptions
Next
From: Tom Lane
Date:
Subject: Re: Segmentation fault in psql