Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vAWYC-002aer-KE for pgsql-general@arkaria.postgresql.org; Sun, 19 Oct 2025 16:46:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vAWYB-00BQsi-5u for pgsql-general@arkaria.postgresql.org; Sun, 19 Oct 2025 16:46:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vAWYA-00BQsZ-PT for pgsql-general@lists.postgresql.org; Sun, 19 Oct 2025 16:46:29 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vAWY7-0034vv-02 for pgsql-general@postgresql.org; Sun, 19 Oct 2025 16:46:29 +0000 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-27ee41e074dso42574645ad.1 for ; Sun, 19 Oct 2025 09:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760892384; x=1761497184; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=sYr/3mmF9Rm/83Z1taqk5wibG5YQ9mbodf9W+wz3hm0=; b=ALkmIdXB7OYuuZtvM4c4Ybc9lfmo/qNoXhv4OWK0QnSQlgTFUIFNVmFAvf8vhf4Jq+ iV4enGQlcub3bekGik7hxnq3VCuASjJSG5T9PNNX0uWwzHf5FScB7ppSOfEzzTfyQZYT +owfiZjahxNcak1jUDY8dRJx3Qphcz8i7JZ5xOIJ5WrQQjoD5Tg6DZ90O4h5jSyceeI8 Zia/2gPAWQq5RZYsm4mY5rzUIJ/p+KHhUqbec4TopNfQlJS5zCs+js52pXdLVF/qITvE mfWJPFBXj1U/sUuzx3267Of76Pd8VbUqvd+SuS8kzEaQdv8/3NWxH9wVhXOanB+8noOM EGEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760892384; x=1761497184; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sYr/3mmF9Rm/83Z1taqk5wibG5YQ9mbodf9W+wz3hm0=; b=B7yu9xszbj1pCMxOfi0TTcaQeryjtd7XN98VunUVclaS7sSO7CIDgXUzio3UIzHKlO DwR5EgcyaLQsi8RnJIAoazsqmUjNC32GM7VEX8sRjGezkMjzeLQiXdfrx2ZY00ix3EzW ppqKo+HwK2B1tDVhPlwqECtf9xYE3Ll5hE9JNric2+Ag2hlPkwAHHK6WDKhpkMBLS+/z T4Fb6EK8Avr0sNKdJRHlPVJugx7KGSFr2My4vFiofe3eMAcNJrOFqaQKuqARZDh4oyfi hk/4EmksfvdBqVlBj7d063Ji82dApLXUMXKvDDStYDT0PNYT7CiETZdmJY0u4Gj0mg2B GlHQ== X-Gm-Message-State: AOJu0Yy0hdeY+7hFwPb9GxI4kB9MvzkDWWCIJMEdl9zyY3jPnbSmfoDX jUzD1TgvJFQGKcnO5PXRRaqcb7M108Rf07lC+klQlVwDAIJiaJIOE6SxRSdAKeAL5A6F1mcQ53k XfSwYGLhXARvZnnIWyFlZbcYdM+4YXDY= X-Gm-Gg: ASbGnctZMqKdeTUJobjBjaW1iCw6Ymp0jdyPr41T2nilMTuk8RuN60Mt67xB8TD5EZ6 FXaLe8UhP/xFn7R4K4sZk9yZ1tOrZuwcNtsc4C4P/unbLlAvWn9LfQT4QHUDA0g4ldq+ZQCjsEM 3f8H96VSc7QRkf6sCIjhETvwmN1Q8QHbP6/dqLoPO5XYhbVdRPE4P4HoX21+Hni7GDy6o3yd9k3 1r8hIyjnsT1ZWBBS2gCZj/sfw5Er6VL012vmrXkRalRy8hf60q0/P7jCSzppJ1AS438CiiC X-Google-Smtp-Source: AGHT+IFyW9An1zzHXPsrLWnhRpoQa24q/yzYUnJW7YdWa/zSADXmePd/CtMKLrTxFgVTrPulVDkpdvg92bMGSNSIFtQ= X-Received: by 2002:a17:903:46c7:b0:28a:8ae7:4034 with SMTP id d9443c01a7336-290c9cd4b1bmr126743635ad.25.1760892383457; Sun, 19 Oct 2025 09:46:23 -0700 (PDT) MIME-Version: 1.0 References: <63dfbc7c-bc63-7fa-a51b-915dd804ea2@appl-ecosys.com> <6b30ebac-6d6d-4c26-be73-de67e208e4e1@aklaver.com> In-Reply-To: From: Isaac Morland Date: Sun, 19 Oct 2025 12:46:11 -0400 X-Gm-Features: AS18NWApMDNV0FaF2X8WMaH7A_KIxSg2ATpEJ6KrZNx04VzcidoaAFdHk_wVues Message-ID: Subject: Re: Convert date and time colums to datetime To: Rich Shepard Cc: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="00000000000000f3ee064185b53b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000000f3ee064185b53b Content-Type: text/plain; charset="UTF-8" On Sun, 19 Oct 2025 at 12:35, Rich Shepard wrote: > On Sun, 19 Oct 2025, Adrian Klaver wrote: > > > 2) If you really need a timestamp the work is already done, instead of > > building on the fly. > > Adrian, > > As each row in the table already has both a date column and a time column I > don't know if I 'really' need a timestamp. When would a timestamp be really > needed? > > > select ('10/19/2025'::date + '07:50'::time)::timestamptz; > > Yes, I saw that on the doc page. This requires manually changing each row > in > the table rather than using a date/time condition/function to to create the > single timestamp column. So, apparently there's not a way to modify the > table other than by hand. If you're talking about actually changing the table, replacing the two columns with a single column, you would need ALTER TABLE. Something like (not tested, just to give you the basic idea): ALTER TABLE [table] ADD [new_column] timestamp; UPDATE [table] SET [new_column] = [date_column] + [time_column]; ALTER TABLE [table] DROP date_column, DROP time_column; The answer already given essentially tells you what to put in the UPDATE statement, which is an important element. The following page may help with details: https://www.postgresql.org/docs/current/sql-altertable.html Of course, all queries that touch the table need to be updated. There are some new features that might help with migration; for example, if you made a new timestamp column that is a generated column, you could have both co-existing in the table at the same time while you update the users of the table to use the new column. You also might be able to do something with defaults to allow the column adding to also populate the new column appropriately, which would allow you to just do a single ALTER TABLE and no UPDATE. I personally would almost always combine date+time into a single timestamp. It's easier for computations, and whenever you need just one all you have to do is cast to date or time as appropriate. --00000000000000f3ee064185b53b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, 19 Oct 2025 at 12:35, Rich Shepar= d <rshepard@appl-ecosys.com<= /a>> wrote:
On Sun, 19 Oct 2025, Adrian Klaver wrote:

