Insert into temporary values ​​(select .... order by id)

I am using Informix database (version 7.32). In one operation, I create a temporary table with the identifier of a regular table and a sequential column (so that I will have all the identifiers from a regular table, numbered continuously). But I want to insert information from a regular table, sorted by ID, for example:

CREATE TEMP TABLE tempTable (id serial, folio int );

INSERT INTO tempTable(id,folio)
SELECT 0,folio FROM regularTable ORDER BY folio;

But this creates a syntax error (due to ORDER BY)

Is there a way to order information and then paste it into tempTable?

UPDATE: the reason I want to do this is because the regular table contains about 10,000 elements and in the jsp file, it should show each record, but it will take a lot of time, so the real reason I want this to do is pagination. This version of Informix does not Limitand Skip. I can’t renumber the serial number because it’s in a relationship, and this is the only solution where you can get a fixed number of results on one page (for example, 500 results per page). An identifier (called a folio) is missing in a regular table because they have been deleted. if i put

SELECT * FROM regularTable WHERE folio BETWEEN X AND Y

I could possibly get 300 on one page and then 500 on the next page

+3
source share
7

SELECT... ORDER BY INSERT .

0

, SQL :

CREATE TEMP TABLE tempTable1 (
id serial,
folio int);

SELECT folio FROM regularTable ORDER BY folio
INTO TEMP tempTable2;

INSERT INTO tempTable1(id,folio) SELECT 0,folio FROM tempTable2;
+3

Informix SELECT INSERT SELECT.

SELECT:

  • INTO TEMP
  • UNION.

, FROM SELECT , INSERT ( , ).

+2

, Informix, , , - :

INSERT INTO tempTable(id,folio)
SELECT 0, folio 
FROM (
    SELECT folio FROM regularTable ORDER BY folio
);
0

. .

, SQL , , , , . ORDER BY, .

, .

0

, , , . , , , , , , - , ?

, , CREATE SEQUENCE, , Informix.

, , UNLOAD , LOAD . SERIAL.

0

- ?

SELECT
    folio
FROM
    (
        SELECT
            ROWNUM n,
            folio
        FROM
            regularTable
        ORDER BY 
            folio
    )
WHERE
    n BETWEEN 501 AND 1000

, "", 10K .

, Informix ROWNUM, Oracle.

0

Source: https://habr.com/ru/post/1699132/


All Articles