Re: [SQL] Find min and max values across two columns?

2006-05-16 Thread Emi Lu

Thank you Tom.


Emi Lu <[EMAIL PROTECTED]> writes:
 


ERROR:  function greatest(integer, integer) does not exist
HINT:  No function matches the given name and argument types. You may 
need to add explicit type casts.
   



We added greatest/least in 8.1, but before that you can just use a
CASE expression instead, along the lines of
case when x>y then x else y end

regards, tom lane

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




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


[SQL] Table constraints and INSERT

2006-05-16 Thread Risto Tamme
Hello

I use PostgreSQL in my program and I found a strange behavior, at least
for me.

I have a simple table with constraint

CREATE TABLE "PART"
(
  "P_PARTKEY" int4 NOT NULL,
  "P_RETAILPRICE" numeric,
  CONSTRAINT "PART_PRIMARY" PRIMARY KEY ("P_PARTKEY"),
  CONSTRAINT "PART_check" CHECK ("P_RETAILPRICE" = (9 + "P_PARTKEY"
/ 10 + "P_PARTKEY" / 100)
);

And I try to insert a row:
INSERT INTO "PART" ("P_PARTKEY","P_RETAILPRICE") VALUES(999,90109.89);

but it fails: ERROR:  new row for relation "PART" violates check
constraint "PART_check"

When you check using your head or pocket calculator then this INSERT
seems to be correct. Is it some floating point mystery?
Is there some trick?
I'm using version 8.0.1 for Windows.

With thanks, Risto

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org