Thread: Drop one-argument string_agg? (was Re: [BUGS] string_agg delimiter having no effect with order by)

Alex Hunsaker <badalex@gmail.com> writes:
> On Wed, Aug 4, 2010 at 11:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> If we were a bit earlier in the 9.0 cycle I would suggest that this
>> confusion is a sufficient reason to drop the one-argument form of
>> string_agg. It's too late now though.

> FWIW I think we can still change it.   Isn't this type of issue part
> of what beta is for?  If we were in RC that would be a different story
> :)

Well, it'd take an initdb to get rid of it.  In the past we've avoided
forcing initdb post-beta1 unless it was Really Necessary.  OTOH, we seem
to be in the mode of encouraging beta testers to test pg_upgrade, so
maybe that concern isn't worth much at the moment.

I am right, am I not, in thinking that we invented string_agg out of
whole cloth?  I don't see it in SQL:2008.  If there is a compatibility-
with-other-products reason to support the one-argument form, that would
be a consideration here.  I don't see a whole lot of functionality gain
from having the one-argument form, though.

BTW, as far as I can tell from checking in the system catalogs,
there are no other built-in aggregates that come in
differing-numbers-of-arguments variants.  So string_agg is the only
one presenting this hazard.
        regards, tom lane


On Wed, Aug 4, 2010 at 13:11, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Alex Hunsaker <badalex@gmail.com> writes:
>> On Wed, Aug 4, 2010 at 11:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> If we were a bit earlier in the 9.0 cycle I would suggest that this
>>> confusion is a sufficient reason to drop the one-argument form of
>>> string_agg. It's too late now though.
>
>> FWIW I think we can still change it.   Isn't this type of issue part
>> of what beta is for?  If we were in RC that would be a different story
>> :)
>
> Well, it'd take an initdb to get rid of it.

I think forcing an initdb might be more trouble than this wart is worth.

> In the past we've avoided
> forcing initdb post-beta1 unless it was Really Necessary.  OTOH, we seem
> to be in the mode of encouraging beta testers to test pg_upgrade, so
> maybe that concern isn't worth much at the moment.

I have one or two 9.0-beta databases,  a forced initdb would defiantly
motivate me to try pg_upgrade :).  To me, the question is are  we
planning on releasing a new beta anyway?  Maybe its worth it then.  If
we were planning on going RC after this last beta (and I dont think we
were?), I agree with Kevin, its not something worth pushing the
release 9.0 for.  By that I mean I assume if we force an initdb that
we would want to do another beta regardless.

Either way, I don't have strong feelings on this other than if we dont
fix it now when will we?  Maybe we will get "lucky" and someone will
find an issue that we have to initdb for anyways :).


On Wed, Aug 4, 2010 at 3:25 PM, Alex Hunsaker <badalex@gmail.com> wrote:
> I think forcing an initdb might be more trouble than this wart is worth.

+1.  I would not make this change unless we have to force an initdb
anyway.  And I really hope we don't, because I'm sort of hoping the
next 9.0 release will be rc1.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


Alex Hunsaker <badalex@gmail.com> writes:
> Either way, I don't have strong feelings on this other than if we dont
> fix it now when will we?

Well, we won't.  If 9.0 ships with both forms of string_agg, we're stuck
with it IMO.  It's not exactly a bug, so I won't cry if that's how
things go; but it is striking that already two different people have
gotten confused enough to file bug reports because of this.  If we don't
pull the one-argument form then I think we can look forward to many more
of those in future years.
        regards, tom lane


On 4 August 2010 20:25, Alex Hunsaker <badalex@gmail.com> wrote:
> On Wed, Aug 4, 2010 at 13:11, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Alex Hunsaker <badalex@gmail.com> writes:
>>> On Wed, Aug 4, 2010 at 11:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>>> If we were a bit earlier in the 9.0 cycle I would suggest that this
>>>> confusion is a sufficient reason to drop the one-argument form of
>>>> string_agg. It's too late now though.
>>
>>> FWIW I think we can still change it.   Isn't this type of issue part
>>> of what beta is for?  If we were in RC that would be a different story
>>> :)
>>
>> Well, it'd take an initdb to get rid of it.
>
> I think forcing an initdb might be more trouble than this wart is worth.
>
>> In the past we've avoided
>> forcing initdb post-beta1 unless it was Really Necessary.  OTOH, we seem
>> to be in the mode of encouraging beta testers to test pg_upgrade, so
>> maybe that concern isn't worth much at the moment.
>
> I have one or two 9.0-beta databases,  a forced initdb would defiantly
> motivate me to try pg_upgrade :).  To me, the question is are  we
> planning on releasing a new beta anyway?  Maybe its worth it then.  If
> we were planning on going RC after this last beta (and I dont think we
> were?), I agree with Kevin, its not something worth pushing the
> release 9.0 for.  By that I mean I assume if we force an initdb that
> we would want to do another beta regardless.
>
> Either way, I don't have strong feelings on this other than if we dont
> fix it now when will we?  Maybe we will get "lucky" and someone will
> find an issue that we have to initdb for anyways :).
>

I think it should be left exactly how it is.  It only needed
clarification in the documentation to explain its usage for the
scenario in question, and probably a couple entries in the regression
tests as they're lacking at the moment.

I wish I had held back on mentioning it as I remembered later that
this has already been discussed to a degree, and I'd probably have
kept my mouth shut upon recalling it.

--
Thom Brown
Registered Linux user: #516935


Robert Haas <robertmhaas@gmail.com> writes:
> On Wed, Aug 4, 2010 at 3:25 PM, Alex Hunsaker <badalex@gmail.com> wrote:
>> I think forcing an initdb might be more trouble than this wart is worth.

> +1.  I would not make this change unless we have to force an initdb
> anyway.  And I really hope we don't, because I'm sort of hoping the
> next 9.0 release will be rc1.

Hm?  I don't think that an initdb here would have any impact on whether
we can call the next drop RC1 or not.  We're talking about removing a
single built-in entry in pg_proc --- it's one of the safest changes we
could possibly make.  The only argument I can see against it is not
wanting to force beta testers through an initdb.  But it seems like that
might actually be a positive thing not a negative one, in this cycle,
because we're trying to get test coverage on pg_upgrade.
        regards, tom lane


