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 1lLBFp-0005B7-UP for pgsql-general@arkaria.postgresql.org; Sat, 13 Mar 2021 20:52:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lLBFo-0005JI-QZ for pgsql-general@arkaria.postgresql.org; Sat, 13 Mar 2021 20:52:56 +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 1lLBFo-0005J7-9E for pgsql-general@lists.postgresql.org; Sat, 13 Mar 2021 20:52:56 +0000 Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lLBFm-0005xZ-00 for pgsql-general@postgresql.org; Sat, 13 Mar 2021 20:52:55 +0000 Received: by mail-qv1-xf35.google.com with SMTP id h3so5970877qvh.8 for ; Sat, 13 Mar 2021 12:52:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=YL3y7izbQKuM3JhrGW/Tzbh3ZouhJ3QmcxtqkmrQd04=; b=fe7zzZJbwkiglW3ZDzl8Oq/UxmttNp/EWRFI9YndWDh4F31+ovroe/ENrqUtMViKD2 ISys+aZrLic/04TvrodxrBhvZLUxkjIUM9cNgEK68lgy63kDc2cJ41aor0VTfcXPsuEG CtTFAdySdlJOxPqrvFuFwZZ5qhQdfWBg/2atXQqlsy0tKme31+yQ7Fx5czLansaDXTik 3ifms0oqs/5mK3cjnPHLabpLK51OAESBBeqU+Z+nPumbp1X4JVMlV898JE0EqicVmd04 jYMh6XFzYCod/C+UcO0o91hE9sJvTgHgcpuvpPtyPJ4nIvhCuzdPGYyWe2cX7DpubOxR ls+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=YL3y7izbQKuM3JhrGW/Tzbh3ZouhJ3QmcxtqkmrQd04=; b=Zu4m3WUe889bQ/RcOAFwM1WhCTiVrvJ2Ua1BomjLJhXie4rSNweMvPmlsTum3d9bLU G1rFL3gUpb5IM2vlqnLEgBl4Xvb/6s0wJchVLUICV44Bduog8jKDIaGhGSIxRXAAvpx4 EuJnNNLguJkXC1+/Q2s2QNoNHbmLsenLvoqgfRfandgZWU73yxk8sCUff3fX/YEs8usR tRmpew2FIgLmLvckNc0Hwvgv+QxcupGFrEk+fA2zXEQ9hv8P5HPrBJAlhBzPcjCGfJem XP7PRctu7eGRv2cFMrRTobv/43rwjgTw3GOQAPbsmczdM5T0QSIJWX/it1nrC5BwX/1c 1CLA== X-Gm-Message-State: AOAM531QUYHtp8u5Nl22V3fwBFrN72fDLyyHcf541I9UE68qchZMJatT hTKn0+LnwwTTQI0rN1jYl0uUc62gG1Uhvkhkvo9D8CfTHsJmQb4YkB8/xZiq/AeOkgsfUAIuBev SFmKE6iy115cKSXQSJfci3EDHnGzMH1ZQRtb2Ngun+ehlF9cWmnoSBcOScSanHBsrnYA9BBmU0a k0 X-Google-Smtp-Source: ABdhPJzGgzzeSyHifKTAt2u3qAIjpBus6aElJ0DZjXRfp7KTBM5DdGvqezpBKxwMVW2xtVEX4I3jvw== X-Received: by 2002:a0c:ff06:: with SMTP id w6mr4039850qvt.51.1615668772445; Sat, 13 Mar 2021 12:52:52 -0800 (PST) Received: from [192.168.4.41] (072-017-018-098.res.spectrum.com. [72.17.18.98]) by smtp.gmail.com with ESMTPSA id 30sm6602307qta.38.2021.03.13.12.52.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Mar 2021 12:52:51 -0800 (PST) Subject: Re: Compare with default value? To: Ulrich Goebel , pgsql-general@postgresql.org References: From: Joe Conway Message-ID: <23993869-ba59-0799-5b46-e6f15f64ab88@joeconway.com> Date: Sat, 13 Mar 2021 15:52:51 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/13/21 1:05 PM, Ulrich Goebel wrote: > I would like to get the rows, where a column has the default value, > similar to: > > select id fromt tbl where col = default > > Is there a chance? It isn't pretty, and not all that practical, but for example: 8<-------------------- create table def(id int, f1 text not null default 'foo'); insert into def values(1,'hello'),(2,default),(3,default),(4,'bar'); SELECT * FROM def WHERE $$'$$ || f1 || $$'::text$$ = (SELECT pg_get_expr(d.adbin, d.adrelid, true) FROM pg_attrdef d JOIN pg_attribute a on d.adrelid = a.attrelid AND d.adnum = a.attnum WHERE a.attrelid = 'def'::regclass AND a.attname = 'f1'); id | f1 ----+----- 2 | foo 3 | foo (2 rows) 8<-------------------- Hope this helps, Joe -- Crunchy Data - http://crunchydata.com PostgreSQL Support for Secure Enterprises Consulting, Training, & Open Source Development