Change PostgreSQL column order in pgAdmin

PostgreSQL cannot move an existing column to a new position, so pgAdmin cannot either. Compare rebuilding the table, using a view, and ordering columns at query or export time.

Searches for changing column order in pgAdmin usually come from one of three goals: making a table easier to read while browsing it, getting a CSV or other delimited export with columns in a set sequence, or permanently changing how the table is defined. These goals need different approaches. Only the third one changes the table, and it is the most expensive.

Short answer: what pgAdmin can and cannot do

pgAdmin is a client. It generates and sends SQL to the PostgreSQL server, so it cannot offer an operation that the server does not support. PostgreSQL's ALTER TABLE has no clause for moving an existing column to a new position. There is nothing like the AFTER or FIRST options found in some other database systems. When you add a column, PostgreSQL places it at the end of the table definition. A drag-to-reorder control for existing columns would therefore have nothing to translate into, and you should not expect to find one in the table properties dialog.

The recommendation depends on what you need. If you only want the columns to display or export in a different order, change the order in your query, a view, or the export step, and leave the table alone. Rebuild the table only when the stored definition itself has to change. A rebuild gives you a permanent new order, but you have to recreate everything that depends on the table, and you need a maintenance window if the table is in use.

What "column order" actually refers to

Two separate things are often both called column order:

  • Stored definition order: the position recorded in the system catalog for each column (the attnum value in pg_attribute). SELECT *, INSERT statements without a column list, and the table's default display all follow this order.
  • Presentation order: the sequence of columns in a particular query result, view, or exported file. Each statement sets this through its column list, and it does not change the table.

This mirrors the difference between changing stored characters and changing only how text is displayed. A view or an explicit SELECT list affects presentation only. A table rebuild changes the stored definition. Editing pg_attribute directly to swap positions is not supported. It can corrupt how existing rows are read and should not be treated as an option.

Option 1: Order columns in the query (no table change)

In pgAdmin's Query Tool, the result grid shows columns in the order the query lists them. Naming the columns explicitly is the simplest fix when the goal is readability:

SELECT email, full_name, id, created_at
FROM customers;

Main benefit: no risk to data or dependencies, and the change takes effect immediately. Tradeoff: you have to repeat the column list in every query where the order matters.

Option 2: Create a view with the preferred order

A view stores a reusable column order without touching the base table:

CREATE VIEW customers_ordered AS
SELECT email, full_name, id, created_at
FROM customers;

After a refresh, the view appears in pgAdmin's object browser, and you can browse or query it like a table. Simple single-table views like this one can usually accept inserts and updates, but check PostgreSQL's rules on updatable views before you rely on that. Tradeoff: a column added to the base table later does not appear in the view until you redefine it.

Option 3: Rebuild the table in the new order

When the stored order must change, the usual method is to create a new table with the columns in the desired sequence, copy the rows over, and swap the names. Because PostgreSQL DDL is transactional, you can wrap these steps in one transaction:

BEGIN;

CREATE TABLE customers_new (
    email       text NOT NULL,
    full_name   text,
    id          bigint PRIMARY KEY,
    created_at  timestamptz NOT NULL DEFAULT now()
);

INSERT INTO customers_new (email, full_name, id, created_at)
SELECT email, full_name, id, created_at
FROM customers;

ALTER TABLE customers RENAME TO customers_old;
ALTER TABLE customers_new RENAME TO customers;

COMMIT;

This example is illustrative. The column names and types must match your real table. The rename is not enough on its own, because PostgreSQL tracks dependencies by object, not by name. After the rename, existing foreign keys, views, and triggers still point to customers_old. Before you drop the old table, check and recreate the following:

  • Indexes, unique constraints, check constraints and exclusion constraints
  • Foreign keys defined on this table, and foreign keys in other tables that reference it
  • Views, materialized views and functions that use the table
  • Triggers, row-level security policies, privileges and ownership
  • Sequences or identity columns: identity values may need OVERRIDING SYSTEM VALUE during the copy, and the sequence must be reset afterward
  • Comments, statistics targets and other per-column settings

pgAdmin can help here. The SQL tab for a table shows the DDL that pgAdmin generates for the table, which gives you a starting point to rearrange. Compare it with your actual dependencies, because generated DDL may not include objects stored outside the table definition. Copying a large table takes time and disk space, and the stronger locks taken during the swap block other sessions. Taking a backup first is standard practice.

Shortcut to avoid: CREATE TABLE ... AS SELECT does give you the new column order, but it does not copy primary keys, defaults, NOT NULL constraints other than those implied by the query, indexes or foreign keys. CREATE TABLE ... (LIKE ... INCLUDING ALL) copies much more, but it keeps the original column order, so it does not solve this problem.

Option 4: Reorder only the exported delimited file

If the real goal is a CSV with columns in a particular sequence, set that sequence when you export. PostgreSQL's COPY accepts either a column list or a query:

COPY (SELECT email, full_name, id, created_at FROM customers)
TO STDOUT WITH (FORMAT csv, HEADER);

Writing to STDOUT sends the data to the client. In psql, the \copy command saves it as a file on your own machine. Inside pgAdmin, you can run the SELECT in the Query Tool and save the result to a file, or use the Import/Export dialog. The exact options in these dialogs vary between pgAdmin versions. The supplied evidence does not cover them, so check the version you have.

Reordering an exported file afterward with a separate delimited-text tool also works, but only if the tool handles CSV quoting correctly. Fields can contain the delimiter, quote characters, or line breaks inside quotes. A tool that splits on every comma or every newline will shift values into the wrong columns without warning. Reordering at export time avoids that risk.

Will the result stay usable after copying or sharing?

Approach | Changes stored table | Survives in shared SQL or exports | Main risk
Explicit SELECT list | No | Only where the query is reused | Must be repeated in every query
View | No | Yes, for anyone querying the view | Drifts when base table gains columns
Table rebuild | Yes | Yes, including SELECT * and dumps | Missed dependencies, locking, copy time
Ordered COPY or export | No | Yes, in the exported file | None to the table; file must be regenerated

Any code that relies on position instead of names can break after a rebuild. This includes SELECT * used by application code, INSERT statements without a column list, and positional COPY imports. Search for these patterns before you change the stored order. For exported files, a header row keeps the column meaning readable even if someone reorders the columns later.

Is a rebuild worth it?

Usually not when the motivation is readability alone. A view or an explicit column list gives you the same visual result without the risk. A rebuild is easier to justify when a table is being redesigned anyway, when positional imports or legacy tools depend on the order, or when you are grouping fixed-width columns to reduce alignment padding in storage. The size of any storage saving depends on the column types and on the data, and no measurements were supplied for this article.

Gaps in this review

No version-specific pgAdmin documentation or test results were supplied. Statements about pgAdmin's interface are limited to how it relates to PostgreSQL's own DDL, and readers should confirm dialog options in their installed version. No timing, lock-duration or storage figures are given, because none were measured.