Search Postgresql Archives

Re: Where do I enter commands?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux