1

I'm trying to alter the type of a column from a table but I also want to know how long it takes to alter the table. I therefore combined:

EXPLAIN ANALYSE

command with:

ALTER TABLE tbl_name ALTER COLUMN col_name TYPE new_type;

So I did:

EXPLAIN ANALYSE ALTER TABLE my_table ALTER COLUMN my_column TYPE text;

But I get the error:

ERROR:  syntax error at or near "ALTER"
LINE 1: EXPLAIN ANALYSE ALTER TABLE my_table ALTER COLUMN my_column...
                        ^

But when I EXPLAIN ANALYSE with a SELECT it has no problem. I.e.:

EXPLAIN ANALYSE SELECT * FROM my_table LIMIT 300;

I must be missing something really simple but I'm not seeing it?

1 Answer 1

6

The manual for EXPLAIN:

Any SELECT, INSERT, UPDATE, DELETE, VALUES, EXECUTE, DECLARE, CREATE TABLE AS, or CREATE MATERIALIZED VIEW AS statement, whose execution plan you wish to see.

ALTER TABLE is not covered.

There are other ways to get the execution time:

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, should have checked the docs for EXPLAIN, is there a way for me to time how long it would take to alter a column then?
Are you using psql? Just turn timing on: \timing on.
Thanks, I just saw that from dba.stackexchange.com/questions/269251/…
@Mark: Ways to get the execution time: stackoverflow.com/a/9065976/939860

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.