Re: SELECT * and column ordering

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT * and column ordering
Date: 2013-01-19 00:43:24
Message-ID: kdcq7c$soj$1@gonzo.reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2013-01-16, Meta Seller Dev/Admin <metaseller(at)gmail(dot)com> wrote:
> Hi! (I'm Chris Angelico posting from a work account - usually I'm here
> under the name rosuav(at)gmail(dot)com(dot))
>
> I've run into a bit of an awkwardness in PostgreSQL setup and am
> hoping for some expert advice.
>
> Several of the tables I work with have two groups of fields: standard
> fields and "free fields". The standard fields have fixed names and
> will always exist; the free fields could be anything. In many cases, I
> want to enumerate all fields, including free ones, and for that I use
> "SELECT * FROM tablename".
>
> Normally, the standard fields are at the beginning of the table,
> having been created first. This is very convenient, as it lets me
> iterate over them first, and then pick up the free fields after. (Or
> alternatively, pick up a specific standard field by its index.) New
> free fields can be created at any time, and the program will happily
> pick them up and work with them. Order among free fields never
> matters.

walking the list of column names you get back from "select *" is likely
to be faster than any of the other options, and you only need to do it
once and (and then store the indices of the interesting columns in an array for
later reference.)

PQgetvalue() has O(1) complexity so once you know the column number
you want the cost is the same.

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2013-01-19 01:06:00 Re: Combine Date and Time Columns to Timestamp
Previous Message Steven Schlansker 2013-01-19 00:40:38 Re: Combine Date and Time Columns to Timestamp