Marcello Verona
2008-12-24 15:41:08 UTC
Vorrei creare al volo una colonna contatore su Postgres come faccio con
MySQL.
Con MySQL questa cosa si può fare così:
mysql> set @N = 0;
Query OK, 0 rows affected (0.27 sec)
mysql> SELECT @N := @N +1 AS numero, nome,stipendio,genere FROM persone;
+--------+--------+-----------+--------+
| numero | nome | stipendio | genere |
+--------+--------+-----------+--------+
| 1 | John | 5000 | m |
| 2 | Mario | 6000 | m |
| 3 | Frank | 5000 | m |
| 4 | Otto | 6000 | m |
| 5 | Susan | 5500 | f |
| 6 | Martin | 5500 | m |
| 7 | Mary | 5500 | f |
| 8 | Bill | 5000 | m |
| 9 | June | 6000 | f |
+--------+--------+-----------+--------+
9 rows in set (0.01 sec)
è possibile realizzare la stessa cosa con Postgres?
Se si con quale sintassi?
Grazie mille.
Marcello
MySQL.
Con MySQL questa cosa si può fare così:
mysql> set @N = 0;
Query OK, 0 rows affected (0.27 sec)
mysql> SELECT @N := @N +1 AS numero, nome,stipendio,genere FROM persone;
+--------+--------+-----------+--------+
| numero | nome | stipendio | genere |
+--------+--------+-----------+--------+
| 1 | John | 5000 | m |
| 2 | Mario | 6000 | m |
| 3 | Frank | 5000 | m |
| 4 | Otto | 6000 | m |
| 5 | Susan | 5500 | f |
| 6 | Martin | 5500 | m |
| 7 | Mary | 5500 | f |
| 8 | Bill | 5000 | m |
| 9 | June | 6000 | f |
+--------+--------+-----------+--------+
9 rows in set (0.01 sec)
è possibile realizzare la stessa cosa con Postgres?
Se si con quale sintassi?
Grazie mille.
Marcello