Re: sequence primary key
От | Tom Lane |
---|---|
Тема | Re: sequence primary key |
Дата | |
Msg-id | 26398.995402545@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: sequence primary key (Jason Earl <jdearl@yahoo.com>) |
Список | pgsql-novice |
Jason Earl <jdearl@yahoo.com> writes: > ... you need to make sure that you don't specify a > toto_id in your insert query. For example your query > should look something like: > INSERT INTO toto (db) VALUES ('SOME VALUE') > And then when you select from the table you will find > that the toto_id column was filled automagically. > processdata=> SELECT * FROM toto; > toto_id | db > ---------+------------ > 1 | SOME VALUE > (1 row) One way to make this easier is to put the columns that are normally filled by a DEFAULT at the end of the table, not the start. For example, if you'd made "db" the first column then it'd have sufficed to write INSERT INTO toto VALUES ('SOME VALUE') with the same results as above. However, a lot of people say it is good practice to write an explicit list of the column names you are supplying in *every* INSERT, whether you think you are skipping over defaulted columns or not. This makes your code less likely to break when you rearrange the database layout. regards, tom lane
В списке pgsql-novice по дате отправления: