Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMKbq-001kYv-Fk for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Jun 2024 04:50:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sMKbo-001xrE-Sj for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Jun 2024 04:50:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMKbo-001xr6-Jg for pgsql-hackers@lists.postgresql.org; Wed, 26 Jun 2024 04:50:16 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sMKbm-003APA-7x for pgsql-hackers@postgresql.org; Wed, 26 Jun 2024 04:50:15 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-52ce9ba0cedso3419568e87.2 for ; Tue, 25 Jun 2024 21:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719377412; x=1719982212; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3TdOqkDjQoF1KkQx8Uuib+Ju0je2zgNRespuxEG2qvs=; b=h56YV/h11Rq8LtxZBUV8Y19vz0Pgt/37jssVBFYn+RRi34keG9zIvf75IGNblkAvXH QJpPQe46tOoTENUU03KFs0uflTDMhtiZZVYfw+dNKEcp+nWeANbHyhZw2vS69azT3s5W 5tibgXgvNr/K/iBObJSjn6rGyMOBxvknCYWNEv/lLY3ZFcfh6B3AEQ6vhwyCzsgOykqJ ZDGqgYViqgXL606K1l2IiUR/VLQWcM4v4cIASqN5ceSMYhIeJ/rgJp6E5QMr2b0297KJ KygtW5UkTrufnILtq/rTU1omw0b2Sb87/mS9UvngaGkcrJJQyaPZi5yVH7Zxvv1w597w 0cYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719377412; x=1719982212; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3TdOqkDjQoF1KkQx8Uuib+Ju0je2zgNRespuxEG2qvs=; b=GQSAd5nkm7WaEB1CdKbh109Kf2FU6jqO6W6lM23fZAoTKxHhomKHyUc19HtQaGfp8I 9uf+V5cB2if1BwxQlPgVa5R1r2PJnd1ZIMreKAWXEubW5UGn2v8GUjaEt0S5XSzTHUQf XcXMWqSQSbQfo+N9Ki1Wr1aCl1KALs01iUGqEUcTrmFqPcCv7PoXUYenGROrCji6CuUh mFyaLcqOsVi8a5WJw2q3vFISIU3PP+ZU5A2UZL51BILX1axcXgYKZcchbIYvn7saC+pm kppaAyE3sfPOGAx/bRBurLp+nAZeeF2YkP+SBnuEAytQVRshDajCZVcx/X4RyjTTs1ZI y3iw== X-Forwarded-Encrypted: i=1; AJvYcCVTkOsCSOU2HGxr/Fgo0ipglxBMyIL38zT2G82oVqKF4d4K8nPszgyXFc5uf1YVnz+4818HeAHIAQmly4dmiKcw4JW2KCdG+oJifM2C X-Gm-Message-State: AOJu0YwFIRQrXX/rCeu+z+KRpW7OFmECZQrZlGutc1wc1YggrgHhVDvG 9p2RJ5afHiFj22746STNfZKHUejqip0c4dlwaeBUqANF0A9YJ5KXlvk2vxGsszY90w91jXOAlVA Swg0AgI/0L+DzSxenUn43uzj+OQg= X-Google-Smtp-Source: AGHT+IGoHHZTX2ILyCY5Rna+0//GvRJBTaBa7THc0VwAPoxFFyP+Hf1qAACBwE+PAqhewHz/Frd7KFsO9rbj5am5Qs0= X-Received: by 2002:a05:6512:3da5:b0:52c:e3bd:c70e with SMTP id 2adb3069b0e04-52ce3bdc793mr7846388e87.6.1719377412232; Tue, 25 Jun 2024 21:50:12 -0700 (PDT) MIME-Version: 1.0 References: <1362410.1719349169@sss.pgh.pa.us> <1390099.1719357084@sss.pgh.pa.us> In-Reply-To: From: David Rowley Date: Wed, 26 Jun 2024 16:50:00 +1200 Message-ID: Subject: Re: Should we document how column DEFAULT expressions work? To: "David G. Johnston" Cc: Tom Lane , James Coleman , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 26 Jun 2024 at 13:31, David G. Johnston wrote: > I'd suggest adding to: > > DEFAULT default_expr > The DEFAULT clause assigns a default data value for the column whose colu= mn definition it appears within. The value is any variable-free expression = (in particular, cross-references to other columns in the current table are = not allowed). Subqueries are not allowed either. The data type of the defau= lt expression must match the data type of the column. > > The default expression will be used in any insert operation that does not= specify a value for the column. If there is no default for a column, then = the default is null. > > + Be aware that the [special timestamp values 1] are resolved immediately= , not upon insert. Use the [date/time constructor functions 2] to produce = a time relative to the future insertion. FWIW, I disagree that we need to write anything about that in this part of the documentation. I think any argument for doing this could equally be applied to something like re-iterating what the operator precedence rules for arithmetic are, and I don't think that should be mentioned. Also, what about all the other places where someone could use one of the special timestamp input values? Should CREATE VIEW get a memo too? How about PREPARE? If people don't properly understand these special timestamp input values, then maybe the documentation in [1] needs to be improved. At the moment the details are within parentheses. Namely "(In particular, now and related strings are converted to a specific time value as soon as they are read.)". Maybe it would be better to be more explicit there and mention that these are special values that the input function understands which are translated to actual timestamp values when the type's input function is called. That could maybe be tied into the DEFAULT clause documentation to mention that the input function for constant values is called at DML time rather than DDL time. That way, we're not adding these (unsustainable) special cases to the documentation. David [1] https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE= -DATETIME-SPECIAL-VALUES