Thread: Select statement

Select statement

From
dave go
Date:
Hi,

I am trying create a new table A from table B. On B
(b1, b2, b3, b4 ) I would like create a table A (a1,
a2, a3) where a2 is b2 and b3.

example:
A)

Id, lastname, Firstname, MInit
------------------------------

B)

Id, Name, MInit
---------------

Thanks very much for your help,
Dave


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: Select statement

From
"Richard Huxton"
Date:
From: "dave go" <godave621@yahoo.com>

> Hi,
>
> I am trying create a new table A from table B. On B
> (b1, b2, b3, b4 ) I would like create a table A (a1,
> a2, a3) where a2 is b2 and b3.

create table foo(a serial, b text);

select a, substr(b,1,strpos(b,' ')-1) as firstname, substr(b,strpos(b,'
')+1) as lastname into bar from foo;

will create a table bar. You will need to add your own sequences etc. later.

Note - CHECK YOUR NAMES FIRST - this will only work with exactly two names
separated by one space.

- Richard Huxton


Re: Select statement

From
missive@frontiernet.net (Lee Harr)
Date:
On Mon, 21 May 2001 19:26:04 +0000 (UTC), dave go <godave621@yahoo.com> wrote:
> Hi,
>
> I am trying create a new table A from table B. On B
> (b1, b2, b3, b4 ) I would like create a table A (a1,
> a2, a3) where a2 is b2 and b3.
>
> example:
> A)
>
> Id, lastname, Firstname, MInit
> ------------------------------
>
> B)
>
> Id, Name, MInit
> ---------------
>


SELECT Id, Firstname||' '||lastname as Name, MInit into B from A;


Re: Re: Select statement

From
"Thalis A. Kalfigopoulos"
Date:
On Mon, 21 May 2001, Lee Harr wrote:

> On Mon, 21 May 2001 19:26:04 +0000 (UTC), dave go <godave621@yahoo.com> wrote:
> > Hi,
> >
> > I am trying create a new table A from table B. On B
> > (b1, b2, b3, b4 ) I would like create a table A (a1,
> > a2, a3) where a2 is b2 and b3.
> >
> > example:
> > A)
> >
> > Id, lastname, Firstname, MInit
> > ------------------------------
> >
> > B)
> >
> > Id, Name, MInit
> > ---------------
> >
>
>
> SELECT Id, Firstname||' '||lastname as Name, MInit into B from A;

That's an interesting syntax which is not "visible" when doing '\h select' in the psql monitor but exists in the online
manual.Someone could add it?... 


regards,
thalis


Re: Re: Select statement

From
"Richard Huxton"
Date:
From: "Thalis A. Kalfigopoulos" <thalis@cs.pitt.edu>

> >
> > SELECT Id, Firstname||' '||lastname as Name, MInit into B from A;
>
> That's an interesting syntax which is not "visible" when doing '\h select'
in the psql monitor but exists in the online manual. Someone could add
it?...

Try "\h select into" - also listed as that in the html docs.

- Richard Huxton