coalesce

Started by Henry Drexlerover 14 years ago9 messagesdocs
Jump to latest
#1Henry Drexler
alonup8tb@gmail.com

http://www.postgresql.org/docs/9.1/static/functions-conditional.html

states: "The COALESCE function returns the first of its arguments that is
not null. Null is returned only if all arguments are null."

I was having a terrible time understanding this, and looking at the two
examples were just as confusing I could not get it to work right.

not sure if others have had the same difficulty, but here are my suggested
adjustments:

Then on someones website this made perfect sense to me:
" If the results of the first argument are null, it will return the
second."

so I made this example that makes sense:

COALESCE(column,substitute value)

#2Kevin Grittner
Kevin.Grittner@wicourts.gov
In reply to: Henry Drexler (#1)
Re: coalesce

Henry Drexler <alonup8tb@gmail.com> wrote:

"If the results of the first argument are null, it will return the
second."

Unless the second is also null, in which case it will return the
third. Unless the third is also null...

The trick is to come up with language which recognizes that there
can be any number of arguments. Personally, I think the existing
language does a good job of that, and is pretty clear.

so I made this example that makes sense:

COALESCE(column,substitute value)

Perhaps a two-argument example would be helpful, as long as it
doesn't mislead people into thinking the construct is limited to two
arguments.

-Kevin

#3Henry Drexler
alonup8tb@gmail.com
In reply to: Kevin Grittner (#2)
Re: coalesce

thanks,

so I take it I am not getting those more complex examples (that are
apparently beyond my use case), I will take a look at them again.

Thank you for the feedback.

On Wed, Sep 21, 2011 at 10:33 AM, Kevin Grittner <
Kevin.Grittner@wicourts.gov> wrote:

Show quoted text

Henry Drexler <alonup8tb@gmail.com> wrote:

"If the results of the first argument are null, it will return the
second."

Unless the second is also null, in which case it will return the
third. Unless the third is also null...

The trick is to come up with language which recognizes that there
can be any number of arguments. Personally, I think the existing
language does a good job of that, and is pretty clear.

so I made this example that makes sense:

COALESCE(column,substitute value)

Perhaps a two-argument example would be helpful, as long as it
doesn't mislead people into thinking the construct is limited to two
arguments.

-Kevin

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Henry Drexler (#3)
Re: coalesce

Excerpts from Henry Drexler's message of mié sep 21 12:50:18 -0300 2011:

thanks,

so I take it I am not getting those more complex examples (that are
apparently beyond my use case), I will take a look at them again.

Maybe the fix is just to add a simpler example, without altering the
wording (which seems pretty clear to me as well, but then I already know
what COALESCE does).

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#5Bruce Momjian
bruce@momjian.us
In reply to: Alvaro Herrera (#4)
Re: coalesce

Alvaro Herrera wrote:

Excerpts from Henry Drexler's message of mi�� sep 21 12:50:18 -0300 2011:

thanks,

so I take it I am not getting those more complex examples (that are
apparently beyond my use case), I will take a look at them again.

Maybe the fix is just to add a simpler example, without altering the
wording (which seems pretty clear to me as well, but then I already know
what COALESCE does).

The current example is:

SELECT COALESCE(description, short_description, '(none)') ...

What would a simpler one look like?

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#6Bruce Momjian
bruce@momjian.us
In reply to: Alvaro Herrera (#4)
Re: coalesce

Alvaro Herrera wrote:

Excerpts from Henry Drexler's message of mi�� sep 21 12:50:18 -0300 2011:

thanks,

so I take it I am not getting those more complex examples (that are
apparently beyond my use case), I will take a look at them again.

Maybe the fix is just to add a simpler example, without altering the
wording (which seems pretty clear to me as well, but then I already know
what COALESCE does).

Here is a doc patch that at least explains the example. Applied.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachments:

/rtmp/coalescetext/x-diffDownload+2-0
#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#6)
Re: coalesce

Bruce Momjian <bruce@momjian.us> writes:

Here is a doc patch that at least explains the example. Applied.

I think s/or/otherwise/ (both places) would make that read better.

regards, tom lane

#8Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#7)
Re: coalesce

Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

Here is a doc patch that at least explains the example. Applied.

I think s/or/otherwise/ (both places) would make that read better.

Done with the attached patch.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachments:

/rtmp/coalesce2text/x-diffDownload+4-4
#9Henry Drexler
alonup8tb@gmail.com
In reply to: Bruce Momjian (#8)
Re: coalesce

That is certainly clearer - thank you.

On Tue, Oct 4, 2011 at 10:39 PM, Bruce Momjian <bruce@momjian.us> wrote:

Show quoted text

Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

Here is a doc patch that at least explains the example. Applied.

I think s/or/otherwise/ (both places) would make that read better.

Done with the attached patch.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +