Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть What's the Time?

  • PG Casts by Hashrocket
  • 2016-09-20
  • 521
What's the Time?
postgrespostgresqldatabasetimetransactionssqlhashrocketpgcasts
  • ok logo

Скачать What's the Time? бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно What's the Time? или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку What's the Time? бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео What's the Time?

The different ways of getting the current time in Postgres and how they differ. This episode is brought to you by Hashrocket, expert consultants in PostgreSQL - learn more at https://hashrocket.com and www.pgcasts.com

we have had some audio issues with this recording, so you may want to turn the volume up a bit.

Transcript:

When it comes to _time_, Postgres can do quite a bit. Even if you just want
to know what time it is _right now_, there are a few different functions to
consider.

The one we are probably the most familiar with is `now()`:

```sql
select now();
```

This gives us the current time.

The `now()` function works the same as the `transaction_timestamp()`
function:

```sql
select transaction_timestamp();
```

We will continue to use `transaction_timestamp()` throughout this episode,
but remember that it is interchangeable with `now()`.

The other two timestamp functions we are going to be looking at are
`statement_timestamp()` and `clock_timestamp()`:

```sql
select statement_timestamp();
select clock_timestamp();
```

They all seem to be doing the same thing, so, what's the difference?

Their names might give us an idea of what each really does. Let's start a
transaction and take a close look:

```sql
begin;

select transaction_timestamp();
```

We can wait a few seconds and then try that statement again:

```sql
select transaction_timestamp();
```

Interesting, they both produce the exact same timestamp. That is because
this function returns the timestamp of when the current transaction began.

Now, let's try out the `statement_timestamp()` function:

```sql
select statement_timestamp();
```

Some time has passed since we started the transaction and that is reflected
here. The `statement_timestamp()` function provides the timestamp that
Postgres began executing the statement.

So, even if we have an expensive query, that references
`statement_timestamp()` multiple times, we will get the same timestamp each
time:

```sql
select statement_timestamp(), pg_sleep(2)::text
union all
select statement_timestamp(), '';
```

We use the `pg_sleep` function to simulate an expensive query. Though there
was a couple of seconds between the two different calls to
`statement_timestamp()`, they both produce the exact same timestamp.

And this is where `clock_timestamp()` comes in to the picture. Let's try the
same query as above, but with `clock_timestamp()` instead:

```sql
select clock_timestamp(), pg_sleep(2)::text
union all
select clock_timestamp(), '';
```

We can see the difference in the timestamps for this example because the
`clock_timestamp()` function gets the actual current time.

You now know the differences between the different timestamp functions.

If we are updating or creating a number of different records within a
transaction and we want all of their timestamps to be coordinated, we should
reach for `transaction_timestamp()` or we can use `now()` as a shorthand.

When more specific timestamps are called for, you may want to reach for
`statement_timestamp()` or `clock_timestamp()`.

That's it for this episode. Until next time, may your data be consistent and
your queries performant.

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]