Re: [SQL] problem using regexp_replace

2010-01-11 Thread Jasen Betts
On 2010-01-11, gher...@fmed.uba.ar wrote: > CREATE FUNCTION valores_sustitucion(valor_ingresado varchar[]) > returns varchar > as > $$ > select case > $1[1] when 'Action_1' then > (select descripcion from load_by_cod($1[2])) > >when 'Action_2' then (select descripcion from pay_by_view($

Re: [SQL] problem using regexp_replace

2010-01-11 Thread gherzig
> On 2010-01-11, gher...@fmed.uba.ar wrote: > >> CREATE FUNCTION valores_sustitucion(valor_ingresado varchar[]) >> returns varchar >> as >> $$ >> select case >> $1[1] when 'Action_1' then >> (select descripcion from load_by_cod($1[2])) >> >>when 'Action_2' then (select descripcion from p

[SQL] CHECK constraint removing brackets

2010-01-11 Thread Andy Shellam
Hi, I notice this had been raised as a bug (and subsequently over-ruled) so I'm asking how I can achieve the following business rule. I have an order table which has an invoice_id column that links to an invoice table (an order can only have 1 invoice, but one invoice can have multiple orders.

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Scott Marlowe
On Mon, Jan 11, 2010 at 12:49 PM, Andy Shellam wrote: > With the above in mind, I decided on the following check to enforce this: > > (state = 'Unconfirmed'::client.order_state AND invoice_id = NULL) OR (state > != 'Unconfirmed'::client.order_state AND invoice_id != NULL) Nothing can = null. an

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Tom Lane
Andy Shellam writes: > With the above in mind, I decided on the following check to enforce this: > (state = 'Unconfirmed'::client.order_state AND invoice_id = NULL) OR (state > != 'Unconfirmed'::client.order_state AND invoice_id != NULL) > However PostgreSQL (8.4.2) converts this to the followi

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Andy Shellam
Hi Tom and Scott, > > I think your real problem is that you're trying to use "= NULL" and > "!= NULL" where you should say IS NULL or IS NOT NULL. Argh such a school-boy error! This is the first bit of database programming I've done for about 2 months, and I hadn't switched my C++ brain off.

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Tom Lane
Andy Shellam writes: > I know about the <> and !=, for some reason != has always made better sense > to me to read, so I tend to write it that way. Yeah, a lot of people prefer != ... that's why we provide it as an alias for <>. There's no functional difference. regards