2

I wish to make a new table with some data from the old, but also with new empty columns I can edit.

I would start with:

CREATE TABLE new_table AS SELECT ID, title, summary FROM old_table;

and then alter the table with new columns:

ALTER TABLE new_table ADD note datatype;

But I need my new empty column to be between title & summary, and not 'in the end' as ALTER gives me.

I would like to combine CREATE TABLE and CREATE TABLE AS SELECT - but is that possible?

6
  • Columns do not have an order. It is meaningless to say that the new columns are "between" title & summary. Commented May 5, 2015 at 14:57
  • Why does the column ordinal matter? The order of the columns is irrelevant in SQL. But to answer your underlying question, just do a CREATE TABLE first, then populate it.
    – Siyual
    Commented May 5, 2015 at 14:57
  • This sounds like a duplicate of stackoverflow.com/questions/5327545/…
    – Mattgb
    Commented May 5, 2015 at 14:59
  • Just a point in light of "columns do not have an order". .. their order can matter in some side cases - in general it's probably not going to make a lot of difference, but it can: stackoverflow.com/questions/894522/…
    – Ditto
    Commented May 5, 2015 at 15:04
  • The order is important, because we can't manually edit the content if we do a view or a query (we're using Valentina Studio), and we need to do a content analysis where we write memos and content-codes inside the data. I know there must be other ways around this - but we're running out of time for our thesis. Commented May 5, 2015 at 15:08

1 Answer 1

7

What about: CREATE TABLE new_table AS SELECT ID, title, '' AS note, summary FROM old_table;

If you wanted to have a specific datatype, you could try CAST. For example, CAST(1 as INTEGER) AS note

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.