Re: Row ordering after CREATE TABLE AS...SELECT regexp_split_to_table(source_text, regexp) AS new_column

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Row ordering after CREATE TABLE AS...SELECT regexp_split_to_table(source_text, regexp) AS new_column
Дата
Msg-id 28900.1266995202@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Row ordering after CREATE TABLE AS...SELECT regexp_split_to_table(source_text, regexp) AS new_column  (John Gage <jsmgage@numericable.fr>)
Ответы Re: Row ordering after CREATE TABLE AS...SELECT regexp_split_to_table(source_text, regexp) AS new_column  (John Gage <jsmgage@numericable.fr>)
Список pgsql-general
John Gage <jsmgage@numericable.fr> writes:
> This is a two-part question:
> 1) I have a source_text that I want to divide into smaller subunits
> that will be contained in rows in a column in a new table.  Is it
> absolutely certain that the initial order of the rows in the resultant
> table after this  operation:

> CREATE TABLE new_table AS SELECT regexp_split_to_table(source_text,
> E'regexp') as subunits FROM source_table;

> will be the same as the order of these subunits in the original text?

If you have a version new enough to have synchronize_seqscans, you'd
need to turn that off.  Otherwise should be OK.

> 2) I would like to be able to create a serial-type column during
> CREATE TABLE AS in the new table that "memorizes" this order so that I
> can reconstruct the original text using ORDER BY on that serial
> column.  However, I am stumped how to do that.

I think the trick is to get the SRF to be expanded before the serial
values are assigned.  There's more than one way to do it, but I think
(too tired to experiment) this would work:

  CREATE TABLE new_table (id serial, subunits text);

  INSERT INTO new_table(subunits) SELECT regexp_split_to_table(source_text,
    E'regexp') FROM source_table;

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: Trying to get a C function built with MSVC
Следующее
От: John Gage
Дата:
Сообщение: Re: Row ordering after CREATE TABLE AS...SELECT regexp_split_to_table(source_text, regexp) AS new_column