0

I have a date string 2020-10-14, 14:13:23, I want to convert this to timestamp with timezone format in python so that I can delete the rows with this particular timestamp in my postgresql table

enter image description here

Please suggest how to proceed?

1 Answer 1

1

Do you want to cast?

select '2020-10-14, 14:13:23'::timestamp with time zone
| timestamptz            |
| :--------------------- |
| 2020-10-14 14:13:23+01 |

If you want to filter on timestamps that belong to the same second as this literal value:

select *
from mytable
where execution_date >= '2020-10-14, 14:13:23'::timestamp with time zone
  and execution_date <  '2020-10-14, 14:13:23'::timestamp with time zone + interval '1 second'
Sign up to request clarification or add additional context in comments.

4 Comments

I did select '2020-10-14, 14:13:23'::timestamp with time zone from table_name and I got 16 rows but in actual the table contains only two rows with this timestamp. Am i doing something wrong?
@Mahesh: please provide sample data and desired results. Better yet, are you able to set up a dbfiddle.uk that demonstrates the issue?
hey, I am unable to provide sample data in the fiddle never used it.. but what I am trying to do is fetch all the rows with this timestamp. so i wrote the query select * from table_name where execution_date in (select '2020-10-14, 14:13:23'::timestamp with time zone) but it is returning 0 rows. execution_date is the column name as shown in the above image
@Mahesh: your data has fractional seconds, not the value that you are passing. So there is no exact match.

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.