iT邦幫忙

4

Postgresql 不需要遞迴,快速生成連續整數1~100

看到暐翰分享的 SQLServer不需要遞迴,使用spt_values快速生成連續整數0-2048

https://ithelp.ithome.com.tw/articles/10229752

我也來一段

with t1 as (
select array_agg(oid) as arr1
  from pg_class
)
select sn
  from t1
  join lateral
  unnest(arr1) with ordinality as gs(elem, sn)
  on true
 limit 100
;

+-----+
| sn  |
+-----+
|   1 |
|   2 |
|   3 |
|   4 |
....
|  98 |
|  99 |
| 100 |
+-----+
(100 rows)

在之前介紹 Array 時就有使用過這個技巧.

https://ithelp.ithome.com.tw/articles/10222763?sc=rss.iron


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 則留言

0
暐翰
iT邦大師 1 級 ‧ 2020-01-16 22:40:28

謝謝大大分享,讚!

Postgresql可惜現在沒有實戰接觸它的機會,只能測試環境跑來玩 : (

0
yves1990
iT邦新手 5 級 ‧ 2020-01-17 11:22:51

請問可以提供 Postgresql關於 AKB 快速生成連續 1 ~ 48 張圖片嗎
/images/emoticon/emoticon01.gif

讀取圖片可以.
https://ithelp.ithome.com.tw/upload/images/20200117/20050647ASJELxIzzN.jpg

我要留言

立即登入留言