PQregisterUserDefinedTypes(3)

πŸ“¦ version 1.5.1, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– PQregisterUserDefinedTypes(3) πŸ’–

okay bestie, so this one is a page from the libpqtypes Manual and it's about registering your very own custom types. let's get into it ✨


🌸 NAME 🌸

PQregisterUserDefinedTypes β€” registers a user-defined types. yes, that's the actual name, and yes, it's the one that makes your custom backend types play nice with libpqtypes πŸ’…


✨ SYNOPSIS ✨

#include <libpqtypes.h>

int PQregisterUserDefinedTypes(PGconn *conn, PGregisterType *types,
                               int count);

πŸ’€ DEPRECATED πŸ’€

okay so, THIS FUNCTION IS DEPRECATED. like, officially. if you're starting something new, bestie, you should be using PQregisterTypes instead. the way that this one is literally just a wrapper around PQregisterTypes now... it's giving legacy code energy πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

so PQregisterUserDefinedTypes() is the function that lets your app register one or more user-defined types at runtime. and what even is a user-defined type, you ask? it's a custom type over in the backend that implements its own C procedures for in/out/send/recv. very main character of it tbh πŸ‘‘

okay important thing: this function must execute a query against the backend to go fetch the type information for each user-defined type. so do not call this from within a transaction. and also, the more types you register in one go, the better β€” register multiple types at the same time to avoid round trip overhead. one trip, many types, that's the vibe πŸŽ€

so the types argument is an array containing count user-defined types to register. if any type does not exist, the register is aborted β€” no partial slay, it's all or nothing. and either typput and/or typget must be specified for each type in the types array. no exceptions, no cap.

NOTE: the typname member of the PGregisterType structure can optionally contain the type's schema, written like schema.typname 🌈
WARNING: PQparamCreate is only aware of types that have already been registered. so if you need to put a type into a param, make sure it is first registered. register first, param later, that's the order, periodt πŸ’…

🌟 User-defined Types Registration 🌟

here's an example that registers two user-defined types:

PGregisterType types[] = {
     {"graphics.rgb", rgb_put, rgb_get},
     {"graphics.digon", digon_put, digon_get}
};

if (!PQregisterUserDefinedTypes(conn, types, 2))
     fprintf(stderr, "PQregisterUserDefinedTypes: %s\n", PQgeterror());

look at that. two types. one call. iconic πŸ”₯


🫢 RETURN VALUE 🫢

  • on success, a non-zero value is returned ✨
  • on error, zero is returned, and PQgeterror(3) will contain an error message. so if you get a zero, go check PQgeterror(3), she'll tell you what went wrong 😭

🌈 EXAMPLES 🌈

None.

(not me giving you literally nothing here. the manpage said None and I'm being honest about it πŸ™ˆ)


πŸ‘‘ AUTHOR πŸ‘‘

a contribution of eSilo, LLC. for the PostgreSQL Database Management System. written by Andrew Chernow and Merlin Moncure. absolute legends, fr fr πŸ’œ


πŸ“ REPORTING BUGS πŸ“

found a bug? report it to <libpqtypes@esilo.com>. they wanna hear about it, bestie πŸ›


Copyright (c) 2011 eSilo, LLC. All rights reserved.

this is free software; see the source for copying conditions. and listen β€” there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. so like, no promises, babes πŸ’€


🌸 SEE ALSO 🌸


and that's the whole page, bestie πŸ’– this was libpqtypes, dated 2011, and we did it for PQregisterUserDefinedTypes(3). mwah, go register something cute πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from