> Well, it'd take an initdb to get rid of it.  In the past we've avoided
> forcing initdb post-beta1 unless it was Really Necessary.  OTOH, we seem
> to be in the mode of encouraging beta testers to test pg_upgrade, so
> maybe that concern isn't worth much at the moment.

If it's causing bugs, drop it now.  If we include it in 9.0, we're stuck
with it for years.

I'm OK with forcing an initDB for RC1.

--                                  -- Josh Berkus                                    PostgreSQL Experts Inc.
                        http://www.pgexperts.com
 


Josh Berkus <josh@agliodbs.com> writes:
> If it's causing bugs, drop it now.  If we include it in 9.0, we're stuck
> with it for years.

Well, it's causing bug reports, which is not exactly the same thing as bugs.
But yeah, I'm thinking we should get rid of it.
        regards, tom lane


04.Ağu.2010 tarihinde 22:44 saatinde, Josh Berkus <josh@agliodbs.com>
şunları yazdı:

> I'm OK with forcing an initDB for RC1.

I think beta5 will be a better choice than RC 1 here.
--
Devrim GÜNDÜZ
PostgreSQL DBA @ Akinon/Markafoni, Red Hat Certified Engineer
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.gunduz.org  Twitter: http://twitter.com/devrimgunduz

On Wed, Aug 4, 2010 at 13:42, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> On Wed, Aug 4, 2010 at 3:25 PM, Alex Hunsaker <badalex@gmail.com> wrote:
>>> I think forcing an initdb might be more trouble than this wart is worth.
>
>> +1.  I would not make this change unless we have to force an initdb
>> anyway.  And I really hope we don't, because I'm sort of hoping the
>> next 9.0 release will be rc1.
>
> Hm?  I don't think that an initdb here would have any impact on whether
> we can call the next drop RC1 or not.  We're talking about removing a
> single built-in entry in pg_proc --- it's one of the safest changes we
> could possibly make.

Great, I was afraid people would want another beta if we forced an
initdb.  So a hearty +1 for fixing it and not doing another beta
(pending other bugs obviously).


> Great, I was afraid people would want another beta if we forced an
> initdb.  So a hearty +1 for fixing it and not doing another beta
> (pending other bugs obviously).

And, btw, there has been a lot of testing of pg_upgrade due to the
initdbs and otherwise.  I think 9.0 is going to have a pretty darned
solid pg_upgrade because of it.

--                                  -- Josh Berkus                                    PostgreSQL Experts Inc.
                        http://www.pgexperts.com
 


On 4 August 2010 20:58, Josh Berkus <josh@agliodbs.com> wrote:
>
>> Great, I was afraid people would want another beta if we forced an
>> initdb.  So a hearty +1 for fixing it and not doing another beta
>> (pending other bugs obviously).
>
> And, btw, there has been a lot of testing of pg_upgrade due to the
> initdbs and otherwise.  I think 9.0 is going to have a pretty darned
> solid pg_upgrade because of it.
>

Leave my name off the commit comment then ;)  People who have been
waiting for this will burn me as a heretical witch... er.. man
witch... warlock?

--
Thom Brown
Registered Linux user: #516935


On Wed, Aug 04, 2010 at 09:02:43PM +0100, Thom Brown wrote:
> On 4 August 2010 20:58, Josh Berkus <josh@agliodbs.com> wrote:
> >
> >> Great, I was afraid people would want another beta if we forced
> >> an initdb.  So a hearty +1 for fixing it and not doing another
> >> beta (pending other bugs obviously).
> >
> > And, btw, there has been a lot of testing of pg_upgrade due to the
> > initdbs and otherwise.  I think 9.0 is going to have a pretty
> > darned solid pg_upgrade because of it.
> >
> 
> Leave my name off the commit comment then ;)  People who have been
> waiting for this will burn me as a heretical witch... er.. man
> witch... warlock?

Witch.

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


On Wed, Aug 4, 2010 at 3:11 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Alex Hunsaker <badalex@gmail.com> writes:
>> On Wed, Aug 4, 2010 at 11:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> If we were a bit earlier in the 9.0 cycle I would suggest that this
>>> confusion is a sufficient reason to drop the one-argument form of
>>> string_agg. It's too late now though.
>
>> FWIW I think we can still change it.   Isn't this type of issue part
>> of what beta is for?  If we were in RC that would be a different story
>> :)
>
> Well, it'd take an initdb to get rid of it.  In the past we've avoided
> forcing initdb post-beta1 unless it was Really Necessary.  OTOH, we seem
> to be in the mode of encouraging beta testers to test pg_upgrade, so
> maybe that concern isn't worth much at the moment.

I vote fix it.  This is going to be a high travel function, and should be right.

merlin


I wrote:
> Hm?  I don't think that an initdb here would have any impact on whether
> we can call the next drop RC1 or not.  We're talking about removing a
> single built-in entry in pg_proc --- it's one of the safest changes we
> could possibly make.

Well, I forgot that an aggregate involves more than one catalog row ;-).
So it's a bit bigger patch than that, but still pretty small and safe.
See attached.

What we are doing here, IMO, is not just changing string_agg() but
instituting a project policy that we are not going to offer built-in
aggregates with the same names and different numbers of arguments ---
otherwise the problem will come right back.  Therefore, the attached
patch adds an opr_sanity regression test that will complain if anyone
tries to add such.  Of course, this isn't preventing users from creating
such aggregates, but it's on their own heads to not get confused if they
do.

This policy also implies that we are never going to allow default
arguments for aggregates, or at least never have any built-in ones
that use such a feature.

By my count the following people had offered an opinion on making
this change:
    for: tgl, josh, badalex, mmoncure
    against: rhaas, thom
Anybody else want to vote, or change their vote after seeing the patch?

            regards, tom lane

Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.522
diff -c -r1.522 func.sgml
*** doc/src/sgml/func.sgml    29 Jul 2010 19:34:40 -0000    1.522
--- doc/src/sgml/func.sgml    4 Aug 2010 22:01:12 -0000
***************
*** 9731,9737 ****
      <thead>
       <row>
        <entry>Function</entry>
!       <entry>Argument Type</entry>
        <entry>Return Type</entry>
        <entry>Description</entry>
       </row>
--- 9731,9737 ----
      <thead>
       <row>
        <entry>Function</entry>
!       <entry>Argument Type(s)</entry>
        <entry>Return Type</entry>
        <entry>Description</entry>
       </row>
***************
*** 9901,9917 ****
          <primary>string_agg</primary>
         </indexterm>
         <function>
