Re: [SQL] date_trunc should be called date_round?

2009-06-29 Thread Mario Splivalo
Tom Lane wrote: > Mario Splivalo writes: >> But, date_trunc behaves like round function: round(1.9) = 2. > > Hmm ... only for float timestamps, and only for the millisec/microsec > cases. > > case DTK_MILLISEC: > #ifdef HAVE_INT64_TIMESTAMP > fsec = (fsec / 1000) * 10

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread Craig Ringer
On Tue, 2009-06-30 at 10:22 +1000, Robert Edwards wrote: > Would this be in addition to a unique constraint on (a, b, c) (for the > cases where c is not null)? That depends on your app's needs. Do you need to enforce uniqueness of (a,b,c) ? Or of (a,b) where c is _not_ null? If so, then yes, that

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread Robert Edwards
Thanks for all these great ideas! Craig Ringer wrote: On Mon, 2009-06-29 at 15:42 +1000, Robert Edwards wrote: Can anyone suggest a way that I can impose uniqueness on a and b when c is NULL? One way is to add an additional partial index on (a,b): CREATE INDEX bobtest_ab_unique ON bobtest(

Re: [SQL] date_trunc should be called date_round?

2009-06-29 Thread Tom Lane
Mario Splivalo writes: > But, date_trunc behaves like round function: round(1.9) = 2. Hmm ... only for float timestamps, and only for the millisec/microsec cases. case DTK_MILLISEC: #ifdef HAVE_INT64_TIMESTAMP fsec = (fsec / 1000) * 1000; #else fsec =

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread Tom Lane
Craig Ringer writes: > On Mon, 2009-06-29 at 15:42 +1000, Robert Edwards wrote: >> Can anyone suggest a way that I can impose uniqueness on a and b when >> c is NULL? > One way is to add an additional partial index on (a,b): > CREATE INDEX bobtest_ab_unique ON bobtest(a,b) WHERE (c IS NULL); Tha

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread Craig Ringer
On Mon, 2009-06-29 at 15:42 +1000, Robert Edwards wrote: > Can anyone suggest a way that I can impose uniqueness on a and b when > c is NULL? One way is to add an additional partial index on (a,b): CREATE INDEX bobtest_ab_unique ON bobtest(a,b) WHERE (c IS NULL); ... however, if you want to do

[SQL] date_trunc should be called date_round?

2009-06-29 Thread Mario Splivalo
It's stated in the docs that date_trunc is "conceptually similar to the trunc function for numbers.". So, trunc(1.1) = 1, trunc(1.9) = 1, and so on. But, date_trunc behaves like round function: round(1.9) = 2. Example: idel=# select date_trunc('milliseconds', '2009-01-01 12:15:00.000999+02'::ti

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread A. Kretschmer
In response to Leo Mannhart : > On Mon, 2009-06-29 at 17:08 +1000, Robert Edwards wrote: > > A. Kretschmer wrote: > > > In response to Robert Edwards : > > >> Can anyone suggest a way that I can impose uniqueness on a and b when > > >> c is NULL? > > > > > > Sure, use a functional index: > > > >

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread A. Kretschmer
In response to Robert Edwards : > A. Kretschmer wrote: > >In response to Robert Edwards : > >>Can anyone suggest a way that I can impose uniqueness on a and b when > >>c is NULL? > > > >Sure, use a functional index: > > > >test=# create table bobtest (a int, b int, c int); > >CREATE TABLE > >test=*

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread Leo Mannhart
On Mon, 2009-06-29 at 17:08 +1000, Robert Edwards wrote: > A. Kretschmer wrote: > > In response to Robert Edwards : > >> Can anyone suggest a way that I can impose uniqueness on a and b when > >> c is NULL? > > > > Sure, use a functional index: > > > > test=# create table bobtest (a int, b int, c

Re: [SQL] .psql_history": No such file

2009-06-29 Thread ivan marchesini
Thanks to all... in effect it is a very little problem if you consider that probably I will call psql from normal accounts... :-) thanks Il giorno dom, 28/06/2009 alle 01.04 +0930, Shane Ambler ha scritto: > Guillaume Lelarge wrote: > > Hi Ivan, > > > > Le vendredi 26 juin 2009 à 17:53:15, iva

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread Robert Edwards
A. Kretschmer wrote: In response to Robert Edwards : Can anyone suggest a way that I can impose uniqueness on a and b when c is NULL? Sure, use a functional index: test=# create table bobtest (a int, b int, c int); CREATE TABLE test=*# create unique index idx_bobtest on bobtest(a,b,coalesce(c