Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A57771337BF5 for ; Sun, 19 Sep 2010 15:28:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 36563-07 for ; Sun, 19 Sep 2010 18:28:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id C075C133616B for ; Sun, 19 Sep 2010 15:28:21 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o8JISIeN006631; Sun, 19 Sep 2010 14:28:18 -0400 (EDT) To: Peter Eisentraut cc: saera87@hotmail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #5662: Incomplete view In-reply-to: <1284918458.20510.0.camel@vanquo.pezone.net> References: <201009190941.o8J9fT6H048689@wwwmaster.postgresql.org> <1284918458.20510.0.camel@vanquo.pezone.net> Comments: In-reply-to Peter Eisentraut message dated "Sun, 19 Sep 2010 20:47:38 +0300" Date: Sun, 19 Sep 2010 14:28:18 -0400 Message-ID: <6630.1284920898@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/156 X-Sequence-Number: 28120 Peter Eisentraut writes: > On sön, 2010-09-19 at 09:41 +0000, saera87@hotmail.com wrote: >> The Sequence view in the information schema is incomplete. It does not >> return a Sequence's maximum_value, minimum_value or increment. Please >> complete the view. > This is known and documented: > http://www.postgresql.org/docs/8.4/static/infoschema-sequences.html > Should still be fixed eventually, of course. I think the difficulty is in the fact that you can't join to a sequence whose name isn't predetermined. In the past we've speculated about creating a single catalog or view containing all sequences' parameters, so that information_schema.sequences could be implemented with a join to that. However, there's never been any movement on that, and it seems less than trivial to do. What about inventing a function to extract a sequence's parameters? Perhaps something like pg_sequence_parameter(seq regclass, colname text) returns bigint which would do an appropriate permissions check and then fetch the named column. (This could actually be implemented in a line or two in plpgsql, but I think we want it in C because information_schema shouldn't depend on plpgsql.) This would work OK for all the bigint columns, and we could cheat a bit for the boolean columns by returning 0 or 1. You couldn't fetch the sequence_name column this way, but that's okay with me --- we don't maintain that anyway. Given that, the sequence view would include outputs like CAST(pg_sequence_parameter(c.oid, 'max_value') AS cardinal_number) AS maximum_value, The main objection I can see to this is that fetching multiple column values would involve multiple accesses to the sequence. But it's not clear that a solution based on a single view would be any better performance-wise. Another possibility, if we had LATERAL, would be a function that takes just the sequence OID and returns all its parameters as a row. But again, if we want to do it that way then fixing the view will involve waiting for a complex feature that might or might not show up anytime soon. Or maybe we could implement that function, call it like this CAST((pg_sequence_parameters(c.oid)).max_value AS cardinal_number) AS maximum_value, and plan on optimizing the view when we get LATERAL. regards, tom lane