| From: | "Chad Thompson" <chad(at)weblinkservices(dot)com> |
|---|---|
| To: | "pgsql-novice" <pgsql-novice(at)postgresql(dot)org> |
| Subject: | views and rules |
| Date: | 2002-07-09 18:01:56 |
| Message-ID: | 00e501c22772$b902f910$32021aac@chad |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
I have a 3rd party software that submits information to my database in a table called call_results. The problem is that it submits the date to one column(calldate) and the time to another (start_time). The reports that i need to run, go significantly faster if date and time are in one column.
--this is what he submits to me
insert into call_results (phonenum, callnum, calldate, start_time)
values ('5552552555', 4524, '6/24/2002', '17:00:32')
To get around this i have tried to create the following.
CREATE TABLE "call_results_fixed" (
"id" int8 DEFAULT nextval('"call_results_fixed_id_seq"'::text) NOT NULL,
"callnum" int4,
"calldate" timestamp,
"phonenum" varchar(15),
"start_time" timestamp
CONSTRAINT "call_results_fixed_pkey" PRIMARY KEY ("id")
) WITH OIDS;
CREATE VIEW "call_results" AS SELECT * from call_results_fixed
CREATE RULE ins_call_results AS ON INSERT TO call_results
DO INSTEAD INSERT INTO call_results_fixed (calldate, callnum, phonenum, start_time)
VALUES ("timestamp"(new.calldate), new.callnum, new.phonenum, "timestamp"(((to_char(timestamptz(new.calldate), 'MM-DD-YYYY'::text) || ' '::text) || text(new.start_time))));
This would effectivly concatinate the date and time and insert them into the call_results_fixed table. (or so it would seem)
I get an error when i set this up, however that says
"Bad timestamp external representation '17:00:32'
In other words, it seems that it is testing the column type without taking into account the rule.
I have tried to work around this by creating a table called call_results with start_time being just a time field and creating similar rule on the table call_results. With this senario I have problems with the select do instead rule.
**whew!** Does that make sense?
Thanks in advance for reading my epic novel, and for any help you can give.
Chad
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pam Wampler | 2002-07-09 18:53:40 | oid2name |
| Previous Message | John Nix | 2002-07-09 17:55:36 | Re: Date Duration Numbers |