pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
grouping treated as keyword in function return table
5+ messages / 2 participants
[nested] [flat]

* grouping treated as keyword in function return table
@ 2016-07-12 15:51 Mike Porter <mike@udel.edu>
  2016-07-12 16:06 ` Re: grouping treated as keyword in function return table Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Mike Porter @ 2016-07-12 15:51 UTC (permalink / raw)
  To: pgsql-bugs

Postgres 9.5.3 built from source.  However, I think this has been
happening for a long time.

create function a() returns table( grouping integer ) language sql as $$
select 1;
$$;
ERROR:  syntax error at or near "grouping"
LINE 1: create function a() returns table( grouping integer ) langua...

If we quote "grouping"
                                            ^
create function a() returns table( "grouping" integer ) language sql as $$
select 1;
$$
;
CREATE FUNCTION

grouping is a valid column in a table and does not need to be quoted:

create temp table test( grouping integer );
CREATE TABLE

So, in almost all cases grouping is not required to be quoted,
however when used in a table defined as a function return type, it
is.  Additionally, pg_dumpall does not quote grouping when dumping
the function so the function will not be restored when the dump is
loaded.

Thanks,

Mike

-
Mike Porter
PGP Fingerprint: F4 AE E1 9F 67 F7 DA EA  2F D2 37 F3 99 ED D1 C2


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: grouping treated as keyword in function return table
  2016-07-12 15:51 grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
@ 2016-07-12 16:06 ` Tom Lane <tgl@sss.pgh.pa.us>
  2016-07-12 16:44   ` Re: grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2016-07-12 16:06 UTC (permalink / raw)
  To: Mike Porter <mike@udel.edu>; +Cc: pgsql-bugs

Mike Porter <mike@udel.edu> writes:
> Postgres 9.5.3 built from source.  However, I think this has been
> happening for a long time.

Only since 9.5, because GROUPING wasn't a keyword before that.

> So, in almost all cases grouping is not required to be quoted,
> however when used in a table defined as a function return type, it
> is.

This is expected given that it's now partially reserved.

> Additionally, pg_dumpall does not quote grouping when dumping
> the function so the function will not be restored when the dump is
> loaded.

That would be a pg_dump bug, but it doesn't happen for me: I get

CREATE FUNCTION a() RETURNS TABLE("grouping" integer)
    LANGUAGE sql
    AS $$  select 1; $$;

Sure you're using 9.5 pg_dump?

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: grouping treated as keyword in function return table
  2016-07-12 15:51 grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
  2016-07-12 16:06 ` Re: grouping treated as keyword in function return table Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-07-12 16:44   ` Mike Porter <mike@udel.edu>
  2016-07-12 16:58     ` Re: grouping treated as keyword in function return table Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Mike Porter @ 2016-07-12 16:44 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On Tue, 12 Jul 2016, Tom Lane wrote:

> Mike Porter <mike@udel.edu> writes:
>> Postgres 9.5.3 built from source.  However, I think this has been
>> happening for a long time.
>
> Only since 9.5, because GROUPING wasn't a keyword before that.
>
>> So, in almost all cases grouping is not required to be quoted,
>> however when used in a table defined as a function return type, it
>> is.
>
> This is expected given that it's now partially reserved.

Perhaps it was in an earlier 9.5 test when I added the quotes...

I noticed that grouping is fully quoted in all the tables in the
dump.  Will grouping be a fully reserved word at some point?

>
>> Additionally, pg_dumpall does not quote grouping when dumping
>> the function so the function will not be restored when the dump is
>> loaded.
>
> That would be a pg_dump bug, but it doesn't happen for me: I get
>
> CREATE FUNCTION a() RETURNS TABLE("grouping" integer)
>    LANGUAGE sql
>    AS $$  select 1; $$;
>
> Sure you're using 9.5 pg_dump?

My notes say so.

/usr/local/postgresql-9.5.3/bin/pg_dumpall -h a.server -U postgres > 9.5.3.sql



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: grouping treated as keyword in function return table
  2016-07-12 15:51 grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
  2016-07-12 16:06 ` Re: grouping treated as keyword in function return table Tom Lane <tgl@sss.pgh.pa.us>
  2016-07-12 16:44   ` Re: grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
@ 2016-07-12 16:58     ` Tom Lane <tgl@sss.pgh.pa.us>
  2016-07-12 17:13       ` Re: grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2016-07-12 16:58 UTC (permalink / raw)
  To: Mike Porter <mike@udel.edu>; +Cc: pgsql-bugs

Mike Porter <mike@udel.edu> writes:
> On Tue, 12 Jul 2016, Tom Lane wrote:
>> Only since 9.5, because GROUPING wasn't a keyword before that.

> I noticed that grouping is fully quoted in all the tables in the
> dump.  Will grouping be a fully reserved word at some point?

Well, we won't voluntarily make it so, but the SQL committee seems not to
care when inventing new syntax whether it requires fully reserving new
keywords to make it work.  So it's a matter of what they do and whether
we decide we want to adopt the feature/syntax.

As far as dumps go, our default practice is to quote any non-unreserved
keyword; it's not worth the trouble to decide for partially-reserved
words whether they'd really need to be quoted in the specific context.

>> Sure you're using 9.5 pg_dump?

> My notes say so.
> /usr/local/postgresql-9.5.3/bin/pg_dumpall -h a.server -U postgres > 9.5.3.sql

Hm, is the source server 9.5?  I think that the TABLE clause is actually
generated server-side in this case.

When you're making a dump you intend to load into a different server
version, we recommend using --quote-all-identifiers to make sure you're
not blindsided by identifiers that have become reserved words in the
newer server version.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: grouping treated as keyword in function return table
  2016-07-12 15:51 grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
  2016-07-12 16:06 ` Re: grouping treated as keyword in function return table Tom Lane <tgl@sss.pgh.pa.us>
  2016-07-12 16:44   ` Re: grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
  2016-07-12 16:58     ` Re: grouping treated as keyword in function return table Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-07-12 17:13       ` Mike Porter <mike@udel.edu>
  0 siblings, 0 replies; 5+ messages in thread

From: Mike Porter @ 2016-07-12 17:13 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On Tue, 12 Jul 2016, Tom Lane wrote:
> Mike Porter <mike@udel.edu> writes:
>> On Tue, 12 Jul 2016, Tom Lane wrote:
>>> Only since 9.5, because GROUPING wasn't a keyword before that.
>>> Sure you're using 9.5 pg_dump?
>
>> My notes say so.
>> /usr/local/postgresql-9.5.3/bin/pg_dumpall -h a.server -U postgres > 9.5.3.sql
>
> Hm, is the source server 9.5?  I think that the TABLE clause is actually
> generated server-side in this case.

The source server is 9.3.5 (9.3...)

> When you're making a dump you intend to load into a different server
> version, we recommend using --quote-all-identifiers to make sure you're
> not blindsided by identifiers that have become reserved words in the
> newer server version.

Great advice.  Thanks, Mike

>
> 			regards, tom lane
>

-
Mike Porter
PGP Fingerprint: F4 AE E1 9F 67 F7 DA EA  2F D2 37 F3 99 ED D1 C2


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2016-07-12 17:13 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12 15:51 grouping treated as keyword in function return table Mike Porter <mike@udel.edu>
2016-07-12 16:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-07-12 16:44   ` Mike Porter <mike@udel.edu>
2016-07-12 16:58     ` Tom Lane <tgl@sss.pgh.pa.us>
2016-07-12 17:13       ` Mike Porter <mike@udel.edu>

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