Re: BUG #2907: pg_get_serial_sequence quoting

Lists: pgsql-bugspgsql-hackerspgsql-patches
From: "Adriaan van Os" <postgres(at)microbizz(dot)nl>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-19 05:52:32
Message-ID: 200701190552.l0J5qWLk003957@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches


The following bug has been logged online:

Bug reference: 2907
Logged by: Adriaan van Os
Email address: postgres(at)microbizz(dot)nl
PostgreSQL version: 8.1.4
Operating system: Mac OS X 10.4.6, intel
Description: pg_get_serial_sequence quoting
Details:

In order to work with capitals (etc.), the table_name parameter of
pg_get_serial_sequence needs double quotes inside single quotes, the
column_name parameter requires a name within single quotes only.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Adriaan van Os <postgres(at)microbizz(dot)nl>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-20 01:38:38
Message-ID: 200701200138.l0K1cc919181@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Adriaan van Os wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2907
> Logged by: Adriaan van Os
> Email address: postgres(at)microbizz(dot)nl
> PostgreSQL version: 8.1.4
> Operating system: Mac OS X 10.4.6, intel
> Description: pg_get_serial_sequence quoting
> Details:
>
> In order to work with capitals (etc.), the table_name parameter of
> pg_get_serial_sequence needs double quotes inside single quotes, the
> column_name parameter requires a name within single quotes only.

I can confirm this is still a problem in current CVS:

test=> CREATE TABLE "Test" ("Xx" SERIAL);
NOTICE: CREATE TABLE will create implicit sequence "Test_Xx_seq" for serial column "Test.Xx"
CREATE TABLE
test=> SELECT pg_get_serial_sequence('Test', 'xX');
ERROR: relation "test" does not exist
test=> SELECT pg_get_serial_sequence('"Test"', 'Xx');
pg_get_serial_sequence
------------------------
PUBLIC."Test_Xx_seq"
(1 row)

test=> SELECT pg_get_serial_sequence('"Test"', 'xx');
ERROR: column "xx" of relation "Test" does not exist

Strangely, this was reported before, but not until November of 2006:

http://archives.postgresql.org/pgsql-general/2006-11/msg01111.php

We have it in the queue to review for 8.3. Hopefully there will a
change or documentation addition for this in 8.3.

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Adriaan van Os <postgres(at)microbizz(dot)nl>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-20 05:03:01
Message-ID: 9518.1169269381@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Adriaan van Os wrote:
>> In order to work with capitals (etc.), the table_name parameter of
>> pg_get_serial_sequence needs double quotes inside single quotes, the
>> column_name parameter requires a name within single quotes only.

> I can confirm this is still a problem in current CVS:

This is not a bug, only a documentation issue.

regards, tom lane


From: Adriaan van Os <postgres(at)microbizz(dot)nl>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-20 09:20:52
Message-ID: 45B1DEF4.2060802@microbizz.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Bruce Momjian wrote:

> Strangely, this was reported before, but not until November of 2006:
>
> http://archives.postgresql.org/pgsql-general/2006-11/msg01111.php

That was a follow up on this thread
<http://archives.postgresql.org/pgsql-hackers/2004-10/msg00964.php>.

Regards,

Adriaan van Os


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Adriaan van Os <postgres(at)microbizz(dot)nl>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [BUGS] BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-20 14:27:10
Message-ID: 200701201427.l0KERAx18984@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Adriaan van Os wrote:
> Bruce Momjian wrote:
>
> > Strangely, this was reported before, but not until November of 2006:
> >
> > http://archives.postgresql.org/pgsql-general/2006-11/msg01111.php
>
> That was a follow up on this thread
> <http://archives.postgresql.org/pgsql-hackers/2004-10/msg00964.php>.

Interesting. In this thread the reason for the current behavior is
given as:

> I presume the reason for that is that the first paramater can be
> qualified:
>
> select pg_get_serial_sequence('"public"."FOO"', 'Ff1');

Would someone explain why qualification makes us lowercase the first
parameter by default? I don't understand it well enough to document it.
I notice this does not work:

test=> SELECT pg_get_serial_sequence('"Test"', '"Xx"');

