Re: Where do I enter commands? - Mailing list pgsql-general

From Andrew Sullivan
Subject Re: Where do I enter commands?
Date
Msg-id 20151025151029.GA1228@crankycanuck.ca
Whole thread Raw
In response to Re: Where do I enter commands?  (David Blomstrom <david.blomstrom@gmail.com>)
List pgsql-general
On Sun, Oct 25, 2015 at 07:57:48AM -0700, David Blomstrom wrote:
> In phpMyAdmin, I've become accustomed to simply copying existing tables,
> then adding, deleting and renaming columns as needed.

Oh!  Interesting.  I suspect you're actually _undermining_ your
ability to use the database (because often when you copy a table it's
a sign that you're using the database like a spreadsheet, and you're
giving up a lot of functionality that way).

But, suppose you're wanting to do that, then here's the easy way to do
it:

--- if you want the same table structure without the data

CREATE TABLE newtable AS SELECT * FROM oldtable WHERE 1=0;

-- if you want the same table with some data

CREATE TABLE newtable AS SELECT columns, you, want, in, order
    FROM oldtable
    [WHERE conditions];

If you want only some columns or new order or something, the WHERE
clause in the latter statement should be 1=0.  It makes a null set
always.  Handy trick.

> I can see PostgreSQL is going to have a learning curve - hopefully shorter
> than the years it took me to learn MySQL - but it looks interesting.

It should be much easier.  You have the basics from MySQL already.
Consistency and rigour are the changes ;-)

A

--
Andrew Sullivan
ajs@crankycanuck.ca


pgsql-general by date:

Previous
From: David Blomstrom
Date:
Subject: Re: Where do I enter commands?
Next
From: Adrian Klaver
Date:
Subject: Re: Where do I enter commands?