Re: Syntax

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: arun chirappurath <arunsnmimt(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Syntax
Date: 2023-12-07 11:14:44
Message-ID: CANzqJaDAPO--6wpZPrbVAkKgtbA7Y9WGSg5wLcdy5YK0OFr+LQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 7, 2023 at 3:01 AM arun chirappurath <arunsnmimt(at)gmail(dot)com>
wrote:

> Hi All,
>
> What is the difference or use case for below syntaxes?
>
> do $$
> declare d int;
> begin
> RAISE INFO 'Script started at %', CURRENT_TIMESTAMP;
> update employees set first_name = 'g' where employee_id = 1; get
> diagnostics d = row_count; raise info 'selected: % rows', d;
> RAISE INFO 'Script finished at %', CURRENT_TIMESTAMP; end;$$;
>
> Or
>
> Just
>
> Begin;
>
> Update statements
>
> Commit;
>

One shows when the statement started, and when *you think* it ended, while
the other doesn't.

https://www.postgresql.org/docs/15/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT

"Since these functions return the start time of the current transaction,
their values do not change during the transaction."

What you really want is clock_timestamp().

In response to

  • Syntax at 2023-12-07 08:00:39 from arun chirappurath

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2023-12-07 12:15:28 Re: Emitting JSON to file using COPY TO
Previous Message Arne Henrik Segtnan 2023-12-07 08:09:07 Re: PostgreSQL 12 error unrecognized configuration parameter zbx_tmp.wal_json_res