Thread

  1. patch: bytea_agg

    Pavel Stehule <pavel.stehule@gmail.com> — 2011-12-21T10:04:16Z

    Hello
    
    this patch adds a bytea_agg aggregation.
    
    It allow fast bytea concatetation.
    
    Regards
    
    Pavel Stehule
    
  2. Re: patch: bytea_agg

    Robert Haas <robertmhaas@gmail.com> — 2011-12-22T16:49:26Z

    On Wed, Dec 21, 2011 at 5:04 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    > this patch adds a bytea_agg aggregation.
    >
    > It allow fast bytea concatetation.
    
    Looks fine to me.  I'll commit this, barring objections.
    
    -- 
    Robert Haas
    EnterpriseDB: http://www.enterprisedb.com
    The Enterprise PostgreSQL Company
    
    
  3. Re: patch: bytea_agg

    Robert Haas <robertmhaas@gmail.com> — 2011-12-23T13:42:51Z

    On Thu, Dec 22, 2011 at 11:49 AM, Robert Haas <robertmhaas@gmail.com> wrote:
    > On Wed, Dec 21, 2011 at 5:04 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    >> this patch adds a bytea_agg aggregation.
    >>
    >> It allow fast bytea concatetation.
    >
    > Looks fine to me.  I'll commit this, barring objections.
    
    Committed.
    
    -- 
    Robert Haas
    EnterpriseDB: http://www.enterprisedb.com
    The Enterprise PostgreSQL Company
    
    
  4. Re: patch: bytea_agg

    Peter Eisentraut <peter_e@gmx.net> — 2011-12-23T17:51:38Z

    On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    > this patch adds a bytea_agg aggregation.
    > 
    > It allow fast bytea concatetation.
    
    Why not call it string_agg?  All the function names are the same between
    text and bytea (e.g., ||, substr, position, length).  It would be nice
    not to introduce arbitrary differences.
    
    
    
  5. Re: patch: bytea_agg

    Pavel Stehule <pavel.stehule@gmail.com> — 2011-12-23T18:23:13Z

    Hello
    
    2011/12/23 Peter Eisentraut <peter_e@gmx.net>:
    > On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    >> this patch adds a bytea_agg aggregation.
    >>
    >> It allow fast bytea concatetation.
    >
    > Why not call it string_agg?  All the function names are the same between
    > text and bytea (e.g., ||, substr, position, length).  It would be nice
    > not to introduce arbitrary differences.
    
    My opinion is not too strong. I don't think so using string_agg is
    good name (for bytea_agg) - as minimal (and only one) reason is
    different API - there is no support for delimiter. If I remember well
    discussion about string_agg, where delimiter is not optimal, there is
    request for immutable interface for aggregates - there was a issue
    with ORDER clause. So bytea_agg is good name.
    
    Regards
    
    Pavel
    
    >
    
    
  6. Re: patch: bytea_agg

    Pavel Stehule <pavel.stehule@gmail.com> — 2011-12-23T18:25:07Z

    Hello
    
    2011/12/23 Peter Eisentraut <peter_e@gmx.net>:
    > On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    >> this patch adds a bytea_agg aggregation.
    >>
    >> It allow fast bytea concatetation.
    >
    > Why not call it string_agg?  All the function names are the same between
    > text and bytea (e.g., ||, substr, position, length).  It would be nice
    > not to introduce arbitrary differences.
    
    My opinion is not strong. I don't think so using string_agg is good
    name (- as minimal (and only one) reason is different API - there is
    no support for delimiter. If I remember well discussion about
    string_agg, where delimiter is not optimal, there is request for
    immutable interface for aggregates - there was a issue with ORDER
    clause. So bytea_agg is good name.
    
    Regards
    
    Pavel
    
    >
    
    
  7. Re: patch: bytea_agg

    Robert Haas <robertmhaas@gmail.com> — 2011-12-23T18:30:26Z

    On Fri, Dec 23, 2011 at 12:51 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    > On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    >> this patch adds a bytea_agg aggregation.
    >>
    >> It allow fast bytea concatetation.
    >
    > Why not call it string_agg?  All the function names are the same between
    > text and bytea (e.g., ||, substr, position, length).  It would be nice
    > not to introduce arbitrary differences.
    
    Well, because it doesn't operate on strings.
    
    I argued when we added string_agg that it ought to be called
    concat_agg, or something like that, but I got shouted down.  So now
    here we are.
    
    -- 
    Robert Haas
    EnterpriseDB: http://www.enterprisedb.com
    The Enterprise PostgreSQL Company
    
    
  8. Re: patch: bytea_agg

    Peter Eisentraut <peter_e@gmx.net> — 2011-12-23T19:16:11Z

    On fre, 2011-12-23 at 13:30 -0500, Robert Haas wrote:
    > On Fri, Dec 23, 2011 at 12:51 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    > > On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    > >> this patch adds a bytea_agg aggregation.
    > >>
    > >> It allow fast bytea concatetation.
    > >
    > > Why not call it string_agg?  All the function names are the same between
    > > text and bytea (e.g., ||, substr, position, length).  It would be nice
    > > not to introduce arbitrary differences.
    > 
    > Well, because it doesn't operate on strings.
    
    Sure, binary strings.  Both the SQL standard and the PostgreSQL
    documentation use that term.
    
    
    
    
  9. Re: patch: bytea_agg

    Robert Haas <robertmhaas@gmail.com> — 2011-12-23T19:19:34Z

    On Fri, Dec 23, 2011 at 2:16 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    > On fre, 2011-12-23 at 13:30 -0500, Robert Haas wrote:
    >> On Fri, Dec 23, 2011 at 12:51 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    >> > On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    >> >> this patch adds a bytea_agg aggregation.
    >> >>
    >> >> It allow fast bytea concatetation.
    >> >
    >> > Why not call it string_agg?  All the function names are the same between
    >> > text and bytea (e.g., ||, substr, position, length).  It would be nice
    >> > not to introduce arbitrary differences.
    >>
    >> Well, because it doesn't operate on strings.
    >
    > Sure, binary strings.  Both the SQL standard and the PostgreSQL
    > documentation use that term.
    
    I'm unimpressed by that argument, but let's see what other people think.
    
    -- 
    Robert Haas
    EnterpriseDB: http://www.enterprisedb.com
    The Enterprise PostgreSQL Company
    
    
  10. Re: patch: bytea_agg

    Kevin Grittner <kevin.grittner@wicourts.gov> — 2011-12-23T19:35:21Z

    Robert Haas <robertmhaas@gmail.com> wrote:
    > Peter Eisentraut <peter_e@gmx.net> wrote:
    >> Robert Haas wrote:
    >>> Peter Eisentraut <peter_e@gmx.net> wrote:
    >>>> On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    >>>>> this patch adds a bytea_agg aggregation.
    >>>>>
    >>>>> It allow fast bytea concatetation.
    >>>>
    >>>> Why not call it string_agg?  All the function names are the
    >>>> same between text and bytea (e.g., ||, substr, position,
    >>>> length).  It would be nice not to introduce arbitrary
    >>>> differences.
    >>>
    >>> Well, because it doesn't operate on strings.
    >>
    >> Sure, binary strings.  Both the SQL standard and the PostgreSQL
    >> documentation use that term.
    > 
    > I'm unimpressed by that argument, but let's see what other people
    > think.
     
    I, for one, try to be consistent about saying "character strings"
    when that is what I mean.  Since at least the SQL-92 standard there
    have been both "character strings" and "bit strings", with a certain
    amount of symmetry in how they are handled.   I don't remember when
    binary strings were introduced, but that is the standard
    terminology.  There is, for example, a standard substring function
    for binary strings.
     
    -Kevin
    
    
  11. Re: patch: bytea_agg

    Tom Lane <tgl@sss.pgh.pa.us> — 2011-12-23T21:19:57Z

    Robert Haas <robertmhaas@gmail.com> writes:
    > On Fri, Dec 23, 2011 at 2:16 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    >> On fre, 2011-12-23 at 13:30 -0500, Robert Haas wrote:
    >>> Well, because it doesn't operate on strings.
    
    >> Sure, binary strings. Both the SQL standard and the PostgreSQL
    >> documentation use that term.
    
    > I'm unimpressed by that argument, but let's see what other people think.
    
    I generally agree with Peter: string_agg makes sense here.  The only
    real argument against it is Pavel's point that he didn't include a
    delimiter parameter, but that just begs the question why not.  It
    seems at least plausible that there would be use-cases for it.
    
    So I think we should try to make this as much like the text case as
    possible.
    
    			regards, tom lane
    
    
  12. Re: patch: bytea_agg

    Pavel Stehule <pavel.stehule@gmail.com> — 2011-12-23T21:36:11Z

    Hello
    
    2011/12/23 Tom Lane <tgl@sss.pgh.pa.us>:
    > Robert Haas <robertmhaas@gmail.com> writes:
    >> On Fri, Dec 23, 2011 at 2:16 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    >>> On fre, 2011-12-23 at 13:30 -0500, Robert Haas wrote:
    >>>> Well, because it doesn't operate on strings.
    >
    >>> Sure, binary strings.  Both the SQL standard and the PostgreSQL
    >>> documentation use that term.
    >
    >> I'm unimpressed by that argument, but let's see what other people think.
    >
    > I generally agree with Peter: string_agg makes sense here.  The only
    > real argument against it is Pavel's point that he didn't include a
    > delimiter parameter, but that just begs the question why not.  It
    > seems at least plausible that there would be use-cases for it.
    
    I don't know a real usage for bytea delimiter. Probably there is, but
    I expect so most often use case will be without delimiter. And when it
    is necessary, then || should be used. I see two ways:
    
    a) use it bytea_agg as it now
    b) use a string_agg with delimiter, that will be usually empty.
    
    Using a string_agg for bytea is not too intuitive (but has sense) -
    maybe we can introduce a synonym type for bytea - like "binary string"
    or "bstring".
    
    Regards
    
    Pavel
    
    
    >
    > So I think we should try to make this as much like the text case as
    > possible.
    >
    >                        regards, tom lane
    
    
  13. Re: patch: bytea_agg

    Kevin Grittner <kevin.grittner@wicourts.gov> — 2011-12-23T21:48:56Z

    Pavel Stehule <pavel.stehule@gmail.com> wrote:
     
    > maybe we can introduce a synonym type for bytea - like "binary
    > string" or "bstring".
     
    The standard mentions these names for binary strings:
     
    BINARY, BINARY VARYING, or BINARY LARGE OBJECT
     
    which have a certain symmetry with:
     
    CHARACTER, CHARACTER VARYING, and CHARACTER
    LARGE OBJECT
     
    -Kevin
    
    
  14. Re: patch: bytea_agg

    Alvaro Herrera <alvherre@commandprompt.com> — 2011-12-24T01:44:11Z

    Excerpts from Pavel Stehule's message of vie dic 23 18:36:11 -0300 2011:
    > Hello
    > 
    > 2011/12/23 Tom Lane <tgl@sss.pgh.pa.us>:
    
    > > I generally agree with Peter: string_agg makes sense here.  The only
    > > real argument against it is Pavel's point that he didn't include a
    > > delimiter parameter, but that just begs the question why not.  It
    > > seems at least plausible that there would be use-cases for it.
    > 
    > I don't know a real usage for bytea delimiter. Probably there is, but
    > I expect so most often use case will be without delimiter.
    
    Well, sometimes bytea is used to store character strings when the
    encoding information is to be handled by the app instead of having
    Postgres know it, for various reasons.  I haven't seen any of those
    cases yet that would use string_add(bytea) but I wouldn't foreclose that
    possibility.
    
    -- 
    Álvaro Herrera <alvherre@commandprompt.com>
    The PostgreSQL Company - Command Prompt, Inc.
    PostgreSQL Replication, Consulting, Custom Development, 24x7 support
    
    
  15. Re: patch: bytea_agg

    Merlin Moncure <mmoncure@gmail.com> — 2011-12-24T13:13:32Z

    On Fri, Dec 23, 2011 at 12:30 PM, Robert Haas <robertmhaas@gmail.com> wrote:
    > Well, because it doesn't operate on strings.
    >
    > I argued when we added string_agg that it ought to be called
    > concat_agg, or something like that, but I got shouted down.  So now
    > here we are.
    
    +1.  Using the input type names to name the function is a mistake and
    should be stopped...enough.  It's verbose and unnecessary...everything
    else in sql is heavily overloaded (we don't have int_max() and
    float_max()).
    
    merlin
    
    
  16. Re: patch: bytea_agg

    Peter Eisentraut <peter_e@gmx.net> — 2012-04-04T20:20:20Z

    On fre, 2011-12-23 at 19:51 +0200, Peter Eisentraut wrote:
    > On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    > > this patch adds a bytea_agg aggregation.
    > > 
    > > It allow fast bytea concatetation.
    > 
    > Why not call it string_agg?  All the function names are the same between
    > text and bytea (e.g., ||, substr, position, length).  It would be nice
    > not to introduce arbitrary differences.
    
    Here is a patch to do the renaming.  As it stands, it fails the
    opr_sanity regression test, because that complains that there are now
    two aggregate functions string_agg with different number of arguments.
    It seems to me that that test should really only complain if the common
    argument types of the two aggregates are the same, correct?
    
    
  17. Re: patch: bytea_agg

    Tom Lane <tgl@sss.pgh.pa.us> — 2012-04-04T22:59:36Z

    Peter Eisentraut <peter_e@gmx.net> writes:
    > On fre, 2011-12-23 at 19:51 +0200, Peter Eisentraut wrote:
    >> On ons, 2011-12-21 at 11:04 +0100, Pavel Stehule wrote:
    >>> this patch adds a bytea_agg aggregation.
    
    >> Why not call it string_agg?
    
    > Here is a patch to do the renaming.  As it stands, it fails the
    > opr_sanity regression test, because that complains that there are now
    > two aggregate functions string_agg with different number of arguments.
    > It seems to me that that test should really only complain if the common
    > argument types of the two aggregates are the same, correct?
    
    Uh, no.  That test is there for good and sufficient reasons, as per its
    comment:
    
    -- 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 renaming you propose would only be acceptable to those who have
    forgotten that history.  I haven't.
    
    			regards, tom lane
    
    
  18. Re: patch: bytea_agg

    Greg Stark <stark@mit.edu> — 2012-04-04T23:22:59Z

    On Wed, Apr 4, 2012 at 11:59 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > The renaming you propose would only be acceptable to those who have
    > forgotten that history.  I haven't.
    
    I had. I looked it up
    http://archives.postgresql.org/pgsql-bugs/2010-08/msg00044.php
    
    That was quite a thread.
    
    -- 
    greg
    
    
  19. Re: patch: bytea_agg

    Peter Eisentraut <peter_e@gmx.net> — 2012-04-07T10:52:00Z

    On ons, 2012-04-04 at 18:59 -0400, Tom Lane wrote:
    > 
    > >> Why not call it string_agg?
    > 
    > > Here is a patch to do the renaming.  As it stands, it fails the
    > > opr_sanity regression test, because that complains that there are now
    > > two aggregate functions string_agg with different number of arguments.
    > > It seems to me that that test should really only complain if the common
    > > argument types of the two aggregates are the same, correct?
    > 
    > Uh, no.  That test is there for good and sufficient reasons, as per its
    > comment:
    > 
    > -- 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 renaming you propose would only be acceptable to those who have
    > forgotten that history.  I haven't.
    
    I had reviewed that thread very carefully, but I'm not sure it applies.
    The issue was that we don't want aggregates with optional second
    argument, because "novices" could confuse
    
    agg(a, b ORDER BY c)
    
    with
    
    agg(a ORDER BY b, c)  -- wrong
    
    without the error being flagged.
    
    But that doesn't apply if the first argument has different types.
    Erroneously calling agg(textdatum ORDER BY textdatum, sthelse) will not
    result in a call to agg(bytea).  (Unless the textdatum is really an
    unknown literal, but that would be silly.)
    
    Nevertheless, the problem would now be that adding string_agg(bytea)
    would effectively forbid adding string_agg(bytea, delim) in the future.
    So making a two-argument string_agg(bytea, bytea) now seems like the
    best solution anyway.  (This applies independently of the function
    renaming, actually.)
    
    
    
    
  20. Re: patch: bytea_agg

    Tom Lane <tgl@sss.pgh.pa.us> — 2012-04-07T14:38:08Z

    Peter Eisentraut <peter_e@gmx.net> writes:
    > On ons, 2012-04-04 at 18:59 -0400, Tom Lane wrote:
    >> Uh, no.  That test is there for good and sufficient reasons, as per its
    >> comment:
    
    > I had reviewed that thread very carefully, but I'm not sure it applies.
    > The issue was that we don't want aggregates with optional second
    > argument, because "novices" could confuse
    
    > agg(a, b ORDER BY c)
    
    > with
    
    > agg(a ORDER BY b, c)  -- wrong
    
    > without the error being flagged.
    
    > But that doesn't apply if the first argument has different types.
    > Erroneously calling agg(textdatum ORDER BY textdatum, sthelse) will not
    > result in a call to agg(bytea).
    
    The point of the policy is to be sure that we will throw a specific
    error message with a suitable hint when a malformed call is made.
    If there are alternative aggregates in the catalogs that have the
    potential to "capture" such a call, then we risk the wrong thing
    happening.  It appears that the lack of any implicit cast from bytea to
    text would prevent that today, but I still think this proposal boxes
    us in to an unreasonable degree compared to the benefit.  For example,
    this would greatly restrict our ability to throw "ambiguous aggregate"
    messages.
    
    > Nevertheless, the problem would now be that adding string_agg(bytea)
    > would effectively forbid adding string_agg(bytea, delim) in the future.
    > So making a two-argument string_agg(bytea, bytea) now seems like the
    > best solution anyway.  (This applies independently of the function
    > renaming, actually.)
    
    Hm.  So are you now suggesting we should get rid of one-argument
    bytea_agg and replace it with two-argument string_agg(bytea,bytea)?
    I could support that, since we've not released bytea_agg yet.
    
    			regards, tom lane
    
    
  21. Re: patch: bytea_agg

    Peter Eisentraut <peter_e@gmx.net> — 2012-04-11T17:46:55Z

    On lör, 2012-04-07 at 10:38 -0400, Tom Lane wrote:
    > > Nevertheless, the problem would now be that adding string_agg(bytea)
    > > would effectively forbid adding string_agg(bytea, delim) in the
    > future.
    > > So making a two-argument string_agg(bytea, bytea) now seems like the
    > > best solution anyway.  (This applies independently of the function
    > > renaming, actually.)
    > 
    > Hm.  So are you now suggesting we should get rid of one-argument
    > bytea_agg and replace it with two-argument string_agg(bytea,bytea)?
    > I could support that, since we've not released bytea_agg yet.
    
    Yes, that looks like the best solution.  Here is a patch for that.
    
  22. Re: patch: bytea_agg

    Tom Lane <tgl@sss.pgh.pa.us> — 2012-04-11T17:57:13Z

    Peter Eisentraut <peter_e@gmx.net> writes:
    > On lr, 2012-04-07 at 10:38 -0400, Tom Lane wrote:
    >> Hm.  So are you now suggesting we should get rid of one-argument
    >> bytea_agg and replace it with two-argument string_agg(bytea,bytea)?
    >> I could support that, since we've not released bytea_agg yet.
    
    > Yes, that looks like the best solution.  Here is a patch for that.
    
    Looks sane in a quick once-over, except for the documentation entry.
    I'm not really thrilled with "text, text or bytea, bytea" because it
    seems easy to misparse.  Moreover, as written the entry claims that
    the return type is text either way, which is wrong.  You could fix
    the latter by writing "same as argument data type", but I wonder
    whether it'd be better to make separate table entries for the two
    forms.
    
    			regards, tom lane