So do we just say because quotes might be needed to distinguish the
schame from the table name, we don't auto-quote the first parameter?

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Adriaan van Os <postgres(at)microbizz(dot)nl>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-21 01:56:49
Message-ID: 17237.1169344609@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
>> I presume the reason for that is that the first paramater can be
>> qualified:
>> select pg_get_serial_sequence('"public"."FOO"', 'Ff1');

> Would someone explain why qualification makes us lowercase the first
> parameter by default? I don't understand it well enough to document it.

The point is that we have to parse the first parameter, whereas the
second one can be taken literally.

regards, tom lane


From: Adriaan van Os <adriaan(at)microbizz(dot)nl>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [HACKERS] BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-22 09:19:25
Message-ID: 45B4819D.7040308@microbizz.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>>> I presume the reason for that is that the first paramater can be
>>> qualified:
>>> select pg_get_serial_sequence('"public"."FOO"', 'Ff1');
>
>> Would someone explain why qualification makes us lowercase the first
>> parameter by default? I don't understand it well enough to document it.
>
> The point is that we have to parse the first parameter, whereas the
> second one can be taken literally.

It still looks inconsistent and ugly. I think the design mistake of pg_get_serial_sequence is that
it takes two parameters rather than one (a fully qualified doublequoted columnname path) or three
(optionally empty schema, tablename, columnname, all three literal).

Regards,

Adriaan van Os


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Adriaan van Os <adriaan(at)microbizz(dot)nl>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] [BUGS] BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-30 02:34:53
Message-ID: 200701300234.l0U2Yr423647@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Adriaan van Os wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >>> I presume the reason for that is that the first paramater can be
> >>> qualified:
> >>> select pg_get_serial_sequence('"public"."FOO"', 'Ff1');
> >
> >> Would someone explain why qualification makes us lowercase the first
> >> parameter by default? I don't understand it well enough to document it.
> >
> > The point is that we have to parse the first parameter, whereas the
> > second one can be taken literally.
>
> It still looks inconsistent and ugly. I think the design mistake of pg_get_serial_sequence is that
> it takes two parameters rather than one (a fully qualified doublequoted columnname path) or three
> (optionally empty schema, tablename, columnname, all three literal).

I did my best to document the behavior of pg_get_serial_sequence().
There actually is a technical reason why we can't auto-quote the first
parameter. Patch applied to HEAD and 8.2.X.

Example of identifiers with embedded periods:

test=> CREATE TABLE "a.b" ("c.d" SERIAL);
NOTICE: CREATE TABLE will create implicit sequence "a.b_c.d_seq" for serial column "a.b.c.d"
CREATE TABLE

test=> SELECT pg_get_serial_sequence('a.b', 'c.d');
ERROR: schema "a" does not exist

test=> SELECT pg_get_serial_sequence('"a.b"', 'c.d');
pg_get_serial_sequence
------------------------
PUBLIC."a.b_c.d_seq"
(1 row)

test=> SELECT pg_get_serial_sequence('"a.b"', '"c.d"');
ERROR: column ""c.""d of relation "a.b" does not exist

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/rtmp/diff text/x-diff 2.7 KB

From: Adriaan van Os <postgres(at)microbizz(dot)nl>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] [BUGS] BUG #2907: pg_get_serial_sequence quoting
Date: 2007-01-30 15:10:07
Message-ID: 45BF5FCF.1080708@microbizz.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> Adriaan van Os wrote:
>> Tom Lane wrote:
>>> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>>>>> I presume the reason for that is that the first paramater can be
>>>>> qualified:
>>>>> select pg_get_serial_sequence('"public"."FOO"', 'Ff1');
>>>> Would someone explain why qualification makes us lowercase the first
>>>> parameter by default? I don't understand it well enough to document it.
>>> The point is that we have to parse the first parameter, whereas the
>>> second one can be taken literally.
>> It still looks inconsistent and ugly. I think the design mistake of pg_get_serial_sequence is that
>> it takes two parameters rather than one (a fully qualified doublequoted columnname path) or three
>> (optionally empty schema, tablename, columnname, all three literal).
>
> I did my best to document the behavior of pg_get_serial_sequence().
> There actually is a technical reason why we can't auto-quote the first
> parameter. Patch applied to HEAD and 8.2.X.

Thanks for the doc change.

Adriaan van Os