如何在 postgresql 中创建十进制序列?

发布于 2025-01-11 14:19:00 字数 285 浏览 0 评论 0原文

我想做的是用如下数据填充表格:

| thickness | length | width  |
|: 0.02 |:1:| 1:|
|: 0.02 |:1:| 2:|
|: 0.04|:1:|1:|
|: 0.06|:1:| 1:|

本质上,我需要以 0.02 的增量从 0 填充到 10

我的宽度和长度列同样需要从 1 填充到 144增量为 0.02

这是大量行,希望自动填充它,而不是手动全部输入。不幸的是,我只能让序列作为整数工作,并且我希望它们按小数递增。

What I'm trying to do is populate a table with data such as follows:

| thickness | length | width  |
|: 0.02 |:1:| 1:|
|: 0.02 |:1:| 2:|
|: 0.04|:1:|1:|
|: 0.06|:1:| 1:|

Essentially I have a column thickness that I need populated from 0 to 10 in increments of 0.02

My Width and Length columns similarly need to be populated from 1 to 144 in increments of 0.02

This is large number of rows and would like to populate it automaticly instead of typing this all out by hand. Unfortunately I could only get the sequence to work as integers, and I would like them to increment by decimals.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2025-01-18 14:19:00

您可以在两个 generate_series() 调用之间使用交叉联接

insert into the_table (thickness, length, width)
select t.thickness, l.val, l.val
from generate_series(0,10,0.02) as t(thickness) 
  cross join generate_series(1,144,0.02) as l(val)

You can use a cross join between two generate_series() calls

insert into the_table (thickness, length, width)
select t.thickness, l.val, l.val
from generate_series(0,10,0.02) as t(thickness) 
  cross join generate_series(1,144,0.02) as l(val)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文