Re: [SQL] special integrity constraints

2004-03-22 Thread Achilleus Mantzios
O kyrios Erik Thiele egrapse stis Mar 22, 2004 : Could it be possible to convert *any* CHECK constraint problem into an equivalent DEFERRABLE FK constraint problem? That is for *every* CHECK CONSTRAINT cc create (and maintain) 2 additional 1 row tables (cc1(val),cc2(val)) in such a way that cc i

Re: [SQL] Sorting an aggregated column

2004-03-22 Thread David Witham
Hi Tom, Thanks for the advice. I was planning to upgrade from 7.3.2 to 7.4 soon but this adds a bit more impetus. Under 7.3.2 I rewrote the query as your example suggested: explain select survey, list ( case when answer_bool = 't' then 'y'::varchar when answer_bool = 'f' then 'n'::v

Re: [SQL] Sorting an aggregated column

2004-03-22 Thread Tom Lane
"David Witham" <[EMAIL PROTECTED]> writes: > This output is correct in this case but there is no guarantee that the > answers will come out in "question" order. I can't see how to > incorporate sorting by the "question" column using this approach. As of PG 7.4 you can reliably use a sorted sub-sel

[SQL] Sorting an aggregated column

2004-03-22 Thread David Witham
Hi all, I ran these commands: create temp table dw_survey(survey int,question int,answer_bool boolean,answer_int int,answer_char varchar); insert into dw_survey values(1,1,'t',null,null); insert into dw_survey values(1,2,'f',null,null); insert into dw_survey values(1,3,'t',null,null); insert int

[SQL] function definition documentation

2004-03-22 Thread Gregory S. Williamson
I am having an impossible time porting some simple Stored Procedures from Informix to postgres. The documentation is almost self defeating. Are there any better descriptions of how to define functions that return several tuples to a wide variety of calling programs (e.g. I can't count on my user

Re: [SQL] special integrity constraints

2004-03-22 Thread Bruno Wolff III
On Mon, Mar 22, 2004 at 17:21:21 +0100, Erik Thiele <[EMAIL PROTECTED]> wrote: > > there is no such thing as a deferred check constraint: > > DEFERRABLE > NOT DEFERRABLE > > This controls whether the constraint can be deferred. A constraint that > is not deferrable will be checked immediately

Re: [SQL] special integrity constraints

2004-03-22 Thread Erik Thiele
On Mon, 22 Mar 2004 09:12:11 -0600 Bruno Wolff III <[EMAIL PROTECTED]> wrote: > On Mon, Mar 22, 2004 at 14:10:42 +0100, > Erik Thiele <[EMAIL PROTECTED]> wrote: > > > > it means (((count_rows(a)+count_rows(b)) modulo 2) == 0) > > OK, that means my FK suggestion won't help. The other suggestion

Re: [SQL] special integrity constraints

2004-03-22 Thread Stephan Szabo
On Mon, 22 Mar 2004, Erik Thiele wrote: > On Mon, 22 Mar 2004 06:21:28 -0800 (PST) > Stephan Szabo <[EMAIL PROTECTED]> wrote: > > > > > On Mon, 22 Mar 2004, Erik Thiele wrote: > > > > However, foreign keys are implemented using "constraint triggers". They're > > really not documented much (because

Re: [SQL] special integrity constraints

2004-03-22 Thread Erik Thiele
On Mon, 22 Mar 2004 06:21:28 -0800 (PST) Stephan Szabo <[EMAIL PROTECTED]> wrote: > > On Mon, 22 Mar 2004, Erik Thiele wrote: > > > On Mon, 22 Mar 2004 12:13:29 +0200 (EET) > > Achilleus Mantzios <[EMAIL PROTECTED]> wrote: > > > > > O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > > > > > > Di

Re: [SQL] inverse of "day of year"

2004-03-22 Thread Dana Hudes
If you have the option to handle the date manipulation in Perl use the DateTime modules. Also see Date::Calc. A considerable amount of effort has been expended dealing with all the nitty-gritty of time manipulation. Use those modules , get your new date or time interval and feed that to the dbms wi

Re: [SQL] inverse of "day of year"

2004-03-22 Thread Bruno Wolff III
On Mon, Mar 22, 2004 at 10:14:40 -0300, Martin Marques <[EMAIL PROTECTED]> wrote: > > Any thoughts on how this could affect date manipulation? This is consistant with what I explained about the behavior when adding a month results in a day in a month past the end of the new month. What do you e

Re: [SQL] special integrity constraints

2004-03-22 Thread Bruno Wolff III
On Mon, Mar 22, 2004 at 14:10:42 +0100, Erik Thiele <[EMAIL PROTECTED]> wrote: > > it means (((count_rows(a)+count_rows(b)) modulo 2) == 0) OK, that means my FK suggestion won't help. The other suggestion about putting triggers on "a" and "b" to update a count in another table that has a deferr

Re: [SQL] special integrity constraints

2004-03-22 Thread Stephan Szabo
On Mon, 22 Mar 2004, Erik Thiele wrote: > On Mon, 22 Mar 2004 12:13:29 +0200 (EET) > Achilleus Mantzios <[EMAIL PROTECTED]> wrote: > > > O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > > > > Did you check out the DEFERRABLE option on the constraint? > > > > DEFERRABLE > NOT DEFERRABLE > > This

Re: [SQL] inverse of "day of year"

2004-03-22 Thread Martin Marques
El Lun 22 Mar 2004 09:50, escribió: > > Intervals are stored as two components. One is absolute time difference, > and the other is in months. '1 year' is equivalent to '12 months'. > The documentation on how they work in corner cases (when added or > subtracted from timestamp(tz)) is sparse. It is

Re: [SQL] special integrity constraints

2004-03-22 Thread Erik Thiele
On Mon, 22 Mar 2004 05:26:04 -0600 Bruno Wolff III <[EMAIL PROTECTED]> wrote: > On Mon, Mar 22, 2004 at 10:20:31 +0100, > Erik Thiele <[EMAIL PROTECTED]> wrote: > > hi, > > > > i have two tables > > > > create table a (x integer); > > create table b (y real); > > > > i have the special constr

Re: [SQL] inverse of "day of year"

2004-03-22 Thread Bruno Wolff III
On Mon, Mar 22, 2004 at 08:32:32 -0300, Martin Marques <[EMAIL PROTECTED]> wrote: > > Is there information on how other intervals are taken? I mean, how is '1 year' > afected with the leap years? Intervals are stored as two components. One is absolute time difference, and the other is in month

Re: [SQL] special integrity constraints

2004-03-22 Thread Achilleus Mantzios
O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > On Mon, 22 Mar 2004 12:13:29 +0200 (EET) > Achilleus Mantzios <[EMAIL PROTECTED]> wrote: > > > O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > > > > Did you check out the DEFERRABLE option on the constraint? > > > > DEFERRABLE > NOT DEFERRA

Re: [SQL] special integrity constraints

2004-03-22 Thread Bruno Wolff III
On Mon, Mar 22, 2004 at 10:20:31 +0100, Erik Thiele <[EMAIL PROTECTED]> wrote: > hi, > > i have two tables > > create table a (x integer); > create table b (y real); > > i have the special constraint that the sum of the number of rows in > table a plus the number of rows in table b must be eve

Re: [SQL] special integrity constraints

2004-03-22 Thread Erik Thiele
On Mon, 22 Mar 2004 12:13:29 +0200 (EET) Achilleus Mantzios <[EMAIL PROTECTED]> wrote: > O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > > Did you check out the DEFERRABLE option on the constraint? > DEFERRABLE NOT DEFERRABLE This controls whether the constraint can be deferred. A constrain

Re: [SQL] special integrity constraints

2004-03-22 Thread Achilleus Mantzios
O kyrios Erik Thiele egrapse stis Mar 22, 2004 : Did you check out the DEFERRABLE option on the constraint? > hi, > > i have two tables > > create table a (x integer); > create table b (y real); > > i have the special constraint that the sum of the number of rows in > table a plus the number o

[SQL] special integrity constraints

2004-03-22 Thread Erik Thiele
hi, i have two tables create table a (x integer); create table b (y real); i have the special constraint that the sum of the number of rows in table a plus the number of rows in table b must be even. so there is a posibility of adding one element to a and one element to b, and again the constra