0

How to convert the oracle timestamp to postgres timestamp,we have a values in oracle data base as below,

15-JUN-2014 01.00.00.0000 PM

I have stored as varchar in postgres/Greenplum. How can I cast to timestamp in postgres,

Output required As below ,

15-06-2014 13.00.00.0000

As 24 hrs format.

4
  • 1
    Timestamps don't have "a format" - neither in Oracle nor in Postgres (or in any other DBMS). How are you transferring the data? How are you connecting the two databases? Commented Sep 29, 2014 at 17:49
  • from oracle we are generating csv files and loading into greenplum in that case i am not able to convert am/pm into 24 hrs format in postgress/greenplum. Commented Sep 29, 2014 at 18:00
  • The why don't you create the CSV file with the correct timestamp format right away? Commented Sep 29, 2014 at 18:51
  • total size of file is more than 100 gb , i dont want to re-create again by sitting more than 2 -3 days :) Commented Sep 30, 2014 at 4:40

2 Answers 2

3

Timestamps are timestamps. They represent a date (incl. time) using an internal representation. But you can convert timestamps to/from strings using various formats. For example, if you need to display them or in order to export your data to an other software requiring some specific representation.

In the following code for Oracle, I convert from a string to a timestamp (TO_TIMESTAMP) using a format corresponding to your first example. Then I "convert back" that timestamp to a string (TO_CHAR) using an other format corresponding to your second representation:

-- Convert a string to a timestamp
WITH sample_data AS 
  (SELECT TO_TIMESTAMP('15-JUN-2014 01.00.00.0000 PM', 
                       'DD-MON-YYYY HH12.MI.SS.FF4 PM') ts FROM DUAL)

-- Convert a timestamp to a string using a format corresponding
-- to "15-06-2014 13.00.00.0000"
SELECT TO_CHAR(ts, 'DD-MM-YYYY HH24.MI.SS.FF4') as result FROM sample_data;

Producing (the string):

result
15-06-2014 13.00.00.0000

Please note that you can convert from string to date in PostgreSQL too using (almost?) exactly the same date functions and formats.

Sign up to request clarification or add additional context in comments.

2 Comments

Still not working it's not converting to 24hrs format select TO_TIMESTAMP(event_timestamp,'DD-MON-YY HH24.MI.SS.FF4')::TIMESTAMP WITHOUT TIME ZONE from jiodba.ext_WFA_ACCOUNTING_MSG limit 100 --"2014-07-01 12:01:18"
this solution strips the 'PM' from the end of the timestamp. How can you maintain the Oracle formatting in PostgreSQL?
0
SELECT To_timestamp(event_timestamp,'DD-MON-YY HH12.MI.SS.SSSS AM.PM')::timestamp without time zone
FROM jiodba.ext_wfa_accounting_msg limit 1000;

Please find the answer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.