根据相对位置比较表列
我在比较 PostgreSQL 中的两个选择时遇到问题。我通过 JDBC 执行这些选择,然后通过将结果集中的数据插入新表来创建新表。我这样做是因为我想避免具有相同名称的列,例如“count”。然后我必须比较这些表中的数据。
问题是,如果相同的数据具有不同的列顺序,那么这些表应该是相同的。例如,如果表 t1
和 t2
中有 3 列 (1, 2, 3),则当 t1.1 = t2.2 时,这些表是相同的
和 t1.2 = t2.1
和 t1.3 = t2.3
。
I have a problem with comparing two selects in PostgreSQL. I'm executing these selects by JDBC, then create new tables by inserting data from the result set to new table. I do it because I want to avoid columns with same name like "count". Then I have to compare data in these tables.
The problem is that these tables should be same if there is same data with different order of columns. For example, if there are 3 columns (1, 2, 3) in tables t1
and t2
these tables are the same if t1.1 = t2.2
and t1.2 = t2.1
and t1.3 = t2.3
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
行中的列顺序在创建时确定。如果您执行 a
或
您获得创建表所用的列顺序。如果您在
SELECT
中命名列,您就会按照明确的顺序获得列。您必须始终拼写出用于类似操作的列。如果您稍后更改其中一个表中的列顺序,它可能会崩溃。不要依赖
*
。只要不包含
ORDER BY
子句,SELECT
中的行顺序就是不确定。如果您想要特定的顺序,则必须ORDER BY
主要列或唯一列(或唯一的列组合)。如果按一组非唯一的列进行排序,则同一键组内的行将再次处于不确定的顺序。阅读有关 ORDER BY 子句的手册。
The order of columns within a row is determined at the time of creation. If you do a
or
you get the column order you created the table with. If you name columns in your
SELECT
you get your columns in your explicit order.You must always spell out the columns you use for an operation like yours. It could break if you alter the order of columns in one of your tables later. Do not rely on
*
.The order of rows in a
SELECT
is indeterminate as long as you don't include anORDER BY
clause. If you want a specific order you have toORDER BY
a primary or unique column (or unique combination of columns). If you order by a non-unique set of columns, the rows within groups of the same key are again in indeterminate order.Read the manual on the ORDER BY clause.