Re: [SQL] need magic to shuffle some numbers

2011-08-23 Thread Samuel Gendler
I don't have time to experiment with actual queries, but you can use the rank() window function to rank rows with prio sorted ascending, and do the same thing to rank rows with prio sorted descending, and update rows with the value from the second where the rank matches the rank from the first. I'

[SQL] need magic to shuffle some numbers

2011-08-23 Thread Andreas
Hi, there is a table that has among others a integer primary key "id" and another integer column "prio" as well as an integer "group_id". I'd like to invert the values of the prio-column for one of the groups. The prio numbers start with 3 and there are 1159 different prios in this group. At

Re: [SQL] WITH RECURSIVE question

2011-08-23 Thread Julien Cigar
mmh I made a little mistake: it was {A,B} of course, not {A,B,C} On 08/23/2011 12:03, Julien Cigar wrote: given D I want {A,B,C} -- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. <> -- Sent via pgsql-sql mailing list (pgsql-sql@pos

Re: [SQL] exclusion constraint for ranges of IP

2011-08-23 Thread Herouth Maoz
On 23/08/2011, at 13:31, Jasen Betts wrote: > On 2011-08-23, Herouth Maoz wrote: > >>EXCLUDE USING GIST ( customer_id WITH =, is_default WITH AND ) > > >> Basically, each customer can have several rows in this table, but only = >> one per customer is allowed to have is_default =3D true.

Re: [SQL] exclusion constraint for ranges of IP

2011-08-23 Thread Jasen Betts
On 2011-08-23, Herouth Maoz wrote: > EXCLUDE USING GIST ( customer_id WITH =, is_default WITH AND ) > Basically, each customer can have several rows in this table, but only = > one per customer is allowed to have is_default =3D true. Is this exclude = > constraint correct? I don't really

Re: [SQL] Confused about writing this stored procedure/method.

2011-08-23 Thread Jasen Betts
On 2011-08-22, JavaNoobie wrote: > Hi All, > I'm trying to write a stored procedure /function to re-order a set of > calendar months.I have a set of calendar months stored from January to > December in my tables. And as of now when I do order by on this column , > the data is ordered alphabetical

Re: [SQL] exclusion constraint for ranges of IP

2011-08-23 Thread Samuel Gendler
On Tue, Aug 23, 2011 at 1:27 AM, Herouth Maoz wrote: > My thanks to everyone who replied. > > I have decided not to implement that constraint at this time. Using a > compound type will make the system more complicated and less readable, plus > requires installing the package which is beyond vanil

[SQL] WITH RECURSIVE question

2011-08-23 Thread Julien Cigar
Hello, I have a classic parent -> child relation (id, container_id) and I would like to find the full hierarchy for a child, something like A / \ B C | D given D I want {A,B,C} WITH RECURSIVE hierarchy(level, container_id, titles, containers) AS (SELECT 1 AS level, container_id, ARRAY[

Re: [SQL] exclusion constraint for ranges of IP

2011-08-23 Thread Herouth Maoz
My thanks to everyone who replied. I have decided not to implement that constraint at this time. Using a compound type will make the system more complicated and less readable, plus requires installing the package which is beyond vanilla PostgreSQL. Now I have another exclusion constraint I'm th