> 2) If you really need a timestamp the work is already done, instead of=
> building on the fly.

Adrian,

As each row in the table already has both a date column and a time column I=
don't know if I 'really' need a timestamp. When would a timesta= mp be really
needed?

> select ('10/19/2025'::date + '07:50'::time)::timestamp= tz;

Yes, I saw that on the doc page. This requires manually changing each row i= n
the table rather than using a date/time condition/function to to create the=
single timestamp column. So, apparently there's not a way to modify the=
table other than by hand.

If you're tal= king about actually changing the table, replacing the two columns with a si= ngle column, you would need ALTER TABLE. Something like (not tested, just t= o give you the basic idea):

ALTER TABLE [table]
=C2=A0 =C2=A0 ADD [new_column] timestamp;
UPDATE [table]<= /div>
=C2=A0 =C2=A0 SET [new_column] =3D [date_column] + [time_column];=
ALTER TABLE [table]
=C2=A0 =C2=A0 DROP date_column,
=C2=A0 =C2=A0 DROP time_column;

The answer= already given essentially tells you what to put in the UPDATE statement, w= hich is an important element. The following page may help with details:


Of course, all queries that touch the = table need to be updated. There are some new features that might help with = migration; for example, if you made a new timestamp column that is a genera= ted column, you could have both co-existing in the table at the same time w= hile you update the users of the table to use the new column. You also migh= t be able to do something with defaults to allow the column adding to also = populate the new column appropriately, which would allow you to just do a s= ingle ALTER TABLE and no UPDATE.

I personally woul= d almost always combine date+time into a single timestamp. It's easier = for computations, and whenever you need just one all you have to do is cast= to date or time as appropriate.
--00000000000000f3ee064185b53b--