github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/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 non user 20 // defined types/functions. OIDs for user defined types/functions will start at 21 // CockroachPrefixedOIDMax and increase as new types are created. User defined 22 // type/function descriptors have a cluster-wide unique stable ID. 23 // CockroachPredefinedOIDMax defines the mapping from this stable ID to a 24 // type/function OID. In particular, stable ID + CockroachPredefinedOIDMax = 25 // type OID. types.StableTypeIDToOID and types.UserDefinedTypeOIDToID should be 26 // used when converting between stable ID's and type/function 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 T_box2d = oid.Oid(90004) 36 T__box2d = oid.Oid(90005) 37 ) 38 39 // ExtensionTypeName returns a mapping from extension oids 40 // to their type name. 41 var ExtensionTypeName = map[oid.Oid]string{ 42 T_geometry: "GEOMETRY", 43 T__geometry: "_GEOMETRY", 44 T_geography: "GEOGRAPHY", 45 T__geography: "_GEOGRAPHY", 46 T_box2d: "BOX2D", 47 T__box2d: "_BOX2D", 48 } 49 50 // TypeName checks the name for a given type by first looking up oid.TypeName 51 // before falling back to looking at the oid extension ExtensionTypeName. 52 func TypeName(o oid.Oid) (string, bool) { 53 name, ok := oid.TypeName[o] 54 if ok { 55 return name, ok 56 } 57 name, ok = ExtensionTypeName[o] 58 return name, ok 59 }