25

Is there ANY difference between those two statements?:

INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets');

and:

INSERT INTO distributors (dname) VALUES ('XYZ Widgets');

I mean is there at least one reason to use one or another pattern in some particular situation or is it completely the same? did is a serial column.

Borys
  • 2,676
  • 2
  • 24
  • 37

2 Answers2

34

It's exactly the same thing. No need to pick one instead of the other.

Usually default keyword is handy when you have computer-generated code. It makes life easier to just use every single column in the insert clause and just use default when you don't have a specific value for certain column.

Other than that, as I said, it's the same.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 4
    `default` is also very handy when you want to indicate an `insert` that used default values for every single column. – Jon Hanna May 09 '14 at 14:38
4
INSERT INTO distributors (dname) VALUES ('XYZ Widgets');

This is fine, you do not need to specify a field if you want its default value being saved, provided a default is set.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95