pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to make the generate_series to generate the letter series?
3+ messages / 3 participants
[nested] [flat]

* How to make the generate_series to generate the letter series?
@ 2023-05-29 03:39 Wen Yi <896634148@qq.com>
  2023-05-29 03:51 ` Re: How to make the generate_series to generate the letter series? Ian Lawrence Barwick <barwick@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Wen Yi @ 2023-05-29 03:39 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

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!


Yours,
Wen Yi

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to make the generate_series to generate the letter series?
  2023-05-29 03:39 How to make the generate_series to generate the letter series? Wen Yi <896634148@qq.com>
@ 2023-05-29 03:51 ` Ian Lawrence Barwick <barwick@gmail.com>
  2023-05-31 01:04   ` Re: How to make the generate_series to generate the letter series? Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Ian Lawrence Barwick @ 2023-05-29 03:51 UTC (permalink / raw)
  To: Wen Yi <896634148@qq.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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

Regards

Ian Barwick





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to make the generate_series to generate the letter series?
  2023-05-29 03:39 How to make the generate_series to generate the letter series? Wen Yi <896634148@qq.com>
  2023-05-29 03:51 ` Re: How to make the generate_series to generate the letter series? Ian Lawrence Barwick <barwick@gmail.com>
@ 2023-05-31 01:04   ` Bruce Momjian <bruce@momjian.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Bruce Momjian @ 2023-05-31 01:04 UTC (permalink / raw)
  To: Ian Lawrence Barwick <barwick@gmail.com>; +Cc: Wen Yi <896634148@qq.com>; pgsql-general <pgsql-general@lists.postgresql.org>

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  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Only you can decide what is important to you.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-05-31 01:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-05-29 03:39 How to make the generate_series to generate the letter series? Wen Yi <896634148@qq.com>
2023-05-29 03:51 ` Ian Lawrence Barwick <barwick@gmail.com>
2023-05-31 01:04   ` Bruce Momjian <bruce@momjian.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox