Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phtyW-0005jI-7x for pgsql-general@arkaria.postgresql.org; Thu, 30 Mar 2023 15:14:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phtyV-0000Q5-6p for pgsql-general@arkaria.postgresql.org; Thu, 30 Mar 2023 15:14:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phtyU-0000Pv-P4 for pgsql-general@lists.postgresql.org; Thu, 30 Mar 2023 15:14:02 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1phtyP-0003yt-72 for pgsql-general@lists.postgresql.org; Thu, 30 Mar 2023 15:14:01 +0000 Received: by mail-ed1-x52b.google.com with SMTP id ew6so77790910edb.7 for ; Thu, 30 Mar 2023 08:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; t=1680189235; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=7Uqnk/QNrMcV0CGQbrhlRw9ZNu74U9yw3aEYaWK21io=; b=nQyEJQ6FT9SvwqLlNqJysBemYgVgE1EjPIzzkpSU+nEwD7uMQ1cwtzv2dXPsEnLkA1 8qFa/rUBFHu7YpFCPndxc9eDmylBLDnjlJK8SRCT6MZstJvZnmmXAjbiHH0XF2eIj7Ou N3g/K711197FI6oTSW9go+9ijUiTYH8pubuY4Siiqejs3D8VWlczgQSUqq1QRx62EhGX xXKjbHg5psyYWpegfuaf7moU9i2LgEgoTpBX254NfMod4UuWnTGQUeJNcUGXkn3OU5OD MS/FW+gcAgaHFWVaUElNtQFi5QHA3HI8YbuD+zihrjY52aCTwE3TFhv7RiD0sx1M/PhN g9BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680189235; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7Uqnk/QNrMcV0CGQbrhlRw9ZNu74U9yw3aEYaWK21io=; b=MzdUbb4ixmvhd97wWwqXn+wTTWUdgiXwf7Yib+t34f3ByUi69CaIfJk1Qwtu0bOo3J z91d3BA/oDa6SGY7fFvTsU3bbjyv2scT8fQsOG9zrB7ndY5HfA3N5I3riY/5/Gc2rQTn 77fEQ5BdqSuQZVDu3KF4Izy7+sRpF81bGrGr0n3Oh5kinPJcL96hBV/pY8mHxMVnxpT2 5sZKGrwE3+gHphnRWWEPmr37CbaZ18RBk7Rk7CUSWUXimJAmihEz1O+wSWCTm6tqwlWx 9jSz21GDz3XZml45drSl0J7Dln09CyO7vF3R+kFQoNHjO2z4sFrvCnuCoBDmhfVnZOgs QfVg== X-Gm-Message-State: AAQBX9fgfWDalDVC4S5L+lB5YytzbnbLPJ9rM6J/hihZ5PGcy9Zo9OA2 q9H7xtJuTvn5Ti3wY5FgWPm3Zw== X-Google-Smtp-Source: AKy350ZfdcrLtc8GgJe6ZUo1wzUnnDLcDb981G97wMgNbzYTnhvwLtCs0YoGvpQxxDc/t6DP47Sitg== X-Received: by 2002:a17:906:4d8b:b0:92b:f8ce:4e75 with SMTP id s11-20020a1709064d8b00b0092bf8ce4e75mr22273735eju.72.1680189234935; Thu, 30 Mar 2023 08:13:54 -0700 (PDT) Received: from localhost.localdomain (62-47-147-6.adsl.highway.telekom.at. [62.47.147.6]) by smtp.gmail.com with ESMTPSA id wt7-20020a170906ee8700b009477a173744sm439945ejb.38.2023.03.30.08.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 08:13:54 -0700 (PDT) Message-ID: <9e27adafdc683c21b493b6fece4e50124307668f.camel@cybertec.at> Subject: Re: Using CTID system column as a "temporary" primary key From: Laurenz Albe To: Dominique Devienne , Francisco Olarte Cc: Adrian Klaver , Sebastien Flaesch , Kirk Wolak , Geoff Winkless , pgsql-general Date: Thu, 30 Mar 2023 17:13:53 +0200 In-Reply-To: References: <478a7768-6b11-dda5-ce82-5b9d39aa4923@aklaver.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2023-03-30 at 14:32 +0200, Dominique Devienne wrote: > I fail to see that myself, sorry. You can bind NULL, you can bind values,= so why > wouldn't you be able to bind DEFAULT too? I see that more as a failing to= the > binding API myself :) That doesn't work because DEFAULT is not a value like NULL, it is a keyword. > But I guess it can be worked around with something like > `... values(coalesce($1, default), ..)` > and abusing NULL to mean DEFAULT on a case-by-case bases. > Assuming default can be used in this way (didn't try), of course. That won't work either, because DEFAULT is a keyword and cannot used in expressions. For what you want, I can think of two approaches: 1. Use two prepared INSERT statements with different column lists, one with the column in question and the other without. Then use the appropriate statement, depending on whether you want the default value or not. 2. Don't use a default value, but a BEFORE INSERT trigger. If you insert some magical value like -1, the trigger replaces the value with some default. The second solution is somewhat uglier (personal hudgement) and slower. Yours, Laurenz Albe