Re: INSERT INTO FROM SELECT

From: Andrej <andrej(dot)groups(at)gmail(dot)com>
To: lmanorders <lmanorders(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: INSERT INTO FROM SELECT
Date: 2014-06-03 00:00:49
Message-ID: CACMx3pPR+Hc9H_7k9+BHv4Ui3XNM9ZhYCtf1mnpv4mF72iGmrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi Lynn,

To the best of my knowledge the SQL standard doesn't define that data
inside a table needs
to be stored in any given order. If you expect to see it in a certain
sequence define that at query time,
when you retrieve the data?

Cheers,
Andrej

On 3 June 2014 11:52, lmanorders <lmanorders(at)gmail(dot)com> wrote:
> I’m using Postgres 9.3 on Windows. I am attempting to insert several rows
> into a table using data from another table. It is inserting correctly, but
> the order isn’t correct. Is an ‘order by’ command not recognized in this
> situation?
>
> Here are the two tables:
> CREATE TABLE accounts (
> acctno char(22) PRIMARY KEY,
> acctdesc varchar(60),
> ...
> accttype integer
> );
>
> CREATE TABLE rprtfrmt (
> lineno integer PRIMAY KEY,
> bdgtacct char(22),
> prntline integer,
> addline integer,
> totllevl integer,
> desconly integer,
> prntundrln integer,
> balshtentry integer,
> rprttype integer,
> blnkline integer
> );
>
> Here are the commands I’m using:
>
> CREATE TEMP SEQUENCE rprtfrmt_seq INCREMENT BY 50 START WITH 50;
> INSERT INTO rprtfrmt (lineno, bdgtacct, prntline, addline, totllevl,
> desconly, prntunderln, balshtentry, rprttype, blnkline)
> (SELECT nextval(‘rprtfrmt_seq’), acctno, 1,1,0,0,0,0,0,1 FROM accounts
> WHERE (accttype = 0 OR accttype = 2) ORDER BY acctno)
>
> It inserts all of the line numbers, account numbers, and ‘fixed’ data into
> the rprtfrmt table, but not in account number order. Any help will be
> greatly appreciated.
> Thanks,
> Lynn
>

--
Please don't top post, and don't use HTML e-Mail :} Make your quotes concise.

http://www.georgedillon.com/web/html_email_is_evil.shtml

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message lmanorders 2014-06-03 00:09:41 Re: INSERT INTO FROM SELECT
Previous Message lmanorders 2014-06-02 23:52:02 INSERT INTO FROM SELECT