Re: [SQL] Conditional SQL query

2000-11-05 Thread Indraneel Majumdar
OK, I solved my own problems (Congrats ;-) Sorry for bothering the list. This is what I'm doing: INSERT INTO table SELECT x,x,x where (select count(*) from table where col1='value')=0; any suggestions? thanks, Indraneel On Mon, 6 Nov 2000, Indraneel Majumdar wrote: > Now I have one more probl

Re: [SQL] Conditional SQL query

2000-11-05 Thread Cristóvão B. B. Dalla Costa
> > Now I have one more problem. How do I insert only once if value does not > exist? eg: > You should create a unique index on the appropriate fields. For example: CREATE UNIQUE INDEX indexname ON table (field1, field2) Then the insert will fail if this particular combination of the values of

Re: [SQL] Conditional SQL query

2000-11-05 Thread Indraneel Majumdar
I finally got it to work. you can't use the parentheses. eg: insert into table select x,x,x where col1 = 'value'; and not insert into table select (x,x,x) where col1 = 'value'; the latter gives a ERROR: parser: parse error at or near "where" I am using PostgreSQL-7.0.2 Now I have one more prob

Re: [SQL] Conditional SQL query

2000-11-05 Thread Cristóvão B. B. Dalla Costa
> > insert into table select ... where col1 = 'value' > > > > this is working but I am inserting values directly and not by select. eg: > > insert into table values(x,x,x) > and not > insert into table select * from table2 > insert into table select (x, x, x) where col1 = 'value'

Re: [SQL] Conditional SQL query

2000-11-05 Thread Indraneel Majumdar
On Sun, 5 Nov 2000, Marten Feldtmann wrote: > Indraneel Majumdar schrieb: > > > > Hi, > > > > how can I insert a record after checking whether one of the fields has a > > certain value or not? eg: > > > > if table(col1)='value' insert into table values (x,x,x) > > > > I am using perl interfac

[SQL] Question about ordering views

2000-11-05 Thread hubert depesz lubaczewski
Hi, I'm wondering if it is possible to make view (or procedure or triger or rule or something) to force SELECTs to this view (rule, procedure or something) to force always using predefined ORDER BY statement without removing possibility to use WHERE statement to this SELECT. regards, depesz -

[SQL] Time penalty on VIEWS on VIEWS

2000-11-05 Thread hubert depesz lubaczewski
Hi, My situation: VIEW A is grouping information from 2 tables (B,C). I have to make another VIEW with additional WHERE statement compared in VIEW A. I can make this as a VIEW groupping tables B and C, or makeing VIEW of VIEW A. I know that second sollution is more flexible but there should be so