User-defined type -- error handling

User-defined type -- error handling

Post by Don » Tue, 14 Feb 2012 03:29:07



Hi,

I have a few types that aren't economically supported in
PostgreSQL that I'll be implementing as "user-defined
types" (NOT "composite types").  Some of this is to
enforce particular semantics (that PG doesn't currently
support in the data model most appropriate to the
application domain).  But there are also efficiency
issues (caching "expensive" characteristics *in* the
object itself).

I like to code defensively.  Lots of invariants in the
code, etc.  I.e., if it *CAN'T HAPPEN*, then I can
explicitly enforce that:
      ASSERT(cant_happen, "The impossible HAS happened!")

Of course, I can't bring PostgreSQL to its knees if something
like this *does* happen (an indication of a bug *somewhere*,
no doubt -- in the type itself, the implementation, the data
model, constraints, etc.).

So, I'm trying to figure out what error to throw and how
PG will react in that event (i.e., just abort the transaction?)

[Note that such errors can be thrown by any of the code that
accesses/implements/modifies the type's representation.
So, they can appear in updates, queries, etc.]

Thanks!
--don

 
 
 

User-defined type -- error handling

Post by Jasen Bett » Tue, 14 Feb 2012 18:20:19



Quote:> Hi,
> So, I'm trying to figure out what error to throw and how
> PG will react in that event (i.e., just abort the transaction?)

22000 looks like good starting place unless one of the other 22xxx
errors fits better

http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html

yes, it will abort transaction much like "select 1/0;" does.

--
?? 100% natural



 
 
 

User-defined type -- error handling

Post by Don » Thu, 16 Feb 2012 12:53:45


Hi Jasen,



>> So, I'm trying to figure out what error to throw and how
>> PG will react in that event (i.e., just abort the transaction?)

> 22000 looks like good starting place unless one of the other 22xxx
> errors fits better

> http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html

> yes, it will abort transaction much like "select 1/0;" does.

I'm thinking of how I would be able to figure out *where*
this was biting me and how I could *fix* it, once bitten.

E.g., imagine having an assertion fail in the "out()" function.
You couldn't *see* the values that were giving those problems
(even if you could identify the rows that were involved).

I've got to stew on this a bit longer...

 
 
 

1. CREATE TYPE containing array of user-defined type elements

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there!

We're trying to create a user-defined type in PostgreSQL 8.2 containing an
array of an element whose type is another user-defined one. We're facing a
problem here, since when we try to do so:

CREATE TYPE newtype AS(
 x double precision,
 y double precision
);

CREATE TYPE newtype2(
 INPUT=array_in,
 OUTPUT=array_out,
 ELEMENT=newtype
);

PostgreSQL complains about non-existent array_out(newtype2). So, we felt
into this forum
http://osdir.com/ml/db.postgresql.novice/2003-07/msg00147.html and someone
suggested creating an alias to array_out because postgresql >= 7.3 is too
much strict about data types ot whatever.

Since we can't access as admin, we can't solve the problem like that. We
can't create an alias for array_out if we're not admins.

Please, we need some help. Thank you.

- --

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iQIVAwUBRxH8x6vCV+KC5A6ZAQJpKxAAgpeHCeDfy/jZ421zs/3tDhNBeQavF2h9
aLRdHV9kiXuB4+NL73tAiTPzqXs042MdDQxKmq3Bg2/WMkgwR2f04hEdWGN8a6hj
JtUKJY29i5BU2gfnfoep/yN6oyTN0qj6Vn2VRryx2cyAX4iA3KxIPpeJpTE9xMsX
S7KFuG+3AC4zSaFqlVt5bczbzm+wrWH4UPLho6FMsZTSo7TLruCWbApL4qRWlSrL
AgG6KFKuT1zNN82SVt6v29KTB80/YBfbHKoUqWn1dJPl/aqVDYH4HKZxR6fZyt2F
WRxPnXjtAAVzPkEJQyqtJpxLQlJ/t0XfGPJ0NZzHXrSnLSp0ms2MxsXn66qLAzXW
yYPF2fadDkh+0RB+mb2Sp6n7cCvRQjx0df56gQysQscYoEtV8drRGHzmoOwsIJaV
fTSmfrpwkkIlPHB314ERfXFJ6jno50vJBv3syP4jYvNlKonsM5PCp/UpvEZgBBh6
jhFzoNsP6zbqv5/GKYiBuo5TsfQWSo38K3l6rLtynvaNhpQ8PBnWwiityciSB2G9
N77NghXU87MbHSD6pCOgCbt5ykncaKtPRPuPp3EcQuvVal75M4ND7DRyNDQ6v74H
shpva7fz0w37Bgh65D+MofeaCK3kEwkReYQ4sdN/X400yCQcl97G41rbcMf/tj0u
LUzf5GRmxfw=
=mKq/
-----END PGP SIGNATURE-----

2. SAMBA: max number of files simultaneously opened

3. User-defined type send/recv vs. out/in

4. tabular inside tabular: how to allign columns horizontally?

5. ECPG and User-defined Types.

6. eliminating \date in \maketitle ?

7. Schema + User-Defined Data Type Indexing problems...

8. Problems Downloading Investment Data from Vanguard

9. User defined data types

10. ENUMs as user defined types?

11. user defined data types

12. Workaround or user defined type

13. How save user defined type in SQL2000 DataBase???