Thread: merging date and time
Hi, I'm experiencing some problems to create a view in which I put together a date and a time in the same field... I have a table which contain a date field (with a date inside) and a varchar field with time inside.. This is the content of those two field in one record: |22-03-1999|14:45:27 I just wanted to create a view in which those two field are merged in a datetime filed.. I tried using different approach but I'm always getting an error message orwhile creating the view or when selectin fromthe created view.. examples: create view glob_time as select datetime(euigw.day||euigw.time) as tempofrom euigw; gives me the following error message; ERROR: There is more than one possible operator '||' for types 'date' and 'varc har' You will have to retype this query using an explicit cast create view glob_time as select datetime(text(euigw.day)||euigw.time) as tempo from euigw; works file, but then if I do select * from glob_time; I get: ERROR: Bad datetime external representation 'Mon 22 Mar 00:00:00 1999 MET14:45: 27' does anyone have an idea about how to solve this? thanks, Marco
miannaco@csc.com wrote: > > Hi, > I'm experiencing some problems to create a view in which I put together a > date and a time in the same field... > > ERROR: Bad datetime external representation 'Mon 22 Mar 00:00:00 1999 > MET14:45:27' > > does anyone have an idea about how to solve this? Well, the error is exactly what it says - that's not a date time. AS you can see, the text version of the 'date' type includes a time of 00:00:00. This lead us to a clue - you need to add the time to the date before the conversion: test=> create table t1 (d date, t text); CREATE test=> insert into t1 values('22-03-1999','14:45:27'); INSERT 101293 1 test=> select datetime(d+timespan(t)) from t1; datetime ---------------------------- Mon Mar 22 14:45:27 1999 CST (1 row) test=> drop table t1; DROP test=> HTH, Ross P.S. no need to send your question twice - and it appeared three times! -- Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> NSBRI Research Scientist/Programmer Computer and Information Technology Institute Rice University, 6100 S. Main St., Houston, TX 77005
On Wed, Mar 31, 1999 at 10:01:20AM -0600, Ross J. Reedstrom wrote: > test=> create table t1 (d date, t text); > CREATE > test=> insert into t1 values('22-03-1999','14:45:27'); > INSERT 101293 1 > test=> select datetime(d+timespan(t)) from t1; > datetime > ---------------------------- > Mon Mar 22 14:45:27 1999 CST > (1 row) > > test=> drop table t1; > DROP > test=> Or more simply... select ('22-03-1999'::date + '14:45:27'::timespan) as myDateTime; mydatetime ---------------------------- Mon Mar 22 14:45:27 1999 GMT (1 row) -- If at first you don't succeed, skydiving is not for you...
Hi, I have two tables, A and B. A contains records which includes an ID or one of the records in table B. A would typically contain the fields: IDA IDB DATA1 DATA2 and B: IDB DATA3 DATA4 I have several records in both but a few of the records in A has a IDB field which does not point to a valid record in B (the record has been deleted). I know how to get all the records in A that have existing records in B. SELECT * FROM A, B WHERE A.BID = B.BID. Now my question ... How do I get the records in A that DO NOT have existing records in B ??? Perplexed look and deep frown ;-) Thanks in Advance Frans