Re: VARIANT / ANYTYPE datatype

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Alvaro Herrera" <alvherre(at)alvh(dot)no-ip(dot)org>, "Pg Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: VARIANT / ANYTYPE datatype
Date: 2011-05-04 17:21:40
Message-ID: 4DC144D4020000250003D286@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:

> A customer came to us with this request: a way to store "any" data
> in a column.

+1

More than once (usually in replication, interface, or audit
situations) I've had to create a table with one column each of a
number of different data types, only one of which will be used in
each row. It would make life much simpler for programming such
things if an "unknown" type could be stored. I could either cast
the types in the rows based on the related identifier column, but it
would be even nicer if they could be read "unknown" and pg_typeof or
something similar could be used to control flow based on the type.

As one example, only *last night* I created the following table as
part of the development of our shop's next generation of software.
(Yes I know about Slony, Londiste, and others -- we need to roll
something out which integrates with existing systems, without
production disruption, over the next few years. This does require a
custom solution.)

Table "public.DbTranOpValue"
Column | Type | Modifiers
----------------+-------------------+-----------
countyNo | "CountyNoT" | not null
backendPid | integer | not null
tranStart | "TimestampT" | not null
logRecordSeqNo | "LogRecordSeqNoT" | not null
columnName | "ColumnNameT" | not null
isAfter | "BooleanT" | not null
textValue | text |
intValue | bigint |
numericValue | numeric |
binaryValue | bytea |
booleanValue | "BooleanT" |
dateValue | "DateT" |
timeValue | "TimeT" |
timestampValue | "TimestampT" |
Indexes:
"DbTranOpValue_pkey" PRIMARY KEY, btree
("backendPid", "tranStart", "logRecordSeqNo", "columnName")

I would much rather have had a "value" column of unknown type.

-Kevin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2011-05-04 17:29:52 Re: branching for 9.2devel
Previous Message Josh Berkus 2011-05-04 17:21:36 Re: branching for 9.2devel