Обсуждение: Function in psql to Compare two numbers and return the bigger value

Поиск
Список
Период
Сортировка

Function in psql to Compare two numbers and return the bigger value

От
Emi Lu
Дата:
HEllo,

I am looking for a psql method to get the bigger value of two numbers.

For example,

methodName(12.6, 3.8)

Will return 12.6

Thanks!

Re: Function in psql to Compare two numbers and return the bigger value

От
"Adam Rich"
Дата:
You want GREATEST()

<http://www.postgresql.org/docs/8.2/interactive/functions-conditional.ht
ml#AEN13140>


-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Emi Lu
Sent: Tuesday, February 13, 2007 12:37 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Function in psql to Compare two numbers and return
the bigger value


HEllo,

I am looking for a psql method to get the bigger value of two numbers.

For example,

methodName(12.6, 3.8)

Will return 12.6

Thanks!

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Re: Function in psql to Compare two numbers and return the bigger value

От
Bricklen Anderson
Дата:
Emi Lu wrote:
> HEllo,
>
> I am looking for a psql method to get the bigger value of two numbers.
>
> For example,
>
> methodName(12.6, 3.8)
>
select greatest(12.6,3.8);

Re: Function in psql to Compare two numbers and return the bigger value

От
Emi Lu
Дата:
>> I am looking for a psql method to get the bigger value of two numbers.
>>
>> For example,
>>
>> methodName(12.6, 3.8)
>>
> select greatest(12.6,3.8);

It does not work for me,
select greatest(12.6,3.8);
ERROR:  function greatest(numeric, numeric) does not exist
HINT:   No function matches the given name and argument types. You may
need to add explicit type casts.

In 8.1 docs, it says that:
GREATEST(value [, ...])
LEAST(value [, ...])

* Note that GREATEST and LEAST are not in the SQL standard, but are a
common extension. *

Does it mean it is not allowed to use "select greatest(12.6,3.8)" ?

thanks


Re: Function in psql to Compare two numbers and return the bigger value

От
Emi Lu
Дата:
Emi Lu wrote:
>
>>> I am looking for a psql method to get the bigger value of two numbers.
>>>
>>> For example,
>>>
>>> methodName(12.6, 3.8)
>>>
>> select greatest(12.6,3.8);
>
> It does not work for me,
> select greatest(12.6,3.8);
> ERROR:  function greatest(numeric, numeric) does not exist
> HINT:   No function matches the given name and argument types. You may
> need to add explicit type casts.
>
> In 8.1 docs, it says that:
> GREATEST(value [, ...])
> LEAST(value [, ...])
>
> * Note that GREATEST and LEAST are not in the SQL standard, but are a
> common extension. *
>
> Does it mean it is not allowed to use "select greatest(12.6,3.8)" ?

I see the reason, my version is 8.0.8. The doc is for 8.1.

Thank you for all your help!

Re: Function in psql to Compare two numbers and return the bigger value

От
Steve Wampler
Дата:
Emi Lu wrote:
> Does it mean it is not allowed to use "select greatest(12.6,3.8)" ?

It may mean you're not running 8.1?  Here's what I get:
-----------------------------------------------------------
->psql
Welcome to psql 8.1.4, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

swampler=# select GREATEST(6.3, 2.8);
 greatest
----------
      6.3
(1 row)

swampler=# select greatest(6.3, 2.8);
 greatest
----------
      6.3
(1 row)

swampler=#
-----------------------------------------------------------

--
Steve Wampler -- swampler@noao.edu
The gods that smiled on your birth are now laughing out loud.