Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Tom Lane
Darren Duncan writes: > But I'm just citing numeric as an example; there would be a lot more > in practice, potentially one for every individual type, so for example > if operators were defined for the open union rather than for the base > type, then users/extensions could define their own types a

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Darren Duncan
To follow-up my earlier comments ... I suspect for practical purposes we may want to limit the scope of some type features. For example, the greatest benefits for "open union" / "mixin" types is with routines/operators, not so much with tables. So, Pg could choose to support open unions but

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Darren Duncan
Robert Haas wrote: On Wed, May 11, 2011 at 11:43 AM, Joseph Adams wrote: On Tue, May 10, 2011 at 5:19 PM, Darren Duncan wrote: Examples of open union types could be number, which all the numeric types compose, and so you can know say that you can use the generic numeric operators on values yo

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Robert Haas
On Wed, May 11, 2011 at 11:43 AM, Joseph Adams wrote: > On Tue, May 10, 2011 at 5:19 PM, Darren Duncan > wrote: >> Examples of open union types could be number, which all the numeric types >> compose, and so you can know say that you can use the generic numeric >> operators on values you have si

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Alvaro Herrera
Excerpts from Simon Riggs's message of mar may 10 17:57:20 -0400 2011: > On Wed, May 4, 2011 at 5:58 PM, Alvaro Herrera > wrote: > > both Oracle and MS-SQL have it > > Do they? What types are they called? ANYTYPE -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Rep

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Joseph Adams
On Wed, May 11, 2011 at 7:53 AM, Robert Haas wrote: > That's likely to be how it gets implemented, but you seem to have > missed the point of some of the discussion upthread: the big problem > with that is that someone might type "DROP TYPE foo", and when they > do, you need an efficient way to fi

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Andrew Dunstan
On 05/11/2011 07:53 AM, Robert Haas wrote: On Tue, May 10, 2011 at 10:29 PM, Joseph Adams wrote: It seems to me a reasonable way to implement VARIANT would be to have a data type called VARIANT that stores an OID of the inner type at the beginning, followed by the binary data. That's likely

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-11 Thread Robert Haas
On Tue, May 10, 2011 at 10:29 PM, Joseph Adams wrote: > It seems to me a reasonable way to implement VARIANT would be to have > a data type called VARIANT that stores an OID of the inner type at the > beginning, followed by the binary data. That's likely to be how it gets implemented, but you see

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Pavel Stehule
2011/5/11 Joseph Adams : > On Tue, May 10, 2011 at 10:29 PM, Joseph Adams > wrote: >> The VARIANT type, or similar, would be useful for the JSON data type >> I've been intermittently working on, as it would allow us to create a >> function like this: >> >>    from_json(JSON) returns VARIANT > > Th

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Joseph Adams
On Tue, May 10, 2011 at 10:29 PM, Joseph Adams wrote: > The VARIANT type, or similar, would be useful for the JSON data type > I've been intermittently working on, as it would allow us to create a > function like this: > >    from_json(JSON) returns VARIANT This occurred to me: if PostgreSQL func

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Joseph Adams
It seems to me a reasonable way to implement VARIANT would be to have a data type called VARIANT that stores an OID of the inner type at the beginning, followed by the binary data. When you say pg_typeof(somevariant), you'll get 'variant'. Instead, you'd use a function like this: variant_typ

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Eric McKeeth
On Tue, May 10, 2011 at 3:57 PM, Simon Riggs wrote: > On Wed, May 4, 2011 at 5:58 PM, Alvaro Herrera > wrote: > > > A customer came to us with this request: a way to store "any" data in a > > column. We've gone back and forth trying to determine reasonable > > implementation restrictions, safet

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Simon Riggs
On Wed, May 4, 2011 at 5:58 PM, Alvaro Herrera wrote: > A customer came to us with this request: a way to store "any" data in a > column.  We've gone back and forth trying to determine reasonable > implementation restrictions, safety and useful semantics for them. > I note that this has been requ

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Darren Duncan
Alvaro Herrera wrote: Excerpts from Bruce Momjian's message of mar may 10 16:21:36 -0400 2011: Darren Duncan wrote: To follow-up, an additional feature that would be useful and resembles union types is the variant where you could declare a union type first and then separately other types could

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Alvaro Herrera
Excerpts from Bruce Momjian's message of mar may 10 16:21:36 -0400 2011: > Darren Duncan wrote: > > To follow-up, an additional feature that would be useful and resembles > > union > > types is the variant where you could declare a union type first and then > > separately other types could decla

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-10 Thread Bruce Momjian
Darren Duncan wrote: > To follow-up, an additional feature that would be useful and resembles union > types is the variant where you could declare a union type first and then > separately other types could declare they are a member of the union. I'm > talking about loosely what mixins or type-r

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-06 Thread Darren Duncan
To follow-up, an additional feature that would be useful and resembles union types is the variant where you could declare a union type first and then separately other types could declare they are a member of the union. I'm talking about loosely what mixins or type-roles or interfaces etc are in

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-06 Thread Darren Duncan
Thanks for picking up on my mentioning union types; I wasn't sure if anyone did. Merlin Moncure wrote: On Fri, May 6, 2011 at 3:18 PM, Andrew Dunstan wrote: On 05/06/2011 04:08 PM, Alvaro Herrera wrote: Excerpts from Darren Duncan's message of mié may 04 15:33:33 -0300 2011: I see VARIANT/

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-06 Thread Merlin Moncure
On Fri, May 6, 2011 at 3:18 PM, Andrew Dunstan wrote: > > > On 05/06/2011 04:08 PM, Alvaro Herrera wrote: >> >> Excerpts from Darren Duncan's message of mié may 04 15:33:33 -0300 2011: >> >>> I see VARIANT/ANYTYPE as the most general case of supporting union types, >>> which, >>> say, could have m

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-06 Thread Tom Lane
Alvaro Herrera writes: > Excerpts from Darren Duncan's message of mié may 04 15:33:33 -0300 2011: >> I see VARIANT/ANYTYPE as the most general case of supporting union types, >> which, >> say, could have more specific examples of "allow any number or date here but >> nothing else". If VARIANT

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-06 Thread Andrew Dunstan
On 05/06/2011 04:08 PM, Alvaro Herrera wrote: Excerpts from Darren Duncan's message of mié may 04 15:33:33 -0300 2011: I see VARIANT/ANYTYPE as the most general case of supporting union types, which, say, could have more specific examples of "allow any number or date here but nothing else".

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-06 Thread Alvaro Herrera
Excerpts from Darren Duncan's message of mié may 04 15:33:33 -0300 2011: > I see VARIANT/ANYTYPE as the most general case of supporting union types, > which, > say, could have more specific examples of "allow any number or date here but > nothing else". If VARIANT is supported, unions in gener

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-05 Thread Andrew Dunstan
On 05/05/2011 01:00 PM, Jim Nasby wrote: On May 4, 2011, at 6:24 PM, Andrew Dunstan wrote: I'm far from convinced that storing deltas per column rather than per record is a win anyway. I don't have hard numbers to hand, but my vague recollection is that my tests showed it to be a design that

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-05 Thread Jim Nasby
On May 4, 2011, at 6:24 PM, Andrew Dunstan wrote: > I'm far from convinced that storing deltas per column rather than per record > is a win anyway. I don't have hard numbers to hand, but my vague recollection > is that my tests showed it to be a design that used more space. It depends on how man

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-05 Thread Merlin Moncure
On Wed, May 4, 2011 at 8:03 PM, Tom Lane wrote: > Alvaro Herrera writes: >> As a followup idea there exists the desire to store records as records >> and not text representation of same (given differing record types, of >> course), for which it'd be more worthwhile. > > Maybe.  The conventional w

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Tom Lane
Alvaro Herrera writes: > As a followup idea there exists the desire to store records as records > and not text representation of same (given differing record types, of > course), for which it'd be more worthwhile. Maybe. The conventional wisdom is that text representation of data is more compact

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Alvaro Herrera
Excerpts from Tom Lane's message of mié may 04 20:05:54 -0300 2011: > Alvaro Herrera writes: > > Excerpts from Tom Lane's message of mié may 04 14:36:44 -0300 2011: > >> Just out of curiosity, what actual functionality gain would ensue over > >> just using text? It seems like doing anything usefu

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Tom Lane
"David E. Wheeler" writes: > On May 4, 2011, at 3:04 PM, Alvaro Herrera wrote: >> As someone commented downthread, they also want to have things such as a >> "typeof" operator. It could be used in (say) a plpgsql function to >> choose different branches of code. > FWIW, pg_typeof(any) has been i

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Andrew Dunstan
On 05/04/2011 07:05 PM, Tom Lane wrote: Alvaro Herrera writes: Excerpts from Tom Lane's message of mié may 04 14:36:44 -0300 2011: Just out of curiosity, what actual functionality gain would ensue over just using text? It seems like doing anything useful with the audit table contents would

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread David E. Wheeler
On May 4, 2011, at 3:04 PM, Alvaro Herrera wrote: > As someone commented downthread, they also want to have things such as a > "typeof" operator. It could be used in (say) a plpgsql function to > choose different branches of code. FWIW, pg_typeof(any) has been in core since 9.0. Best, David

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Tom Lane
Alvaro Herrera writes: > Excerpts from Tom Lane's message of mié may 04 14:36:44 -0300 2011: >> Just out of curiosity, what actual functionality gain would ensue over >> just using text? It seems like doing anything useful with the audit >> table contents would still require casting the column t

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Alvaro Herrera
Excerpts from Tom Lane's message of mié may 04 14:36:44 -0300 2011: > Alvaro Herrera writes: > > The main idea is to be able to store column values in an audit table > > like this: > > old_valuevariant > > new_valuevariant > > Currently, they use text for old_value and new_value, but this

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Merlin Moncure
On Wed, May 4, 2011 at 2:55 PM, Andrew Dunstan wrote: > On 05/04/2011 01:36 PM, Tom Lane wrote: >> >>> The main idea is to be able to store column values in an audit table >>> like this: >>> old_value       variant >>> new_value       variant >>> Currently, they use text for old_value and new_valu

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Andrew Dunstan
On 05/04/2011 01:36 PM, Tom Lane wrote: The main idea is to be able to store column values in an audit table like this: old_value variant new_value variant Currently, they use text for old_value and new_value, but this is, of course, not very satisfactory. Just out of curiosity,

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Merlin Moncure
On Wed, May 4, 2011 at 12:36 PM, Tom Lane wrote: > Alvaro Herrera writes: >> A customer came to us with this request: a way to store "any" data in a >> column.  We've gone back and forth trying to determine reasonable >> implementation restrictions, safety and useful semantics for them. > > Yes,

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Darren Duncan
Alvaro Herrera wrote: A customer came to us with this request: a way to store "any" data in a column. We've gone back and forth trying to determine reasonable implementation restrictions, safety and useful semantics for them. I note that this has been requested in the past: http://archives.postg

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Tom Lane
Alvaro Herrera writes: > A customer came to us with this request: a way to store "any" data in a > column. We've gone back and forth trying to determine reasonable > implementation restrictions, safety and useful semantics for them. Yes, it seems rather messy. > The main idea is to be able to s

Re: [HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Kevin Grittner
Alvaro Herrera 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

[HACKERS] VARIANT / ANYTYPE datatype

2011-05-04 Thread Alvaro Herrera
Hello, A customer came to us with this request: a way to store "any" data in a column. We've gone back and forth trying to determine reasonable implementation restrictions, safety and useful semantics for them. I note that this has been requested in the past: http://archives.postgresql.org/pgsql-