Home > Archive > PostgreSQL SQL > November 2006 > max (timestamp,timestamp)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author max (timestamp,timestamp)
T E Schmitz

2006-11-13, 7:21 pm

I tried the following query but the query fails as
"function max (timestamp w. timezone,timestamp w. timezone) does not exist"

SELECT id,

MAX(last_updated,
(SELECT MAX (last_updated) FROM product_category_mem
ber WHERE
product_category_mem
ber.id = product_category.id))

FROM product_category


product_category.last_updated and product_category_mem
ber.last_updated
are timestamps with timezone.


Is there any other way I can produce this result

--


Regards,

Tarlika Elisabeth Schmitz


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

A. Kretschmer

2006-11-13, 7:21 pm

am Mon, dem 13.11.2006, um 13:46:00 +0000 mailte T E Schmitz folgendes:
> I tried the following query but the query fails as
> "function max (timestamp w. timezone,timestamp w. timezone) does not exist"
>
> SELECT id,
>
> MAX(last_updated,
> (SELECT MAX (last_updated) FROM product_category_mem
ber WHERE
> product_category_mem
ber.id = product_category.id))
>
> FROM product_category
>
>
> product_category.last_updated and product_category_mem
ber.last_updated
> are timestamps with timezone.


Really, there are no such function. Perhaps this can help you:

SELECT id, MAX(product_category
.last_updated),
MAX(product_category
_member.last_updated) from product_category,
product_category_mem
ber WHERE product_category_mem
ber.id =
product_category.id;

**untested**



Your fault is that there are no max(timestamp,timest
amp) - funktion and
i think, you should read more about JOINs.


Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

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

imad

2006-11-13, 7:21 pm

max (timestamptz, timestamptz) does not exist already. You need to
create a simple function in PLpgSQL something like

if a > b
return a;
else
return b;

Even an sql function will do the job here using case statement.

--Imad
www.EntepriseDB.com



On 11/13/06, A. Kretschmer <andreas. kretschmer@schollgla
s.com> wrote:
> am Mon, dem 13.11.2006, um 13:46:00 +0000 mailte T E Schmitz folgendes:
>
> Really, there are no such function. Perhaps this can help you:
>
> SELECT id, MAX(product_category
.last_updated),
> MAX(product_category
_member.last_updated) from product_category,
> product_category_mem
ber WHERE product_category_mem
ber.id =
> product_category.id;
>
> **untested**
>
>
>
> Your fault is that there are no max(timestamp,timest
amp) - funktion and
> i think, you should read more about JOINs.
>
>
> Andreas
> --
> Andreas Kretschmer
> Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
> GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Michael Fuhr

2006-11-13, 7:21 pm

On Mon, Nov 13, 2006 at 07:29:09PM +0500, imad wrote:
> max (timestamptz, timestamptz) does not exist already. You need to
> create a simple function in PLpgSQL something like
>
> if a > b
> return a;
> else
> return b;


Since PostgreSQL 8.1 you can use GREATEST:

test=> SELECT greatest(1, 2);
greatest
----------
2
(1 row)

test=> SELECT greatest(2, 1);
greatest
----------
2
(1 row)

test=> SELECT greatest(6, 3, 1, 10, 9, 5, 2, 7, 8, 4);
greatest
----------
10
(1 row)

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

T E Schmitz

2006-11-14, 7:19 pm

Michael Fuhr wrote:
> On Mon, Nov 13, 2006 at 07:29:09PM +0500, imad wrote:
>
>
>
> Since PostgreSQL 8.1 you can use GREATEST:
>
> test=> SELECT greatest(1, 2);


That'll be a handy feature! Unfortunately, my server is still on 7.4.


Thanks to everyone for the quick responses.
--


Regards,

Tarlika

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com