Re: [SQL] INSERT w/o variable names for a SERIAL type?
| От | Tom Lane |
|---|---|
| Тема | Re: [SQL] INSERT w/o variable names for a SERIAL type? |
| Дата | |
| Msg-id | 9907.951676161@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: [SQL] INSERT w/o variable names for a SERIAL type? (Peter Eisentraut <peter_e@gmx.net>) |
| Ответы |
Re: [SQL] INSERT w/o variable names for a SERIAL type?
Re: [SQL] INSERT w/o variable names for a SERIAL type? |
| Список | pgsql-sql |
Peter Eisentraut <peter_e@gmx.net> writes:
> Emils Klotins writes:
>> Now, if I want to write a general #define, I'd need to have a way
>> to specify 'default' for SERIAL field, for, if I omit the id field in
>> VALUES, I need to specify all the rest of the fields explicitly.
>>
>> Is there any value I could put in place of id in VALUES part, to
>> make it replaced with the next value in sequence?
> INSERT INTO my_table VALUES (a, b, c, DEFAULT, x, y, z, ...);
I think that is legal SQL92 syntax, but Postgres doesn't accept it
at present.
The usual recommendation is to call out the columns you are loading
explicitly:
INSERT INTO my_table(a,b,d) VALUES (val-for-a, val-for-b, val-for-d);
The ones you don't load get their default values substituted instead.
This way is a shade more verbose, but it's good solid defensive
programming practice: the insert will do what it's supposed to
even if the table schema changes to add/delete/reorder columns.
regards, tom lane
В списке pgsql-sql по дате отправления: