How do I use generate_series() in SQL in the middle of a string?
Ex: 'This is the 1 string.' 'This is the 2 string.' 'This is the 3 string.'
I'm looking to generate numbers from 1 to 10000, so I know I would use generate_series(1, 10000), but how can I use this in the middle of a string?
I'm trying to insert this into table 'xyz' column 'strings'.
I have tried this code but it obviously gave me an error: INSERT INTO xyz (strings) 'This is the ' || generate_series(1, 10000) || ' string.';
Here is a way to do generate numbers(20) and insert each one in a separate row.
create table t(x varchar(100))
insert into t
select 'This is ' || cast(x.* as varchar(20)) || ' string'
from generate_series(1,20) x
https://dbfiddle.uk/?rdbms=postgres_14&fiddle=b646bd97e9aa3a8bb131dbb0335953ca
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.