![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a question regarding rules, in particular when the where clause is evaluated. |
#3
| |||
| |||
|
|
Klaus Dahlke <klaus.dahlke (AT) gmx (DOT) de> wrote: I have a question regarding rules, in particular when the where clause is evaluated. Could you post the CREATE TABLE statements for the tables you use? Then I'll try to reproduce the problem and see if I can find anything. Yours, Laurenz Albe |
#4
| |||
| |||
|
|
I have a question regarding rules, in particular when the where clause is evaluated. Could you post the CREATE TABLE statements for the tables you use? Then I'll try to reproduce the problem and see if I can find anything. thanks for your help, here are the statements: [...] CREATE OR REPLACE RULE pppd_time AS ON INSERT TO logtest where program='pppd' DO INSERT INTO pppd_time (date, uptime) VALUES (now(), to_number(split_part((new.message)::text, ' '::text, 3), '999D9'::text)); [...] insert into logtest (date, program, message) values (now(), 'yppd', 'Hello World'); ERROR: invalid input syntax for type numeric: " " [...] As you see, the first insert statement should go only into table logtest (where clause not fulfilled), but it fails at the type conversion to numeric called in the rule and then the entire statement aborts. |
|
In the online documentation it is written: For ON INSERT rules, the original query (if not suppressed by INSTEAD) is done before any actions added by rules. so even for the first insert statement I would expect to have an entry in the logtest. |
#5
| |||
| |||
|
|
... My suggestion is that you avoid the problem, be it a bug or not, by using an expression that does not produce an error, no matter what the inserted message is. You can depend on it that the INSERT into pppd_time will not take place except when the condition evaluates to TRUE. ..... Yours, Laurenz Albe |
#6
| |||
| |||
|
|
My suggestion is that you avoid the problem, be it a bug or not, by using an expression that does not produce an error, no matter what the inserted message is. You can depend on it that the INSERT into pppd_time will not take place except when the condition evaluates to TRUE. many thanks for looking into it! So, I have to make up my mind to either upgrade or to play abit around with altering the rule. My current work around is to have two columns in pppd_time for the time. One is of type varchar, the other one is numeric. The first rule 'copies' the time in form of a string from logtest into the pppd_time. pppd_time has also a rule simply updating that row by converting the time string into a number. It works for the time being but just having one column is much more elegant. |
#7
| |||
| |||
|
|
Klaus Dahlke <klaus.dahlke (AT) gmx (DOT) de> wrote: Why don't you use to_number('0' || split_part((new.message)::text, ' '::text, 3), '999D9') or something similar? It seems to work for me (do some testing), and that way you can retain your original setup. Yours, Laurenz Albe Hi Laurenz, |
#8
| |||
| |||
|
|
Why don't you use to_number('0' || split_part((new.message)::text, ' '::text, 3), '999D9') or something similar? It seems to work for me (do some testing), and that way you can retain your original setup. I gave it a try, unfortunately no success. Still the error 'ERROR: invalid input syntax for type numeric: " "' occurs. |
#9
| |||
| |||
|
|
Klaus Dahlke <klaus.dahlke (AT) gmx (DOT) de> wrote: Why don't you use to_number('0' || split_part((new.message)::text, ' '::text, 3), '999D9') or something similar? It seems to work for me (do some testing), and that way you can retain your original setup. I gave it a try, unfortunately no success. Still the error 'ERROR: invalid input syntax for type numeric: " "' occurs. Really? You get the error when you select to_number('0' || split_part(('Hello World')::text, ' '::text, 3), '999D9'); That would be strange. Do I miss something here? Yours, Laurenz Albe Hi Laurenz, |
|
| split_part((new.message)::text, ' '::text, 3), '999D9')' in the rule works fine! |
![]() |
| Thread Tools | |
| Display Modes | |
| |