!          string_agg(<replaceable class="parameter">expression</replaceable>
!                     [, <replaceable class="parameter">delimiter</replaceable> ] )
         </function>
        </entry>
        <entry>
!        <type>text</type>
        </entry>
        <entry>
         <type>text</type>
        </entry>
!       <entry>input values concatenated into a string, optionally with delimiters</entry>
       </row>

       <row>
--- 9901,9917 ----
          <primary>string_agg</primary>
         </indexterm>
         <function>
!          string_agg(<replaceable class="parameter">expression</replaceable>,
!                     <replaceable class="parameter">delimiter</replaceable>)
         </function>
        </entry>
        <entry>
!        <type>text</type>, <type>text</type>
        </entry>
        <entry>
         <type>text</type>
        </entry>
!       <entry>input values concatenated into a string, separated by delimiter</entry>
       </row>

       <row>
Index: doc/src/sgml/syntax.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v
retrieving revision 1.149
diff -c -r1.149 syntax.sgml
*** doc/src/sgml/syntax.sgml    4 Aug 2010 15:27:57 -0000    1.149
--- doc/src/sgml/syntax.sgml    4 Aug 2010 22:01:12 -0000
***************
*** 1589,1598 ****
  </programlisting>
      not this:
  <programlisting>
! SELECT string_agg(a ORDER BY a, ',') FROM table;  -- not what you want
  </programlisting>
!     The latter syntax will be accepted, but <literal>','</> will be
!     treated as a (useless) sort key.
     </para>

     <para>
--- 1589,1599 ----
  </programlisting>
      not this:
  <programlisting>
! SELECT string_agg(a ORDER BY a, ',') FROM table;  -- incorrect
  </programlisting>
