Search Postgresql Archives

Re: "Named" column default expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tom Lane wrote on 28.10.2011 16:21:
I just noticed that Postgres allows the following syntax:
create table foo
(
id integer constraint id_default_value default 42
);

I'm wondering why this doesn't throw an error then.

It's an implementation artifact --- our grammar regards everything after
a column's type name as a list of column constraints.  So "DEFAULT foo"
has to be considered as one variant of column constraint.  We could
probably tweak the grammar enough so it didn't allow "CONSTRAINT name"
to be prefixed to that one case, but there seems little point in adding
complexity for that.  The most it would accomplish is to break
applications that are expecting this particular deviation from spec to
work.

Thanks for the explanation.

I have seen the syntax on SQL Server and there it does give the default definition a name. I was somewhat surprised about the syntax as I have never considered a default to be a constraint. So I checked the PostgreSQL manual just to find that the same syntax works there as well....

Regards
Thomas





--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux