github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/oidext/oidext.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 // Package oidext contains oids that are not in `github.com/lib/pq/oid` 12 // as they are not shipped by default with postgres. 13 // As CRDB does not support extensions, we'll need to automatically assign 14 // a few OIDs of our own. 15 package oidext 16 17 import "github.com/lib/pq/oid" 18 19 // CockroachPredefinedOIDMax defines the maximum OID allowed for use by 20 // non user defined types. OIDs for user defined types will start at 21 // CockroachPrefixedOIDMax and increase as new types are created. 22 // User defined type descriptors have a cluster-wide unique stable ID. 23 // CockroachPredefinedOIDMax defines the mapping from this stable ID to 24 // a type OID. In particular, stable ID + CockroachPredefinedOIDMax = type OID. 25 // types.StableTypeIDToOID and types.UserDefinedTypeOIDToID should be used when 26 // converting between stable ID's and type OIDs. 27 const CockroachPredefinedOIDMax = 100000 28 29 // OIDs in this block are extensions of postgres, thus having no official OID. 30 const ( 31 T_geometry = oid.Oid(90000) 32 T__geometry = oid.Oid(90001) 33 T_geography = oid.Oid(90002) 34 T__geography = oid.Oid(90003) 35 ) 36 37 // ExtensionTypeName returns a mapping from extension oids 38 // to their type name. 39 var ExtensionTypeName = map[oid.Oid]string{ 40 T_geometry: "GEOMETRY", 41 T__geometry: "_GEOMETRY", 42 T_geography: "GEOGRAPHY", 43 T__geography: "_GEOGRAPHY", 44 } 45 46 // TypeName checks the name for a given type by first looking up oid.TypeName 47 // before falling back to looking at the oid extension ExtensionTypeName. 48 func TypeName(o oid.Oid) (string, bool) { 49 name, ok := oid.TypeName[o] 50 if ok { 51 return name, ok 52 } 53 name, ok = ExtensionTypeName[o] 54 return name, ok 55 }