!     The latter is syntactically valid, but it represents a call of a
!     single-argument aggregate function with two <literal>ORDER BY</> keys
!     (the second one being rather useless since it's a constant).
     </para>

     <para>
Index: src/backend/utils/adt/varlena.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v
retrieving revision 1.177
diff -c -r1.177 varlena.c
*** src/backend/utils/adt/varlena.c    26 Feb 2010 02:01:10 -0000    1.177
--- src/backend/utils/adt/varlena.c    4 Aug 2010 22:01:12 -0000
***************
*** 3320,3326 ****
  /*
   * string_agg - Concatenates values and returns string.
   *
!  * Syntax: string_agg(value text, delimiter text = '') RETURNS text
   *
   * Note: Any NULL values are ignored. The first-call delimiter isn't
   * actually used at all, and on subsequent calls the delimiter precedes
--- 3320,3326 ----
  /*
   * string_agg - Concatenates values and returns string.
   *
!  * Syntax: string_agg(value text, delimiter text) RETURNS text
   *
   * Note: Any NULL values are ignored. The first-call delimiter isn't
   * actually used at all, and on subsequent calls the delimiter precedes
***************
*** 3359,3386 ****

      state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0);

-     /* Append the element unless null. */
-     if (!PG_ARGISNULL(1))
-     {
-         if (state == NULL)
-             state = makeStringAggState(fcinfo);
-         appendStringInfoText(state, PG_GETARG_TEXT_PP(1));        /* value */
-     }
-
-     /*
-      * The transition type for string_agg() is declared to be "internal",
-      * which is a pass-by-value type the same size as a pointer.
-      */
-     PG_RETURN_POINTER(state);
- }
-
- Datum
- string_agg_delim_transfn(PG_FUNCTION_ARGS)
- {
-     StringInfo    state;
-
-     state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0);
-
      /* Append the value unless null. */
      if (!PG_ARGISNULL(1))
      {
--- 3359,3364 ----
Index: src/include/catalog/catversion.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/catalog/catversion.h,v
retrieving revision 1.588
diff -c -r1.588 catversion.h
*** src/include/catalog/catversion.h    16 Jul 2010 02:15:54 -0000    1.588
--- src/include/catalog/catversion.h    4 Aug 2010 22:01:12 -0000
***************
*** 53,58 ****
   */

  /*                            yyyymmddN */
! #define CATALOG_VERSION_NO    201007151

  #endif
--- 53,58 ----
   */

  /*                            yyyymmddN */
! #define CATALOG_VERSION_NO    201008041

  #endif
Index: src/include/catalog/pg_aggregate.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/catalog/pg_aggregate.h,v
retrieving revision 1.71
diff -c -r1.71 pg_aggregate.h
*** src/include/catalog/pg_aggregate.h    1 Feb 2010 03:14:43 -0000    1.71
--- src/include/catalog/pg_aggregate.h    4 Aug 2010 22:01:12 -0000
***************
*** 224,231 ****
  DATA(insert ( 2335    array_agg_transfn    array_agg_finalfn        0    2281    _null_ ));

  /* text */
! DATA(insert (3537    string_agg_transfn            string_agg_finalfn    0    2281    _null_ ));
! DATA(insert (3538    string_agg_delim_transfn    string_agg_finalfn    0    2281    _null_ ));

  /*
   * prototypes for functions in pg_aggregate.c
--- 224,230 ----
  DATA(insert ( 2335    array_agg_transfn    array_agg_finalfn        0    2281    _null_ ));

  /* text */
! DATA(insert ( 3538    string_agg_transfn    string_agg_finalfn        0    2281    _null_ ));

  /*
   * prototypes for functions in pg_aggregate.c
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.573
diff -c -r1.573 pg_proc.h
*** src/include/catalog/pg_proc.h    29 Jul 2010 20:09:25 -0000    1.573
--- src/include/catalog/pg_proc.h    4 Aug 2010 22:01:12 -0000
***************
*** 2835,2850 ****
  DESCR("COVAR_SAMP(double, double) aggregate final function");
  DATA(insert OID = 2817 (  float8_corr                PGNSP PGUID 12 1 0 0 f f f t f i 1 0 701 "1022" _null_ _null_
_null__null_ float8_corr _null_ _null_ _null_ )); 
  DESCR("CORR(double, double) aggregate final function");
! DATA(insert OID = 3534 (  string_agg_transfn        PGNSP PGUID 12 1 0 0 f f f f f i 2 0 2281 "2281 25" _null_ _null_
_null__null_ string_agg_transfn _null_ _null_ _null_ )); 
! DESCR("string_agg(text) transition function");
! DATA(insert OID = 3535 (  string_agg_delim_transfn    PGNSP PGUID 12 1 0 0 f f f f f i 3 0 2281 "2281 25 25" _null_
_null__null_ _null_ string_agg_delim_transfn _null_ _null_ _null_ )); 
  DESCR("string_agg(text, text) transition function");
  DATA(insert OID = 3536 (  string_agg_finalfn        PGNSP PGUID 12 1 0 0 f f f f f i 1 0 25 "2281" _null_ _null_
_null__null_ string_agg_finalfn _null_ _null_ _null_ )); 
! DESCR("string_agg final function");
! DATA(insert OID = 3537 (  string_agg                PGNSP PGUID 12 1 0 0 t f f f f i 1 0 25 "25" _null_ _null_ _null_
_null_aggregate_dummy _null_ _null_ _null_ )); 
! DESCR("concatenate aggregate input into an string");
  DATA(insert OID = 3538 (  string_agg                PGNSP PGUID 12 1 0 0 t f f f f i 2 0 25 "25 25" _null_ _null_
_null__null_ aggregate_dummy _null_ _null_ _null_ )); 
! DESCR("concatenate aggregate input into an string with delimiter");

  /* To ASCII conversion */
  DATA(insert OID = 1845 ( to_ascii    PGNSP PGUID 12 1 0 0 f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_
to_ascii_default_null_ _null_ _null_ )); 
--- 2835,2846 ----
  DESCR("COVAR_SAMP(double, double) aggregate final function");
  DATA(insert OID = 2817 (  float8_corr                PGNSP PGUID 12 1 0 0 f f f t f i 1 0 701 "1022" _null_ _null_
_null__null_ float8_corr _null_ _null_ _null_ )); 
  DESCR("CORR(double, double) aggregate final function");
! DATA(insert OID = 3535 (  string_agg_transfn        PGNSP PGUID 12 1 0 0 f f f f f i 3 0 2281 "2281 25 25" _null_
_null__null_ _null_ string_agg_transfn _null_ _null_ _null_ )); 
  DESCR("string_agg(text, text) transition function");
  DATA(insert OID = 3536 (  string_agg_finalfn        PGNSP PGUID 12 1 0 0 f f f f f i 1 0 25 "2281" _null_ _null_
_null__null_ string_agg_finalfn _null_ _null_ _null_ )); 
! DESCR("string_agg(text, text) final function");
  DATA(insert OID = 3538 (  string_agg                PGNSP PGUID 12 1 0 0 t f f f f i 2 0 25 "25 25" _null_ _null_
_null__null_ aggregate_dummy _null_ _null_ _null_ )); 
! DESCR("concatenate aggregate input into a string");

  /* To ASCII conversion */
  DATA(insert OID = 1845 ( to_ascii    PGNSP PGUID 12 1 0 0 f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_
to_ascii_default_null_ _null_ _null_ )); 
Index: src/include/utils/builtins.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/utils/builtins.h,v
retrieving revision 1.352
diff -c -r1.352 builtins.h
*** src/include/utils/builtins.h    22 Jul 2010 01:22:35 -0000    1.352
--- src/include/utils/builtins.h    4 Aug 2010 22:01:12 -0000
***************
*** 729,735 ****
  extern Datum pg_column_size(PG_FUNCTION_ARGS);

  extern Datum string_agg_transfn(PG_FUNCTION_ARGS);
- extern Datum string_agg_delim_transfn(PG_FUNCTION_ARGS);
  extern Datum string_agg_finalfn(PG_FUNCTION_ARGS);

  /* version.c */
--- 729,734 ----
***************
*** 780,788 ****
  extern Datum chr (PG_FUNCTION_ARGS);
  extern Datum repeat(PG_FUNCTION_ARGS);
  extern Datum ascii(PG_FUNCTION_ARGS);
- extern Datum string_agg_transfn(PG_FUNCTION_ARGS);
- extern Datum string_agg_delim_transfn(PG_FUNCTION_ARGS);
- extern Datum string_agg_finalfn(PG_FUNCTION_ARGS);

  /* inet_net_ntop.c */
  extern char *inet_net_ntop(int af, const void *src, int bits,
--- 779,784 ----
Index: src/test/regress/expected/aggregates.out
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/expected/aggregates.out,v
retrieving revision 1.22
diff -c -r1.22 aggregates.out
*** src/test/regress/expected/aggregates.out    18 Jul 2010 19:37:48 -0000    1.22
--- src/test/regress/expected/aggregates.out    4 Aug 2010 22:01:12 -0000
***************
*** 800,811 ****
  LINE 1: select aggfns(distinct a,a,c order by a,b)
                                                  ^
  -- string_agg tests
- select string_agg(a) from (values('aaaa'),('bbbb'),('cccc')) g(a);
-   string_agg
- --------------
-  aaaabbbbcccc
- (1 row)
-
  select string_agg(a,',') from (values('aaaa'),('bbbb'),('cccc')) g(a);
     string_agg
  ----------------
--- 800,805 ----
***************
*** 818,827 ****
   aaaa,bbbb,cccc
  (1 row)

! select string_agg(a,',') from (values(null),(null),('bbbb'),('cccc')) g(a);
   string_agg
  ------------
!  bbbb,cccc
  (1 row)

  select string_agg(a,',') from (values(null),(null)) g(a);
--- 812,821 ----
   aaaa,bbbb,cccc
  (1 row)

! select string_agg(a,'AB') from (values(null),(null),('bbbb'),('cccc')) g(a);
   string_agg
  ------------
!  bbbbABcccc
  (1 row)

  select string_agg(a,',') from (values(null),(null)) g(a);
***************
*** 831,853 ****
  (1 row)

  -- check some implicit casting cases, as per bug #5564
! select string_agg(distinct f1 order by f1) from varchar_tbl;  -- ok
   string_agg
  ------------
!  aababcd
  (1 row)

! select string_agg(distinct f1::text order by f1) from varchar_tbl;  -- not ok
  ERROR:  in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list
! LINE 1: select string_agg(distinct f1::text order by f1) from varcha...
!                                                      ^
! select string_agg(distinct f1 order by f1::text) from varchar_tbl;  -- not ok
  ERROR:  in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list
! LINE 1: select string_agg(distinct f1 order by f1::text) from varcha...
!                                                ^
! select string_agg(distinct f1::text order by f1::text) from varchar_tbl;  -- ok
   string_agg
  ------------
!  aababcd
  (1 row)

--- 825,847 ----
  (1 row)

  -- check some implicit casting cases, as per bug #5564
! select string_agg(distinct f1, ',' order by f1) from varchar_tbl;  -- ok
   string_agg
  ------------
!  a,ab,abcd
  (1 row)

! select string_agg(distinct f1::text, ',' order by f1) from varchar_tbl;  -- not ok
  ERROR:  in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list
! LINE 1: select string_agg(distinct f1::text, ',' order by f1) from v...
!                                                           ^
! select string_agg(distinct f1, ',' order by f1::text) from varchar_tbl;  -- not ok
  ERROR:  in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list
! LINE 1: select string_agg(distinct f1, ',' order by f1::text) from v...
!                                                     ^
! select string_agg(distinct f1::text, ',' order by f1::text) from varchar_tbl;  -- ok
   string_agg
  ------------
!  a,ab,abcd
  (1 row)

Index: src/test/regress/expected/opr_sanity.out
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/expected/opr_sanity.out,v
retrieving revision 1.90
diff -c -r1.90 opr_sanity.out
*** src/test/regress/expected/opr_sanity.out    14 Jan 2010 16:31:09 -0000    1.90
--- src/test/regress/expected/opr_sanity.out    4 Aug 2010 22:01:13 -0000
***************
*** 773,778 ****
--- 773,803 ----
   min     | <       |            1
  (2 rows)

+ -- Check that there are not aggregates with the same name and different
+ -- numbers of arguments.  While not technically wrong, we have a project policy
+ -- to avoid this because it opens the door for confusion in connection with
+ -- ORDER BY: novices frequently put the ORDER BY in the wrong place.
+ -- See the fate of the single-argument form of string_agg() for history.
+ -- The only aggregates that should show up here are count() and count(*).
+ SELECT p1.oid::regprocedure, p2.oid::regprocedure
+ FROM pg_proc AS p1, pg_proc AS p2
+ WHERE p1.oid < p2.oid AND p1.proname = p2.proname AND
+     p1.proisagg AND p2.proisagg AND
+     array_dims(p1.proargtypes) != array_dims(p2.proargtypes)
+ ORDER BY 1;
+      oid      |   oid
+ --------------+---------
+  count("any") | count()
+ (1 row)
+
+ -- For the same reason, aggregates with default arguments are no good.
+ SELECT oid, proname
+ FROM pg_proc AS p
+ WHERE proisagg AND proargdefaults IS NOT NULL;
+  oid | proname
+ -----+---------
+ (0 rows)
+
  -- **************** pg_opfamily ****************
  -- Look for illegal values in pg_opfamily fields
  SELECT p1.oid
Index: src/test/regress/sql/aggregates.sql
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/sql/aggregates.sql,v
retrieving revision 1.18
diff -c -r1.18 aggregates.sql
*** src/test/regress/sql/aggregates.sql    18 Jul 2010 19:37:49 -0000    1.18
--- src/test/regress/sql/aggregates.sql    4 Aug 2010 22:01:13 -0000
***************
*** 357,370 ****
    from (values (1,1,'foo')) v(a,b,c), generate_series(1,2) i;

  -- string_agg tests
- select string_agg(a) from (values('aaaa'),('bbbb'),('cccc')) g(a);
  select string_agg(a,',') from (values('aaaa'),('bbbb'),('cccc')) g(a);
  select string_agg(a,',') from (values('aaaa'),(null),('bbbb'),('cccc')) g(a);
! select string_agg(a,',') from (values(null),(null),('bbbb'),('cccc')) g(a);
  select string_agg(a,',') from (values(null),(null)) g(a);

  -- check some implicit casting cases, as per bug #5564
! select string_agg(distinct f1 order by f1) from varchar_tbl;  -- ok
! select string_agg(distinct f1::text order by f1) from varchar_tbl;  -- not ok
! select string_agg(distinct f1 order by f1::text) from varchar_tbl;  -- not ok
! select string_agg(distinct f1::text order by f1::text) from varchar_tbl;  -- ok
--- 357,369 ----
    from (values (1,1,'foo')) v(a,b,c), generate_series(1,2) i;

  -- string_agg tests
  select string_agg(a,',') from (values('aaaa'),('bbbb'),('cccc')) g(a);
  select string_agg(a,',') from (values('aaaa'),(null),('bbbb'),('cccc')) g(a);
! select string_agg(a,'AB') from (values(null),(null),('bbbb'),('cccc')) g(a);
  select string_agg(a,',') from (values(null),(null)) g(a);

  -- check some implicit casting cases, as per bug #5564
! select string_agg(distinct f1, ',' order by f1) from varchar_tbl;  -- ok
! select string_agg(distinct f1::text, ',' order by f1) from varchar_tbl;  -- not ok
! select string_agg(distinct f1, ',' order by f1::text) from varchar_tbl;  -- not ok
! select string_agg(distinct f1::text, ',' order by f1::text) from varchar_tbl;  -- ok
Index: src/test/regress/sql/opr_sanity.sql
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/sql/opr_sanity.sql,v
retrieving revision 1.73
diff -c -r1.73 opr_sanity.sql
*** src/test/regress/sql/opr_sanity.sql    29 Nov 2009 18:53:54 -0000    1.73
--- src/test/regress/sql/opr_sanity.sql    4 Aug 2010 22:01:13 -0000
***************
*** 621,626 ****
--- 621,646 ----
      amopmethod = (SELECT oid FROM pg_am WHERE amname = 'btree')
  ORDER BY 1, 2;

+ -- Check that there are not aggregates with the same name and different
+ -- numbers of arguments.  While not technically wrong, we have a project policy
+ -- to avoid this because it opens the door for confusion in connection with
+ -- ORDER BY: novices frequently put the ORDER BY in the wrong place.
+ -- See the fate of the single-argument form of string_agg() for history.
+ -- The only aggregates that should show up here are count() and count(*).
+
+ SELECT p1.oid::regprocedure, p2.oid::regprocedure
+ FROM pg_proc AS p1, pg_proc AS p2
+ WHERE p1.oid < p2.oid AND p1.proname = p2.proname AND
+     p1.proisagg AND p2.proisagg AND
+     array_dims(p1.proargtypes) != array_dims(p2.proargtypes)
+ ORDER BY 1;
+
+ -- For the same reason, aggregates with default arguments are no good.
+
+ SELECT oid, proname
+ FROM pg_proc AS p
+ WHERE proisagg AND proargdefaults IS NOT NULL;
+
  -- **************** pg_opfamily ****************

  -- Look for illegal values in pg_opfamily fields

On 4 August 2010 23:19, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I wrote:
>> Hm?  I don't think that an initdb here would have any impact on whether
>> we can call the next drop RC1 or not.  We're talking about removing a
>> single built-in entry in pg_proc --- it's one of the safest changes we
>> could possibly make.
>
> Well, I forgot that an aggregate involves more than one catalog row ;-).
> So it's a bit bigger patch than that, but still pretty small and safe.
> See attached.
>
> What we are doing here, IMO, is not just changing string_agg() but
> instituting a project policy that we are not going to offer built-in
> aggregates with the same names and different numbers of arguments ---
> otherwise the problem will come right back.  Therefore, the attached
> patch adds an opr_sanity regression test that will complain if anyone
> tries to add such.  Of course, this isn't preventing users from creating
> such aggregates, but it's on their own heads to not get confused if they
> do.

Yes, I think that's sensible.

>
> This policy also implies that we are never going to allow default
> arguments for aggregates, or at least never have any built-in ones
> that use such a feature.
>
> By my count the following people had offered an opinion on making
> this change:
>        for: tgl, josh, badalex, mmoncure
>        against: rhaas, thom
> Anybody else want to vote, or change their vote after seeing the patch?
>
>                        regards, tom lane
>
>

I was afraid that the function would be pulled completely, but from
looking at the patch, you're only removing the function with a
single-parameter signature, which is quite innocuous.  So I'm "for"
now.
--
Thom Brown
Registered Linux user: #516935


Thom Brown <thom@linux.com> writes:
> I was afraid that the function would be pulled completely, but from
> looking at the patch, you're only removing the function with a
> single-parameter signature, which is quite innocuous.

Yes, of course, sorry if I confused anyone.  It's the combination of
having both one- and two-argument forms that is the problem.  Since
the one-argument form isn't doing anything but offering a rather
useless default, we won't lose functionality if we pull it.
        regards, tom lane


On Wed, Aug 04, 2010 at 06:19:49PM -0400, Tom Lane wrote:
> I wrote:
> > Hm?  I don't think that an initdb here would have any impact on whether
> > we can call the next drop RC1 or not.  We're talking about removing a
> > single built-in entry in pg_proc --- it's one of the safest changes we
> > could possibly make.
> 
> Well, I forgot that an aggregate involves more than one catalog row ;-).
> So it's a bit bigger patch than that, but still pretty small and safe.
> See attached.
> 
> What we are doing here, IMO, is not just changing string_agg() but
> instituting a project policy that we are not going to offer built-in
> aggregates with the same names and different numbers of arguments ---
> otherwise the problem will come right back.  Therefore, the attached
> patch adds an opr_sanity regression test that will complain if anyone
> tries to add such.  Of course, this isn't preventing users from creating
> such aggregates, but it's on their own heads to not get confused if they
> do.
> 
> This policy also implies that we are never going to allow default
> arguments for aggregates, or at least never have any built-in ones
> that use such a feature.
> 
> By my count the following people had offered an opinion on making
> this change:
>     for: tgl, josh, badalex, mmoncure
>     against: rhaas, thom
> Anybody else want to vote, or change their vote after seeing the patch?

