counter v insert into ... select

Michal Hlavac hlavki na medium13.sk
Čtvrtek Duben 21 17:44:58 CEST 2005


Ondrej Koala Vacha wrote:
> Dobry den,
> 
> vkladam data do tabulky pomoci insert into ... select a je treba, aby 
> kazde takove vkladani vytvorilo souvislou ciselnou radu od 1. Priklad:
> 
> create table X (
> ...
> int a,
> int b
> );
> 
> insert into X select ...,1, formule from Y where ...
> 
> pricemz po select a,b from X mame dostat
> 
> 1,1
> 1,2
> 1,3
> ... atd.
> 
> 
> Otazka je, jak takove posloupnosti dosahnout. Zatim to mam u mysql resene 
> vnitrni promennou, tedy:
> 
> insert into X select ...,1, (@sqlist_row:=@sqlist_row+1) from Y where ...
> 
> Mate nekdo napad, jak to vyresit obecne, nebo aspon jak to vyresit v 
> postgresql? 

napriklad cez temporary sequence...
pozri si
http://www.postgresql.org/docs/8.0/interactive/sql-createsequence.html

CREATE TEMP SEQUENCE tvoja_sekvencia;
insert into X select ...,1, nextval('tvoja_sekvencia') from Y where ...

miso


Další informace o konferenci Databases