From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | Konstantin Izmailov <pgfizm(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: pg_attribute.attnum - wrong column ordinal? |
Date: | 2009-11-25 01:30:28 |
Message-ID: | 407d949e0911241730j52ca3099oe7bce71adf1318e1@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Wed, Nov 25, 2009 at 1:03 AM, Konstantin Izmailov <pgfizm(at)gmail(dot)com> wrote:
> My question: can pg_attribute.attnum be used to determine the sequential
> ordinal positions of columns in a table? What is a right way to get the
> ordinal numbers?
You could use something like:
row_number() over (partition by T.schemaname,T.viewname order by
attnum) as "ORDINAL_POSITION"
If you just stick this in there in place of attnum it'll cause an
extra sort. It should be possible with enough clever rearranging of
the query to do the whole query with a single sort since that's the
same sort order that the results are ordered in.
Incidentally you probably want UNION ALL rather than UNION in the
original query.
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Konstantin Izmailov | 2009-11-25 02:00:20 | Re: pg_attribute.attnum - wrong column ordinal? |
Previous Message | Christophe Pettus | 2009-11-25 01:05:29 | Re: Processing Delay |
From | Date | Subject | |
---|---|---|---|
Next Message | KaiGai Kohei | 2009-11-25 01:52:04 | Re: SE-PgSQL patch review |
Previous Message | Simon Riggs | 2009-11-25 01:24:09 | Re: Hot standby and removing VACUUM FULL |