Re: SELECT * and column ordering - Mailing list pgsql-general

From Jasen Betts
Subject Re: SELECT * and column ordering
Date
Msg-id kdcq7c$soj$1@gonzo.reversiblemaps.ath.cx
Whole thread Raw
In response to SELECT * and column ordering  ("Meta Seller Dev/Admin" <metaseller@gmail.com>)
List pgsql-general
On 2013-01-16, Meta Seller Dev/Admin <metaseller@gmail.com> wrote:
> Hi! (I'm Chris Angelico posting from a work account - usually I'm here
> under the name rosuav@gmail.com.)
>
> 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

pgsql-general by date:

Previous
From: Steven Schlansker
Date:
Subject: Re: Combine Date and Time Columns to Timestamp
Next
From: Adrian Klaver
Date:
Subject: Re: Combine Date and Time Columns to Timestamp