Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0wWI-0003g3-Ko for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 22:24:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0wWG-0007CM-73 for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 22:24:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0wWF-0007CF-VG for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 22:24:56 +0000 Received: from mail-it0-f65.google.com ([209.85.214.65]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g0wW9-0006b2-M6 for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 22:24:55 +0000 Received: by mail-it0-f65.google.com with SMTP id e14-v6so4625860itf.1 for ; Fri, 14 Sep 2018 15:24:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:mail-followup-to:date :in-reply-to:message-id:user-agent:organization:mime-version; bh=jrnxyr7ezSko9tp7Hr7sLmh8NAFMQqq9x5+pGODSAWs=; b=IcD2iWpB7gcZ75eygf8EKQSddzFOpUu1v3UdkjrXB6Qdpbu74XOntnfi1NXUNmLSJF SJnkTo0OMg+afbUdz59AAO8/KU757YbuyTWr8Apg3v3YCKVNzJoqcHwZQSpVwhV/vD32 9UsIueG/Pcjm9Cb1PErxeOpVmu8/R+vNbf5WVBXCyrJXBabVHUrHrmi6sNZNi0CSBvfK AuFdCO4mi8MBci4qaiKdFZQXKIHgbXPNt4KskWtAeP9Ru6b0V6u/Q6y9yNsJ7tUlnOmw o04SVJHBxxPTRmtg7pSm/lrXAnMtsQEb6ZpjuW+o1B/gWTaq6iS2rzJjiEhIb9L+nH2n jhPw== X-Gm-Message-State: APzg51DOxMHd1RrwvrXQa6c7gGcsDM4k7ya/LxQ3ZJJtlgG+VBUXnIDo uE8FcgJo2zaE/qAAHXnILiPwAq35 X-Google-Smtp-Source: ANB0VdaTCNb1YxuRA3Xddv/1CqZu1B29eiKZ7n4tAHrwBNjxByuqYJjvACumfTspxjkoV6UrYhtAmA== X-Received: by 2002:a24:918d:: with SMTP id i135-v6mr4019332ite.98.1536963887112; Fri, 14 Sep 2018 15:24:47 -0700 (PDT) Received: from smtp.gmail.com (net82.ceos.umanitoba.ca. [130.179.67.82]) by smtp.gmail.com with ESMTPSA id a64-v6sm83966itg.40.2018.09.14.15.24.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Sep 2018 15:24:46 -0700 (PDT) From: Sebastian P. Luque To: pgsql-general@lists.postgresql.org Subject: Re: column information from view References: <87in373gpd.fsf@gmail.com> <2046.1536961948@sss.pgh.pa.us> Mail-Followup-To: pgsql-general@lists.postgresql.org Date: Fri, 14 Sep 2018 17:24:45 -0500 In-Reply-To: <2046.1536961948@sss.pgh.pa.us> (Tom Lane's message of "Fri, 14 Sep 2018 17:52:28 -0400") Message-ID: <87a7oj3efm.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Organization: University of Manitoba MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 14 Sep 2018 17:52:28 -0400, Tom Lane wrote: > Umm ... why are you doing cols.table_name = 'persistent_view' and not > cols.table_name = 'temporary_view' ? I should have pointed out that the column descriptions are all NULL in the temporary view, and I'd like to pull them from the persistent view which have the same name. I know this is brittle though. > It seems rather odd to write a query that involves both pg_class and > the information_schema --- by involving pg_class, you've already given > up hope of making the query portable to non-PG DBMSes. > Personally, I'd probably write it something like this: > select pa.attnum, pa.attname, col_description(pa.attrelid, pa.attnum) > from pg_attribute pa, pg_attribute ta where pa.attrelid = > 'persistent_view'::regclass and ta.attrelid = > 'temporary_view'::regclass and pa.attname = ta.attname order by > pa.attnum; > If you were dealing with tables, it'd also be wise to add "pa.attnum > > 0 and not pa.attisdropped", but I think neither of those conditions > can fail for views. Thank you Tom, this does seem more elegant, but I'd have to retrieve the actual "attrelid" from the names of the two views somehow. I'm very green on using these internal database tables. -- Seb