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 1scTWU-007bzj-Qw for pgsql-general@arkaria.postgresql.org; Fri, 09 Aug 2024 17:35:30 +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 1scTWS-0051Ff-9g for pgsql-general@arkaria.postgresql.org; Fri, 09 Aug 2024 17:35:28 +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 1scTWR-0051Ea-S1 for pgsql-general@lists.postgresql.org; Fri, 09 Aug 2024 17:35:27 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1scTWP-0040SR-Ch for pgsql-general@lists.postgresql.org; Fri, 09 Aug 2024 17:35:27 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2eeb1ba0468so29782871fa.0 for ; Fri, 09 Aug 2024 10:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723224924; x=1723829724; darn=lists.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=0Az/GMItCReYsBGleLYgsnY1YJmqXNJWEJ61SXhJ+bY=; b=cjiu811YZf8xzImfHxw9nOFdw/YMkUPOfvsSWvoWsHP3yzRvLKl3DZqxKVCXUpIeN3 9Id2ms4u4txySNkmd3YXxd9OTXcYDSV4kYA7LspfsBo0EhT/mnAKxpepdtjL8ZcBvSDT yPK2eYtwhyU+yYCNSMljRfxrniFbWAmzgojJl0A1ha9F1qk/vH2a6CPNe+deCfaNH+zL XnHKXADfRokQfJF46/IfOcZiuIJNHgI8opJcvmm5nOuXoqMNmgiLO1SzAAspP1NkEerl m1slg/Aa7rBc6jvayHesq8Ld0TVUOHCDCp/SGlzmdd7cz4AfNnBEP9DZSpv+gY7bwZ17 WIWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723224924; x=1723829724; 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=0Az/GMItCReYsBGleLYgsnY1YJmqXNJWEJ61SXhJ+bY=; b=KiBTeNUsZEuljrTzDNBlaSSzTogWI5ADFe7bUXk109VInRpy7zzJyuJABDSeM1bcFR ym5gSwHfcXE4OpbdScwjyMtwoHD69qJZlri/iuJjL2RyNMv1KUguJPjepxSQCNHYuvRF eg+vNoPFRg4l13fbxX6oVAqyEtHu906QPU9Wx54wJXgcGOjejq0Xx/1+hOaoKve/kmBQ UX1p6sGJjuCAXNGwQf4Rqje0xj63+zhHJD4TFaLsUc5L/OC29YzV1bRb9YhFOj0ZPmh+ 5y6zt3lskV2lBc7aAmyENiKQGlobQR0xA1qHqZGipMvpYrDPzw/Mu7KViDbR/tdd0CO1 AGNQ== X-Gm-Message-State: AOJu0Yz29xrKiBVeIFLqOuMYMjZlFdMh3v0d7l1HaQLXdIEX3j6YeRMN 2JmN0oGDIaTkzXnFYn7FQ08BgjpzaVUpDDfiqczv425zuUSWg1wPB6vuSlJj3aIg446TFjR0Yla Ktg1nl+do/TbIJ73ftzCYBwGO7w== X-Google-Smtp-Source: AGHT+IGe2ZFT4duvSym1XPElcuuqfa0Axal7c/GO8peIg3jo3N3068BbnhNpOjwUY8hMF29T8/nn2iF33cqZWquQ2kw= X-Received: by 2002:a05:6512:33c9:b0:52c:f521:9423 with SMTP id 2adb3069b0e04-530ee988af4mr1599017e87.26.1723224923755; Fri, 09 Aug 2024 10:35:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?Q?Torsten_F=C3=B6rtsch?= Date: Fri, 9 Aug 2024 19:35:12 +0200 Message-ID: Subject: Re: Getting specific partition from the partition name To: veem v Cc: pgsql-general Content-Type: multipart/alternative; boundary="00000000000072decb061f4391a1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000072decb061f4391a1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable If you want to convert your table name into a timestamp, you don't need substring or similar. This also works: =3D# select to_date('table_part_p2024_08_08', '"table_part_p"YYYY"_"MM"_"DD= '); to_date ------------ 2024-08-08 (1 row) But as Greg said, your strings are perfectly sortable. On Thu, Aug 8, 2024 at 9:52=E2=80=AFPM veem v wrote: > Hi , > We are using postgres version 15.4. We have a range partition table and > the partition naming convention is generated by pg_partman and is somethi= ng > like "table_name>_pYYYY_MM_DD". > > We have a requirement of extracting specific partitions ordered by the > date criteria and also do some operations on that specific date. But I am > struggling and it's not working as expected.I tried something as below bu= t > it's not working.Can somebody guide me here please. > > to_date( substring('table_part_p2024_08_08' from > '_p(\d{4})_(\d{2})_(\d{2})'), 'YYYY_MM_DD' > ) < current_date > > or is there any ready-made data dictionary which will give us the order o= f > the partitions by the date and we can get hold of the specific nth > partition in that table? > > Regards > Veem > --00000000000072decb061f4391a1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If you want to convert your table name into a timesta= mp, you don't need substring or similar. This also works:
=3D# select to_date('table_part_p2024_08_08', '"tab= le_part_p"YYYY"_"MM"_"DD');
=C2=A0 to_date = =C2=A0
------------
=C2=A02024-08-08
(1 row)

But as Greg said, your strings are perfectly sortable.


On Thu, Aug 8, 2024 at 9:52=E2=80=AFPM veem v <veema0000@gmail.com> wrote:
Hi ,
We are us= ing=C2=A0postgres version 15.4. We have a range partition table and the par= tition naming convention is generated by pg_partman and is something like &= quot;table_name>_pYYYY_MM_DD".

We have a r= equirement=C2=A0of extracting specific partitions ordered by the date crite= ria and also do some operations on that specific date. But I am struggling = and it's not working as expected.I tried something as below but it'= s not working.Can somebody guide me here please.

= =C2=A0to_date(=C2=A0substring('table_part_p2024_08_08' from '_p= (\d{4})_(\d{2})_(\d{2})'),=C2=A0 =C2=A0 =C2=A0 'YYYY_MM_DD'
=
=C2=A0 =C2=A0 ) < current_date

<= div>or is there any ready-made=C2=A0data dictionary which will give us the = order of the partitions by the date and we can get hold of the specific=C2= =A0nth partition in that table?

Regards
Veem
--00000000000072decb061f4391a1--