+1 for removing the single-argument version.

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


On Wed, Aug 4, 2010 at 16:33, Thom Brown <thom@linux.com> wrote:

> I was afraid that the function would be pulled completely, but from
> looking at the patch, you're only removing the function with a
> single-parameter signature, which is quite innocuous.  So I'm "for"
> now.

Ahh, Now I see why you were worried about people calling you a witch :)

On another note, I do wonder if we could avoid more confusion by just
reordering the arguments.  In-fact I bet the original argument
ordering was done precisely so it would match the 1 argument version.

I dunno about anyone else but (a, ',' order by a) just looks weird.

Or in other words, any thoughts on:
select string_agg(delim, expression);

I don't want to stretch this out, but while we are making changes...


Alex Hunsaker <badalex@gmail.com> writes:
> I dunno about anyone else but (a, ',' order by a) just looks weird.

I suppose, but aren't you just focusing on the argument being constant?
In the more general case I don't think there's anything unnatural about
this syntax.

> Or in other words, any thoughts on:
> select string_agg(delim, expression);

That looks pretty weird to me anyway, with or without use of ORDER BY.
Nobody would think to write the delimiter first.  Usually you put the
"most important" argument first, and no one would see the delimiter
as the most important one.
        regards, tom lane


On Wed, Aug 4, 2010 at 7:07 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Or in other words, any thoughts on:
>> select string_agg(delim, expression);
>
> That looks pretty weird to me anyway, with or without use of ORDER BY.
> Nobody would think to write the delimiter first.  Usually you put the
> "most important" argument first, and no one would see the delimiter
> as the most important one.

