Get Object?
От | Alex Lau |
---|---|
Тема | Get Object? |
Дата | |
Msg-id | 3C8D78B1.4000303@dpcgroup.com обсуждение исходный текст |
Список | pgsql-hackers |
This is the c code section and sql section that I need for casting Object reference column If anyone know there is an internal one is already build, please let me know. If not I'm just wondering we can put that into the src. This will allow all object reference column to cast back as oid like they assigned to and build index on top like a reference key, so no schema needed anymore, pretty close to object relation :) Replace the "man" with your table name in the sql file will work :) e.g CREATE TABLE man ( firstname text ); ALTER TABLE man ADD son man; INSERT INTO man ( firstname ) VALUES ( 'alexbaby' ); INSERT 12345 1; INSERT INTO man ( firstname, son ) VALUES ( 'alex', 12345::man ); INSERT 12346 1; SELECT * FROM man WHERE son = (SELECT oid FROM man WHERE firstname='alexbaby'); -- find a man his son's also is a man and his name is alexbaby; or CREATE UNIQUE INDEX man_oid_unique_key ON man ( oid ); CREATE UNIQUE INDEX man_son_unique_key ON man ( firstname, son ); firstname | son ----------------- alex | 12345 :) I'm done on this part, I hope somebody in postgres still interested in building object functionality. Thanks Alex #include "postgres.h" /* general Postgres declarations */ #include "fmgr.h" /* for argument/result macros */ #include "executor/execdebug.h" #include "executor/executor.h" /* for GetAttributeByName() */ #include "utils/geo_decls.h" /* for point type */ /* These prototypes just prevent possible warnings from gcc. */ Datum castoid(PG_FUNCTION_ARGS); Datum castoidbyname(PG_FUNCTION_ARGS); Datum my_abs_lt(PG_FUNCTION_ARGS); Datum my_abs_le(PG_FUNCTION_ARGS); Datum my_abs_eq(PG_FUNCTION_ARGS); Datum my_abs_ge(PG_FUNCTION_ARGS); Datum my_abs_gt(PG_FUNCTION_ARGS); Datum my_abs_cmp(PG_FUNCTION_ARGS); /* Composite types */ PG_FUNCTION_INFO_V1(castoid); Datum castoid(PG_FUNCTION_ARGS) {TupleTableSlot *t = (TupleTableSlot *) PG_GETARG_POINTER(0);int32 slot = PG_GETARG_INT32(1);int32 myid; bool isnull;myid = DatumGetInt32(GetAttributeByNum(t, slot, &isnull));if (isnull) PG_RETURN_INT32(0); /* * Alternatively, we might prefer to do PG_RETURN_NULL() for null * salary */ PG_RETURN_INT32(myid); } PG_FUNCTION_INFO_V1(castoidbyname); Datum castoidbyname(PG_FUNCTION_ARGS) {TupleTableSlot *t = (TupleTableSlot *) PG_GETARG_POINTER(0);/*char *slot = PG_GETARG_CSTRING(1);*/text *slot = PG_GETARG_TEXT_P(1);int32 myid;bool isnull; /*printf( "cast -->%s<----", slot+VARHDRSZ );*/ myid = DatumGetInt32(GetAttributeByName(t, slot->vl_dat, &isnull));if(isnull) PG_RETURN_INT32(0); /* * Alternatively, we might prefer to do PG_RETURN_NULL() for null * salary */ PG_RETURN_INT32(myid); } PG_FUNCTION_INFO_V1(my_abs_lt); Datum my_abs_lt(PG_FUNCTION_ARGS) {int32 left = PG_GETARG_OID(0), right=PG_GETARG_OID(1); PG_RETURN_BOOL(left < right); } PG_FUNCTION_INFO_V1(my_abs_le); Datum my_abs_le(PG_FUNCTION_ARGS) {int32 left = PG_GETARG_OID(0), right=PG_GETARG_OID(1); PG_RETURN_BOOL(left <= right); } PG_FUNCTION_INFO_V1(my_abs_eq); Datum my_abs_eq(PG_FUNCTION_ARGS) {int32 left = PG_GETARG_OID(0), right=PG_GETARG_OID(1); PG_RETURN_BOOL(left==right); } PG_FUNCTION_INFO_V1(my_abs_ge); Datum my_abs_ge(PG_FUNCTION_ARGS) {int32 left = PG_GETARG_OID(0), right=PG_GETARG_OID(1); PG_RETURN_BOOL(left>=right); } PG_FUNCTION_INFO_V1(my_abs_gt); Datum my_abs_gt(PG_FUNCTION_ARGS) {int32 left = PG_GETARG_OID(0), right=PG_GETARG_OID(1); PG_RETURN_BOOL(left>right); } PG_FUNCTION_INFO_V1(my_abs_cmp); Datum my_abs_cmp(PG_FUNCTION_ARGS) {int32 left = PG_GETARG_OID(0), right=PG_GETARG_OID(1); if( left < right ) PG_RETURN_INT32(-1); else if ( left > right ) PG_RETURN_INT32(1); else PG_RETURN_INT32(0); }
В списке pgsql-hackers по дате отправления:
Предыдущее
От: "'Ben Grimm'"Дата:
Сообщение: Re: [BUGS] Bug #613: Sequence values fall back to previously chec
Следующее
От: "Serguei Mokhov"Дата:
Сообщение: FYI: Fw: [General] master thesis defence, Xin Shen, Wed. March 27, 16:00, H 601