Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qCRBE-0005Dd-4U for pgsql-admin@arkaria.postgresql.org; Thu, 22 Jun 2023 20:45:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qCRBC-0007db-Kl for pgsql-admin@arkaria.postgresql.org; Thu, 22 Jun 2023 20:45:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qCRBC-0007bl-9y for pgsql-admin@lists.postgresql.org; Thu, 22 Jun 2023 20:45:22 +0000 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qCRB8-003gO9-TM for pgsql-admin@lists.postgresql.org; Thu, 22 Jun 2023 20:45:21 +0000 Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-763e968b795so156060785a.0 for ; Thu, 22 Jun 2023 13:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687466717; x=1690058717; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=v3IomsBNjPhjF/AY/uB5bTlraz6WL/8MYw9mXPMm6iI=; b=WKqKwM5s4y0g8nFomJwCUiy2DxnZ+bL/ceHFJ38C/n+UtkrateJNQsbnbIgmQ7RVBQ E4BISFQ5/0+SI3yLMserdB+mCFT2OO1tc2JZmEAC6eAlrPYO9jtBWfBcYaYucUCKWl3x lXQhUrMREj8itSXtKriUHcRc/orRzA6UHgTIsLwsuB5LqMBJN76DuBag/w/FtYL5Lj8p 2G4629sm13y7HoZQ3UGEuwPHU7Zj6EgZLlgu2oMProM640VtK2vcu0RXtGlTvONHCXyd B8JRQK2J8bsPX33ie6Fwtdvqi0Qsh0wvNx8v4bRzmv+fnsG0xxI6Cr42gdpVB0vuykyu wPFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687466717; x=1690058717; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=v3IomsBNjPhjF/AY/uB5bTlraz6WL/8MYw9mXPMm6iI=; b=SL2ZxLhtA1QE8sLoCC+6hWYC6DDq6H36IkRfdRHy1LkWTovFYoYqO2NFbn0pK9rXNK txnR47N5oWpxAkNWPgWPXpMhXJpYY5WOJokle5iGCDoaf5Jwtf3+oVa0WKCraMKrb3vm CcpdIbUJ7lTqFiZJpKd6mUv/3xPSxqk1sB2BclArkI1RhB3x4x3Ra4R8jFUIUMHNfDdF t0L1GvcmWlz8usOMQO68vdZyRIAiIq4A7Fs2Pdt3h8o0OJjKdnTnU0/bl0qk5bM8USPC hfMWEgtS+5nl4BMFD+dOdXzJj4nftdfjyzFQLRN8I/Y/+Dbk1dZ4yy6aaXqdnB4Jga5e 1c8A== X-Gm-Message-State: AC+VfDyVk6AEIzvC6RbOFNVy3gYzzjYLi1hzBYEU64N3i0lz2t2uOm06 MHP5/PXbqSljxiZ0gP5hJrGqmy2U5R8= X-Google-Smtp-Source: ACHHUZ5kGHCqLkYTrjx5yoQSbXvqzaoD/B7mH3jzOI/Q9KSjX2LXtKgBFCKqDkE2qZJ1rhrtimo7fg== X-Received: by 2002:a05:620a:24c1:b0:75e:c23f:82ef with SMTP id m1-20020a05620a24c100b0075ec23f82efmr25896379qkn.67.1687466717457; Thu, 22 Jun 2023 13:45:17 -0700 (PDT) Received: from ?IPV6:2600:1700:bd2c:b810:1087:186d:a03b:79fd? ([2600:1700:bd2c:b810:1087:186d:a03b:79fd]) by smtp.googlemail.com with ESMTPSA id r2-20020a0de802000000b0056d2474dbafsm2063421ywe.51.2023.06.22.13.45.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Jun 2023 13:45:16 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------1MZEz3yoatH0WQkVWD0dQ6Yt" Message-ID: <328b8fb1-08e8-2c74-a2b8-878ad5e9f9a4@gmail.com> Date: Thu, 22 Jun 2023 15:45:15 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: GENERATE AS Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: <7c48174f8ce449af8f3e875bdeca7150@express-scripts.com> From: Ron In-Reply-To: <7c48174f8ce449af8f3e875bdeca7150@express-scripts.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------1MZEz3yoatH0WQkVWD0dQ6Yt Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 6/22/23 15:00, Wetmore, Matthew (CTR) wrote: > > Hi, I have this issue and now I’m just wasting time. Can you tell me what > I’m doing wrong? > > I’d like to subtract a column timestamp hour from current hour to give me > hours elapased. > > How do I do this easily? > > I think I’ve tried every combination of types and casting. > > Thanks in advance. > > --------------------------- > > 1. ALTER TABLE matt > >                add column matt_time timestamp with time zone default > current_timestamp; > Besides what Ilya and David mentioned, CURRENT_TIMESTAMP is based on when the transaction started.  You might have wanted clock_timestamp(). -- Born in Arizona, moved to Babylonia. --------------1MZEz3yoatH0WQkVWD0dQ6Yt Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 6/22/23 15:00, Wetmore, Matthew (CTR) wrote:

Hi, I have this issue and now I’m just wasting time. Can you tell me what I’m doing wrong?

 

I’d like to subtract a column timestamp hour from current hour to give me hours elapased.

 

How do I do this easily?

 

I think I’ve tried every combination of types and casting.

 

Thanks in advance.

---------------------------

 

1. ALTER TABLE matt

               add column matt_time timestamp with time zone default current_timestamp;


Besides what Ilya and David mentioned, CURRENT_TIMESTAMP is based on when the transaction started.  You might have wanted clock_timestamp().

--
Born in Arizona, moved to Babylonia.
--------------1MZEz3yoatH0WQkVWD0dQ6Yt--