Well, it would match the syntax of things like perl's join().  But I
think that's probably not enough reason to go fiddling with it.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


On Wed, Aug 4, 2010 at 17:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Alex Hunsaker <badalex@gmail.com> writes:
>> I dunno about anyone else but (a, ',' order by a) just looks weird.
>
> I suppose, but aren't you just focusing on the argument being constant?

Yes.

>> Or in other words, any thoughts on:
>> select string_agg(delim, expression);
>
> That looks pretty weird to me anyway, with or without use of ORDER BY.
> Nobody would think to write the delimiter first.  Usually you put the
> "most important" argument first, and no one would see the delimiter
> as the most important one.

No argument about the most important arg first.  I think we have a
difference of opinion on what the important argument is :-)

It might just be my perl upbringing talking, for example you join(',',...) or split(',', ....) in perl.

Either way *shrug*  Im happy to leave it alone.


On Wed, Aug 4, 2010 at 6:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>        for: tgl, josh, badalex, mmoncure
>        against: rhaas, thom
> Anybody else want to vote, or change their vote after seeing the patch?

If we're not regarding this as beta-forcing, I abstain.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


On Wed, Aug 4, 2010 at 11:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> What we are doing here, IMO, is not just changing string_agg() but
> instituting a project policy that we are not going to offer built-in
> aggregates with the same names and different numbers of arguments ---
> otherwise the problem will come right back.

