Re: [GENERAL] default value returned from sql stmt

2012-03-30 Thread Alban Hertroys
On 30 Mar 2012, at 10:22, Richard Huxton wrote: > On 30/03/12 08:46, Pavel Stehule wrote: >> 2012/3/30 Richard Huxton: >>> On 29/03/12 23:28, Pavel Stehule wrote: select anum from t1 where anum = 4 union all select 100 limit 1; >>> >>> >>> I'm not sure the ordering here is guaran

Re: [GENERAL] default value returned from sql stmt

2012-03-30 Thread Pavel Stehule
2012/3/30 Richard Huxton : > On 30/03/12 08:46, Pavel Stehule wrote: >> >> 2012/3/30 Richard Huxton: >>> >>> On 29/03/12 23:28, Pavel Stehule wrote: select anum from t1 where anum = 4 union all select 100 limit 1; >>> >>> >>> >>> I'm not sure the ordering here is guaranteed by t

Re: [GENERAL] default value returned from sql stmt

2012-03-30 Thread Richard Huxton
On 30/03/12 08:46, Pavel Stehule wrote: 2012/3/30 Richard Huxton: On 29/03/12 23:28, Pavel Stehule wrote: select anum from t1 where anum = 4 union all select 100 limit 1; I'm not sure the ordering here is guaranteed by the standard though, is it? You could end up with the 4 being discarded.

Re: [GENERAL] default value returned from sql stmt

2012-03-30 Thread Pavel Stehule
2012/3/30 Richard Huxton : > On 29/03/12 23:28, Pavel Stehule wrote: >> >> select anum from t1 where anum = 4 >> union all select 100 limit 1; > > > I'm not sure the ordering here is guaranteed by the standard though, is it? > You could end up with the 4 being discarded. A order is random for only

Re: [GENERAL] default value returned from sql stmt

2012-03-30 Thread Richard Huxton
On 29/03/12 23:28, Pavel Stehule wrote: select anum from t1 where anum = 4 union all select 100 limit 1; I'm not sure the ordering here is guaranteed by the standard though, is it? You could end up with the 4 being discarded. -- Richard Huxton Archonet Ltd -- Sent via pgsql-general mail

Re: [GENERAL] default value returned from sql stmt

2012-03-29 Thread Ken Tanzer
It depends on what exactly it is you're trying to do, and where your default is supposed to be used. Are you wanting a single number returned? in that case something like this SELECT COALESCE((SELECT anum FROM t1 WHERE anum=4 [ LIMIT 1 ]),100) that would get you back a 4 or 100 in this case. I

Re: [GENERAL] default value returned from sql stmt

2012-03-29 Thread David Salisbury
On 3/29/12 4:26 PM, Chris Angelico wrote: On Fri, Mar 30, 2012 at 9:16 AM, David Salisbury wrote: development=# select coalesce(anum,100) from t1 where anum = 4; What you have there is rather different from COALESCE, as you're looking for a case where the row completely doesn't exist. But

Re: [GENERAL] default value returned from sql stmt

2012-03-29 Thread Pavel Stehule
Hello 2012/3/30 David Salisbury : > > In trying to get an sql stmt to return a default value, I read in the docs.. > > "The COALESCE function returns the first of its arguments that is not null. > Null is returned only if all arguments are null. It is often used to > substitute a default value for

Re: [GENERAL] default value returned from sql stmt

2012-03-29 Thread Chris Angelico
On Fri, Mar 30, 2012 at 9:16 AM, David Salisbury wrote: > development=# select  coalesce(anum,100) from t1 where anum = 4; What you have there is rather different from COALESCE, as you're looking for a case where the row completely doesn't exist. But you can fudge it with an outer join. Untested

[GENERAL] default value returned from sql stmt

2012-03-29 Thread David Salisbury
In trying to get an sql stmt to return a default value, I read in the docs.. "The COALESCE function returns the first of its arguments that is not null. Null is returned only if all arguments are null. It is often used to substitute a default value for null values when data is retrieved for dis