Skip to content

postgres useful commands

Rajesh Khadka edited this page Apr 15, 2020 · 4 revisions

functions

To get current time in postgres

Timezone: now()

UTC time : timezone('utc', now())

Join Multiple Tables

select * from **table_name** as user inner join **table_name** as profile on user.id = profile.doctor_id inner join **table_name** fee on profile.id = fee.doctor_profile_id where user.id='54800353-28f6-4e9d-bbc9-b8c3bca59594';

Adding or subtract time

update consultation.consultations set expires = (select CURRENT_DATE + INTERVAL '7 day') where created_at <= '2020-04-09' and frequency > 0; update consultation.consultations set expires = (select CURRENT_DATE - INTERVAL '7 day') where created_at <= '2020-04-09' and frequency > 0;

we can use day, month, year