Well I think this can be a pretty soft policy. The thing is that for
string_agg it's a pretty weak argument for the one-argument form
anyways so there's not much loss in losing the 1-argument form. In
other cases the extra arguments might be for very obscure cases or
there may be lots of precedent for the variadic form and users might
expect to have it. In which case we could decide the cost/benefit
calculation comes down the other way.

-- 
greg


Greg Stark <gsstark@mit.edu> writes:
> On Wed, Aug 4, 2010 at 11:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> What we are doing here, IMO, is not just changing string_agg() but
>> instituting a project policy that we are not going to offer built-in
>> aggregates with the same names and different numbers of arguments ---
>> otherwise the problem will come right back.

> Well I think this can be a pretty soft policy.

Sure, we could break it given good cause.  What I intend with the
opr_sanity test is just that people won't be able to put something
in without being reminded of this consideration.
        regards, tom lane


I wrote:
> Well, I forgot that an aggregate involves more than one catalog row ;-).
> So it's a bit bigger patch than that, but still pretty small and safe.
> See attached.

Applied to HEAD and 9.0.  The mistaken case will now yield this:

regression=# select string_agg(f1 order by f1, ',') from text_tbl;
ERROR:  function string_agg(text) does not exist
LINE 1: select string_agg(f1 order by f1, ',') from text_tbl;              ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

It's not perfect (I don't think it's practical to get the HINT to
read "Put the ORDER BY at the end" ;-)) but at least it should
get people pointed in the right direction when they do this.
        regards, tom lane


On ons, 2010-08-04 at 18:19 -0400, Tom Lane wrote:
> 
> This policy also implies that we are never going to allow default
> arguments for aggregates, or at least never have any built-in ones
> that use such a feature.
> 
> By my count the following people had offered an opinion on making
> this change:
>         for: tgl, josh, badalex, mmoncure
>         against: rhaas, thom
> Anybody else want to vote, or change their vote after seeing the
> patch?

I vote against this patch.  There are plenty of other places that SQL is
confusing, and this move seems excessive to me, and I find the
functionality that is proposed for removal quite useful.



Peter Eisentraut <peter_e@gmx.net> writes:
> I vote against this patch.  There are plenty of other places that SQL is
> confusing, and this move seems excessive to me, and I find the
> functionality that is proposed for removal quite useful.

Huh?  The functionality proposed for removal is only that of omitting an
explicit delimiter argument for string_agg().  Since the default value
(an empty string) doesn't seem to be the right thing all that often
anyway, I'm not following why you think this is a significant downgrade.
        regards, tom lane


On Aug 5, 2010, at 11:25 AM, Tom Lane wrote:

> Applied to HEAD and 9.0.  The mistaken case will now yield this:
>
> regression=# select string_agg(f1 order by f1, ',') from text_tbl;
> ERROR:  function string_agg(text) does not exist
> LINE 1: select string_agg(f1 order by f1, ',') from text_tbl;
>               ^

I'm confused: that looks like the two-argument form to me. Have I missed something?

> HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
>
> It's not perfect (I don't think it's practical to get the HINT to
> read "Put the ORDER BY at the end" ;-)) but at least it should
> get people pointed in the right direction when they do this.

It confuses the shit out of me. It says "string_agg(text)" doesn't exist when that clearly is not the name of the
functionyou've called. 

Best,

David



On 5 August 2010 19:39, David E. Wheeler <david@kineticode.com> wrote:
> On Aug 5, 2010, at 11:25 AM, Tom Lane wrote:
>
>> Applied to HEAD and 9.0.  The mistaken case will now yield this:
>>
>> regression=# select string_agg(f1 order by f1, ',') from text_tbl;
>> ERROR:  function string_agg(text) does not exist
>> LINE 1: select string_agg(f1 order by f1, ',') from text_tbl;
>>               ^
>
> I'm confused: that looks like the two-argument form to me. Have I missed something?
>
>> HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
>>
>> It's not perfect (I don't think it's practical to get the HINT to
>> read "Put the ORDER BY at the end" ;-)) but at least it should
>> get people pointed in the right direction when they do this.
>
> It confuses the shit out of me. It says "string_agg(text)" doesn't exist when that clearly is not the name of the
functionyou've called. 
>

What function name do you believe was called?

--
Thom Brown
Registered Linux user: #516935


On Thu, Aug 5, 2010 at 12:25, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> regression=# select string_agg(f1 order by f1, ',') from text_tbl;
> ERROR:  function string_agg(text) does not exist
> LINE 1: select string_agg(f1 order by f1, ',') from text_tbl;
>               ^
> HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
>
> It's not perfect (I don't think it's practical to get the HINT to
> read "Put the ORDER BY at the end" ;-)) but at least it should
> get people pointed in the right direction when they do this.

Not to mention I think most of the confusion came from using the 1
argument version first (with an order by) and then jumping straight to
the 2 arg version.


"David E. Wheeler" <david@kineticode.com> writes:
> On Aug 5, 2010, at 11:25 AM, Tom Lane wrote:
>> Applied to HEAD and 9.0.  The mistaken case will now yield this:
>> regression=# select string_agg(f1 order by f1, ',') from text_tbl;
>> ERROR:  function string_agg(text) does not exist

> I'm confused: that looks like the two-argument form to me. Have I missed something?

Yeah, the whole point of the thread: that's not a call of a two-argument
aggregate.  It's a call of a one-argument aggregate, using a two-column
sort key to order the aggregate input rows.

> It confuses the shit out of me. It says "string_agg(text)" doesn't exist when that clearly is not the name of the
functionyou've called.
 

Well, maybe we need to expend some more sweat on the error message then.
But this patch was still a prerequisite thing, because without it there
is no error that we can complain about.
        regards, tom lane


On Aug 5, 2010, at 11:42 AM, Thom Brown wrote:

>>> LINE 1: select string_agg(f1 order by f1, ',') from text_tbl;
>>>               ^
>>
>> I'm confused: that looks like the two-argument form to me. Have I missed something?
>>
>>> HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
>>>
>>> It's not perfect (I don't think it's practical to get the HINT to
>>> read "Put the ORDER BY at the end" ;-)) but at least it should
>>> get people pointed in the right direction when they do this.
>>
>> It confuses the shit out of me. It says "string_agg(text)" doesn't exist when that clearly is not the name of the
functionyou've called. 
>>
>
> What function name do you believe was called?

The message says:
   string_agg(f1 order by f1, ',')

That looks like string_agg(text, text) or string_agg(anyelement, text).

