Thread: Opaque data type
I'm a bit confused by the "opaque" data type. I've searched the archives and have seen the data type used as both input to triggers and as output from triggers. At first I thought it meant "nothing" but after seeing trigger definitions that use multiple instances of the opaque data type as input, it seems to me that it means something like "something, but I don't know what just now". Could someone clarify the concept that underlies the opaque data type? Thanks. -- John Burski I.T. Manager and Systems Administration 911EP First in LEDs... The solid state warning light leader. 25 Sixth Avenue North Saint Cloud, MN 56303 1-800-863-6911
John Burski <john.burski@911ep.com> writes: > Could someone clarify the concept that underlies the opaque data type? It *is* confusing, because OPAQUE is actually used for several distinct purposes. If you look in the pg-hackers mail list archives, you'll find discussions (as yet unimplemented) to replace OPAQUE by several pseudo-types that have crisper meanings. Offhand I can recall these uses: * Sometimes OPAQUE means "this function doesn't return anything at all", similarly to "returns void" in C and some other languages. * Sometimes OPAQUE means "this value can be any datatype at all" (eg, input of the count() aggregate). * Sometimes OPAQUE means "I know exactly what this should be, but it's an internal datatype with no SQL-level equivalent". This is usually what's at stake with a trigger function. * Sometimes OPAQUE means "I know exactly what this should be, but I haven't declared it yet" (ie, a forward reference). This is needed to declare I/O functions of user-defined types, since the system requires the functions to already exist when the type is declared. Confused yet? Basically, OPAQUE has been used as an easy out in rather more places than it should have been :-(. Someday we'll clean this up. regards, tom lane
Actually, that cleared things up quite a bit. While it may be a bit confusing, I'm no longer standing on the "ignorant" square. Thanks! Tom Lane wrote: > John Burski <john.burski@911ep.com> writes: > > Could someone clarify the concept that underlies the opaque data type? > > It *is* confusing, because OPAQUE is actually used for several distinct > purposes. If you look in the pg-hackers mail list archives, you'll find > discussions (as yet unimplemented) to replace OPAQUE by several > pseudo-types that have crisper meanings. > > Offhand I can recall these uses: > > * Sometimes OPAQUE means "this function doesn't return anything at all", > similarly to "returns void" in C and some other languages. > > * Sometimes OPAQUE means "this value can be any datatype at all" (eg, > input of the count() aggregate). > > * Sometimes OPAQUE means "I know exactly what this should be, but it's > an internal datatype with no SQL-level equivalent". This is usually > what's at stake with a trigger function. > > * Sometimes OPAQUE means "I know exactly what this should be, but I > haven't declared it yet" (ie, a forward reference). This is needed > to declare I/O functions of user-defined types, since the system > requires the functions to already exist when the type is declared. > > Confused yet? Basically, OPAQUE has been used as an easy out in rather > more places than it should have been :-(. Someday we'll clean this up. > > regards, tom lane -- John Burski I.T. Manager and Systems Administration 911EP First in LEDs... The solid state warning light leader. 25 Sixth Avenue North Saint Cloud, MN 56303 1-800-863-6911