将值插入到一个查询的多行中
这并不是主题所暗示的另一个蹩脚的问题;)。这是我的查询:
在提交时使用 (OIDS) 创建临时表 temp_tab AS SELECT 22 AS num, 'smth' AS Something_else;
SELECT * FROM temp_tab;
我想要完成的是一次向此临时表插入多个值,如下所示:
在提交时创建临时表 temp_tab DROP AS SELECT (22, 23, 24) AS num, ('smth', 'wqer', 'asdf') AS Something_else;
我不将数据插入普通表而不是临时表的原因是因为我想使用我的数据库来计算地理点(postgis)之间的距离,并且我有很多数据 - 这样做(加排序)对于 php 来说太详尽了,我不需要存储这些数据 - 我只想进行一些计算并将集合返回到我的代码。
It's not another lame question as the topic suggests ;). So here's my query:
CREATE TEMP TABLE temp_tab WITH (OIDS) ON COMMIT DROP AS SELECT 22 AS num, 'smth' AS something_else;
SELECT * FROM temp_tab;
What I'm trying to accomplish is to insert into this temporary table more than one value at a time, like this:
CREATE TEMP TABLE temp_tab WITH (OIDS) ON COMMIT DROP AS SELECT (22, 23, 24) AS num, ('smth', 'wqer', 'asdf') AS something_else;
The reason why I'm not inserting the data into an ordinary table rather than temp is because I want to use my db to calculate distances between geographical points (postgis), and I have a lot of data - doing this (plus sorting) would be too exhaustive for php and I don't need to store this data - I just want to make some calculations and return the set to my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以按照 http 使用
VALUES
命令://www.postgresql.org/docs/9.0/interactive/sql-createtableas.html,所以*注意:我还没有尝试过查询,所以那里可能有错字,但你应该得到这个想法。
You can also use a
VALUES
command as per http://www.postgresql.org/docs/9.0/interactive/sql-createtableas.html, so*note: I haven't tried the query, so there may be a typo in there, but you should get the idea.
我不使用 postgresql,但在 SQL Server 中,您可以使用 UNION ALL 构建多行文字。这对你有用吗?
I don't use postgresql, but in SQL Server you can build up multiple rows of literals using UNION ALL. Does this work for you?