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 1q4AGs-0003Ct-4q for pgsql-general@arkaria.postgresql.org; Wed, 31 May 2023 01:05:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q4AGq-0007eb-Og for pgsql-general@arkaria.postgresql.org; Wed, 31 May 2023 01:05:00 +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 1q4AGq-0007eS-EF for pgsql-general@lists.postgresql.org; Wed, 31 May 2023 01:05:00 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q4AGn-002nxI-Qn for pgsql-general@lists.postgresql.org; Wed, 31 May 2023 01:04:59 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1q4AGe-0038CX-SS; Tue, 30 May 2023 21:04:48 -0400 Date: Tue, 30 May 2023 21:04:48 -0400 From: Bruce Momjian To: Ian Lawrence Barwick Cc: Wen Yi <896634148@qq.com>, pgsql-general Subject: Re: How to make the generate_series to generate the letter series? Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, May 29, 2023 at 12:51:15PM +0900, Ian Lawrence Barwick wrote: > 2023年5月29日(月) 12:39 Wen Yi <896634148@qq.com>: > > > > Hi team, > > when I study the generate_series function, I found that it can not only generate the number series but also can generate the date series.(ref: https://www.postgresql.org/docs/current/functions-srf.html) > > That means I can make the generate_series to generate the letter series. > > > > So I try this command (I guess I can follow the ascil code rule to complete this work): > > > > # SELECT * FROM generate_series('a'::int, 'z'::int, 1); > > > > But the postgres reply me a error, because the 'a' can't translate into 'integer' type. > > > > Can someone provide me a better solution? > > Thanks in advance! > > SELECT chr(x + 96) FROM generate_series(1, 26) x A working example is: SELECT chr(x + 96) FROM generate_series(1, 26) as f(x); Here is a blog entry about more complex examples: https://momjian.us/main/blogs/pgblog/2012.html#July_24_2012 -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you.