Error in table change in PostgreSQL. How do I change the type of a colulna int to the timestamp type?

3

I am studying PostgreSQL DB for a recent book I purchased. When trying to change a tab based on the command I learned in the book, an error occurred, I used exactly the same command written in the book without change. I am trying to change a field type int to type timestamp but the following error occurs

- change in table with column change type int to type timestamp

alter table commissions alter column data_payment type timestamp using data_pagamento_timestamp;

obs: in the book is written date_payment_timestamp. Timestamp is a type in SQL to store date and time however with " timestamp" stands as part of the table name. I removed the "" and left timestamp separate from the column name because I thought this was a book error but it did not work because it still does not work. How do I fix this?

The error that occurs below:

LINE 1: ... ata_payment type timestamp using data_payment timestamp;                                                              ^ SQL state: 42601 Character: 87

    
asked by anonymous 17.11.2018 / 16:57

1 answer

0

timestamp is a date with one hour.

To transform numbers into timestamp, you have to indicate the numbers they represent (seconds, minutes, hours). And what does the 0.

For example, if they are seconds and today is the time 0:

create table table11(
  id serial primary key,
  seconds int
);

insert into table11 (seconds) values 
  (15), (60), (60*60);

alter table table11 alter seconds type timestamp
  using '2018-11-18'::date + (seconds||' seconds')::interval;

select * from table11;  

Note that the USING part is the one that indicates how the transformation should be done.

To see an example, visit: link

    
19.11.2018 / 04:07