how do i insert a default value?

Started by Andy Krigerover 23 years ago4 messagesgeneral
Jump to latest
#1Andy Kriger
akriger@greaterthanone.com

How do you insert a default value in an insert statement that doesn't
specify column names? For example, I have a table with 20 columns. I don't
want to specify the names in order to skip columns that have default values.

In MySql a null or empty value uses the default column value. In Postgres?

thx
andy

#2scott.marlowe
scott.marlowe@ihs.com
In reply to: Andy Kriger (#1)
Re: how do i insert a default value?

On Tue, 12 Nov 2002, Andy Kriger wrote:

How do you insert a default value in an insert statement that doesn't
specify column names? For example, I have a table with 20 columns. I don't
want to specify the names in order to skip columns that have default values.

In MySql a null or empty value uses the default column value. In Postgres?

Postgresql uses the keyword DEFAULT with no ticks to get a default.

insert into table bubba values ('truck','washer',DEFAULT,'gun
rack',DEFAULT,36,24,36);

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: scott.marlowe (#2)
Re: how do i insert a default value?

"scott.marlowe" <scott.marlowe@ihs.com> writes:

On Tue, 12 Nov 2002, Andy Kriger wrote:

How do you insert a default value in an insert statement that doesn't
specify column names? For example, I have a table with 20 columns. I don't
want to specify the names in order to skip columns that have default values.

Postgresql uses the keyword DEFAULT with no ticks to get a default.

insert into table bubba values ('truck','washer',DEFAULT,'gun
rack',DEFAULT,36,24,36);

That's new in 7.3, though. In prior releases you could only (a) omit
columns at the right, or (b) use a column name list.

regards, tom lane

#4scott.marlowe
scott.marlowe@ihs.com
In reply to: Tom Lane (#3)
Re: how do i insert a default value?

On Tue, 12 Nov 2002, Tom Lane wrote:

"scott.marlowe" <scott.marlowe@ihs.com> writes:

On Tue, 12 Nov 2002, Andy Kriger wrote:

How do you insert a default value in an insert statement that doesn't
specify column names? For example, I have a table with 20 columns. I don't
want to specify the names in order to skip columns that have default values.

Postgresql uses the keyword DEFAULT with no ticks to get a default.

insert into table bubba values ('truck','washer',DEFAULT,'gun
rack',DEFAULT,36,24,36);

That's new in 7.3, though. In prior releases you could only (a) omit
columns at the right, or (b) use a column name list.

Yeah, I realized that RIGHT after I'd written my second response. sigh