如何更改 PostgreSQL 数据库表中列的位置? [英] How do I alter the position of a column in a PostgreSQL database table?

查看:105
本文介绍了如何更改 PostgreSQL 数据库表中列的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下方法,但没有成功:

I've tried the following, but I was unsuccessful:

ALTER TABLE person ALTER COLUMN dob POSITION 37;

推荐答案

"改变列位置" 在 PostgreSQL Wiki 中说:

"Alter column position" in the PostgreSQL Wiki says:

PostgreSQL 目前定义了列基于 attnum 列的顺序pg_attribute 表.唯一的办法更改列顺序是通过重新创建表,或通过添加列和旋转数据,直到你达到所需的布局.

PostgreSQL currently defines column order based on the attnum column of the pg_attribute table. The only way to change column order is either by recreating the table, or by adding columns and rotating data until you reach the desired layout.

这很弱,但在他们的辩护中,在标准 SQL 中,也没有重新定位列的解决方案.支持更改列序数位置的数据库品牌正在定义对 SQL 语法的扩展.

That's pretty weak, but in their defense, in standard SQL, there is no solution for repositioning a column either. Database brands that support changing the ordinal position of a column are defining an extension to SQL syntax.

我想到了另一个想法:您可以定义一个 VIEW 来指定您喜欢的列顺序,而无需更改基表中列的物理位置.

One other idea occurs to me: you can define a VIEW that specifies the order of columns how you like it, without changing the physical position of the column in the base table.

这篇关于如何更改 PostgreSQL 数据库表中列的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