Best,

David



On Aug 5, 2010, at 11:45 AM, Tom Lane wrote:

>> I'm confused: that looks like the two-argument form to me. Have I missed something?
>
> Yeah, the whole point of the thread: that's not a call of a two-argument
> aggregate.  It's a call of a one-argument aggregate, using a two-column
> sort key to order the aggregate input rows.

OH!. Wow, weird. I never noticed that.

>> It confuses the shit out of me. It says "string_agg(text)" doesn't exist when that clearly is not the name of the
functionyou've called. 
>
> Well, maybe we need to expend some more sweat on the error message then.
> But this patch was still a prerequisite thing, because without it there
> is no error that we can complain about.

Yeah, understood.

Best,

David



> Well, maybe we need to expend some more sweat on the error message then.
> But this patch was still a prerequisite thing, because without it there
> is no error that we can complain about.

Yes, I'd say an addition to the HINT is in order *assuming* at that
stage we can tell if the user passed an ORDER BY or not.

--                                  -- Josh Berkus                                    PostgreSQL Experts Inc.
                        http://www.pgexperts.com
 


Josh Berkus <josh@agliodbs.com> writes:
>> Well, maybe we need to expend some more sweat on the error message then.
>> But this patch was still a prerequisite thing, because without it there
>> is no error that we can complain about.

> Yes, I'd say an addition to the HINT is in order *assuming* at that
> stage we can tell if the user passed an ORDER BY or not.

I was just looking at this, and realized I was mistaken earlier: the
error is issued in ParseFuncOrColumn, which already is passed the
agg_order list, so actually it's completely trivial to tell whether
a variant error message is appropriate.  I suggest that we key it off
there being not just an ORDER BY, but an ORDER BY with more than one
element; if there's only one then this cannot be the source of
confusion.

Next question: exactly how should the variant HINT be phrased?
I'm inclined to drop the bit about explicit casts and make it read
something like

HINT: No aggregate function matches the given name and argument
types. Perhaps you misplaced ORDER BY; ORDER BY must appear after all
regular arguments of the aggregate.
        regards, tom lane


On Thu, Aug 5, 2010 at 3:16 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Josh Berkus <josh@agliodbs.com> writes:
>>> Well, maybe we need to expend some more sweat on the error message then.
>>> But this patch was still a prerequisite thing, because without it there
>>> is no error that we can complain about.
>
>> Yes, I'd say an addition to the HINT is in order *assuming* at that
>> stage we can tell if the user passed an ORDER BY or not.
>
> I was just looking at this, and realized I was mistaken earlier: the
> error is issued in ParseFuncOrColumn, which already is passed the
> agg_order list, so actually it's completely trivial to tell whether
> a variant error message is appropriate.  I suggest that we key it off
> there being not just an ORDER BY, but an ORDER BY with more than one
> element; if there's only one then this cannot be the source of
> confusion.
>
> Next question: exactly how should the variant HINT be phrased?
> I'm inclined to drop the bit about explicit casts and make it read
> something like
>
> HINT: No aggregate function matches the given name and argument
> types. Perhaps you misplaced ORDER BY; ORDER BY must appear after all
> regular arguments of the aggregate.

Could we arrange to emit this error message only when there is an
aggregate with the same name but different arguments?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


On Aug 5, 2010, at 12:16 PM, Tom Lane wrote:

> HINT: No aggregate function matches the given name and argument
> types. Perhaps you misplaced ORDER BY; ORDER BY must appear after all
> regular arguments of the aggregate.

+1

David




Robert Haas <robertmhaas@gmail.com> writes:
> On Thu, Aug 5, 2010 at 3:16 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Next question: exactly how should the variant HINT be phrased?
>> I'm inclined to drop the bit about explicit casts and make it read
>> something like
>> 
>> HINT: No aggregate function matches the given name and argument
>> types. Perhaps you misplaced ORDER BY; ORDER BY must appear after all
>> regular arguments of the aggregate.

> Could we arrange to emit this error message only when there is an
> aggregate with the same name but different arguments?

That'd move it into the category of needing significant restructuring,
I'm afraid.  At the moment it's not apparent that it's worth it.
We're already able to limit the use of the variant hint to a pretty
darn narrow set of cases, and it is only a hint after all.
        regards, tom lane


On 8/5/10 12:18 PM, Robert Haas wrote:
> Could we arrange to emit this error message only when there is an
> aggregate with the same name but different arguments?

Personally, I don't see this as really necessary.  Just mentioning ORDER
BY in the hint will be enough to give people the right place to look.

--                                  -- Josh Berkus                                    PostgreSQL Experts Inc.
                        http://www.pgexperts.com
 


Josh Berkus <josh@agliodbs.com> writes:
> On 8/5/10 12:18 PM, Robert Haas wrote:
>> Could we arrange to emit this error message only when there is an
>> aggregate with the same name but different arguments?

> Personally, I don't see this as really necessary.  Just mentioning ORDER
> BY in the hint will be enough to give people the right place to look.

I suppose Robert is more concerned about the possibility that we emit
the ORDER BY hint when that isn't really the source of the problem.
But after all, the reason it's a hint and not the primary error message
is that it's not certain to be helpful.
        regards, tom lane


On tor, 2010-08-05 at 14:38 -0400, Tom Lane wrote:
> Huh?  The functionality proposed for removal is only that of omitting
> an explicit delimiter argument for string_agg().  Since the default
> value (an empty string) doesn't seem to be the right thing all that
> often anyway, I'm not following why you think this is a significant
> downgrade.

I just think it's useful to have the one-argument version.  I understand
the functionality is available in other ways.



Peter Eisentraut <peter_e@gmx.net> writes:
> On tor, 2010-08-05 at 14:38 -0400, Tom Lane wrote:
>> Huh?  The functionality proposed for removal is only that of omitting
>> an explicit delimiter argument for string_agg().  Since the default
>> value (an empty string) doesn't seem to be the right thing all that
>> often anyway, I'm not following why you think this is a significant
>> downgrade.

> I just think it's useful to have the one-argument version.  I understand
> the functionality is available in other ways.

Well, other things being equal I'd have preferred to keep the
one-argument version too.  But this thread has made it even clearer than
before that we will get continuing bug reports if we leave the behavior
alone.  I don't think the ability to leave off the delimiter value is
worth the amount of confusion it'll cause.
        regards, tom lane