Re: [PATCHES] TODO Item - Return compressed length of TOAST datatypes
The next iteration - Hopefully I have got the idea basically right. I wonder if I have done the am I a varlena the long way.., pls advise if so! Cheers Mark Tom Lane wrote: My recollection of that discussion is that we just wanted something that would return the actual VARSIZE() of the datum. You're building something way too confusing ... A more interesting point is that the way you've declared the function, it will only work on text values, which is pretty limiting. Ideally we'd define this thing as pg_datum_length(any-varlena-type) returns int but there is no pseudotype corresponding to any varlena type. I was thinking about this the other day in connection with my proposal to make something that could return the TOAST value OID of an out-of-line datum. I think the only non-restrictive way to do it would be to declare the function as taking any, and then add a runtime check using the get_fn_expr_argtype() mechanism to test that what you've been given is in fact a varlena datatype. diff -Nacr ./src/backend/access/heap/tuptoaster.c.orig ./src/backend/access/heap/tuptoaster.c *** ./src/backend/access/heap/tuptoaster.c.orig Mon Mar 21 13:23:58 2005 --- ./src/backend/access/heap/tuptoaster.c Sun Jun 19 14:24:43 2005 *** *** 1436,1438 --- 1436,1482 return result; } + + /* -- + * toast_datum_size + * + *Show the (possibly compressed) size of a datum + * -- + */ + Size + toast_datum_size(Datum value) + { + + varattrib *attr = (varattrib *) DatumGetPointer(value); + Sizeresult; + + if (VARATT_IS_EXTERNAL(attr)) + { + /* +* Attribute is stored externally - If it is compressed too, +* then we need to get the external datum and calculate its size, +* otherwise we just use the external rawsize. +*/ + if (VARATT_IS_COMPRESSED(attr)) + { + varattrib *attrext = toast_fetch_datum(attr); + result = VARSIZE(attrext); + pfree(attrext); + } + else + { + result = attr-va_content.va_external.va_rawsize; + } + } + else + { + /* +* Attribute is stored inline either compressed or not, just +* calculate the size of the datum in either case. +*/ + result = VARSIZE(attr); + } + + return result; + + } diff -Nacr ./src/backend/utils/adt/Makefile.orig ./src/backend/utils/adt/Makefile *** ./src/backend/utils/adt/Makefile.orig Fri Apr 2 09:28:45 2004 --- ./src/backend/utils/adt/MakefileFri Jun 17 17:52:09 2005 *** *** 24,30 tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \ network.o mac.o inet_net_ntop.o inet_net_pton.o \ ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \ ! ascii.o quote.o pgstatfuncs.o encode.o like.o: like.c like_match.c --- 24,30 tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \ network.o mac.o inet_net_ntop.o inet_net_pton.o \ ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \ ! ascii.o quote.o pgstatfuncs.o encode.o toastfuncs.o like.o: like.c like_match.c diff -Nacr ./src/backend/utils/adt/toastfuncs.c.orig ./src/backend/utils/adt/toastfuncs.c *** ./src/backend/utils/adt/toastfuncs.c.orig Fri Jun 17 17:52:09 2005 --- ./src/backend/utils/adt/toastfuncs.cSun Jun 19 17:35:26 2005 *** *** 0 --- 1,74 + /*- + * + * toastfuncs.c + * Functions for accessing information about toasted data. + * + * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * $PostgreSQL$ + * + *- + */ + + #include postgres.h + #include fmgr.h + + #include catalog/pg_type.h + #include access/xact.h + #include access/tuptoaster.h + #include utils/builtins.h + #include utils/syscache.h + + Datum + pg_datum_length(PG_FUNCTION_ARGS) + { + + Datum value = PG_GETARG_DATUM(0); + int size; + + + if (fcinfo-flinfo-fn_extra == NULL) + { + /* +* On the first call check lookup the datatype of the supplied argument +* and check if is a varlena . +*/ + Oid argtypeid = get_fn_expr_argtype(fcinfo-flinfo, 0); + HeapTuple tp; + int typlen; +
Re: [PATCHES] win32/MSVC fix for libpq
OK, applied. I had to use \# in: echo \#define SYSCONFDIR pg_config_paths.h so that bcc wouldn't consider the # to be a comment, but it seems MSVC doesn't have that issue, and in fact has a problem with it. I modified the psql/win32.mak too to remove the \# and use just #. --- Andreas Pflug wrote: The attached fix reenables libpq compilation with MSVC6. Regards, Andreas Index: fe-connect.c === RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.311 diff -u -r1.311 fe-connect.c --- fe-connect.c 12 Jun 2005 00:07:07 - 1.311 +++ fe-connect.c 19 Jun 2005 09:47:18 - @@ -3104,6 +3104,8 @@ if (stat(pgpassfile, stat_buf) == -1) return NULL; +#ifndef WIN32 + if (!S_ISREG(stat_buf.st_mode)) { fprintf(stderr, @@ -3113,7 +3115,6 @@ return NULL; } -#ifndef WIN32 /* If password file is insecure, alert the user and ignore it. */ if (stat_buf.st_mode (S_IRWXG | S_IRWXO)) { Index: win32.mak === RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/win32.mak,v retrieving revision 1.34 diff -u -r1.34 win32.mak --- win32.mak 29 Apr 2005 13:42:21 - 1.34 +++ win32.mak 19 Jun 2005 10:19:06 - @@ -115,7 +115,7 @@ copy pthread.h.win32 pthread.h pg_config_paths.h: win32.mak - echo \#define SYSCONFDIR pg_config_paths.h + echo #define SYSCONFDIR pg_config_paths.h $(OUTDIR) : if not exist $(OUTDIR)/$(NULL) mkdir $(OUTDIR) @@ -215,5 +215,8 @@ $(CPP_PROJ) /I. ..\..\backend\utils\mb\encnames.c +.c{$(CPP_OBJS)}.obj: + $(CPP) $(CPP_PROJ) $ + .c.obj: $(CPP) $(CPP_PROJ) $ ---(end of broadcast)--- TIP 8: explain analyze is your friend -- Bruce Momjian| http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] Python setof patch
On Wed, Jun 15, 2005 at 03:03:46PM +0200, Gerrit van Dyk wrote: My next project I am working in is to get the PL/Python module to return records (ie. structured data) Hmmm...if you're interested in working on PL/Python, then you might mosey over to pgsql-hackers and see the process crash when a plpython function returns unicode thread: http://archives.postgresql.org/pgsql-hackers/2005-06/msg00806.php I was going to submit a simple patch to fix the immediate problem, calling ereport(ERROR, ...) if PyObject_Str() returned NULL. I haven't decided on an error message yet, not being sure if I should hard-code something generic or if there's a way to get a more specific error message from Python. Tino Wildenhain followed up with a suggestion to improve PL/Python's Unicode support. Is that anything you'd be interested in working on? If so then please reply to the thread in pgsql-hackers to keep the discussion in one place (I already moved it to -hackers from -bugs because the former seemed more a appropriate place for extended discussion). -- Michael Fuhr http://www.fuhr.org/~mfuhr/ ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send unregister YourEmailAddressHere to [EMAIL PROTECTED])
[PATCHES] code cleanup for tz
This patch makes various cosmetic improvements to the timezone code: remove the use of the register qualifier, make some function declaration syntax a bit more consistent, etc. I'll apply this later today, barring any objections. -Neil Index: src/timezone/ialloc.c === RCS file: /var/lib/cvs/pgsql/src/timezone/ialloc.c,v retrieving revision 1.5 diff -c -r1.5 ialloc.c *** src/timezone/ialloc.c 21 May 2004 20:59:10 - 1.5 --- src/timezone/ialloc.c 20 Jun 2005 05:25:30 - *** *** 38,46 char * icatalloc(char *old, const char *new) { ! register char *result; ! register int oldsize, ! newsize; newsize = (new == NULL) ? 0 : strlen(new); if (old == NULL) --- 38,46 char * icatalloc(char *old, const char *new) { ! char *result; ! int oldsize, ! newsize; newsize = (new == NULL) ? 0 : strlen(new); if (old == NULL) Index: src/timezone/localtime.c === RCS file: /var/lib/cvs/pgsql/src/timezone/localtime.c,v retrieving revision 1.10 diff -c -r1.10 localtime.c *** src/timezone/localtime.c 19 Apr 2005 03:13:59 - 1.10 --- src/timezone/localtime.c 20 Jun 2005 05:28:27 - *** *** 81,95 static const char *getnum(const char *strp, int *nump, int min, int max); static const char *getsecs(const char *strp, long *secsp); static const char *getoffset(const char *strp, long *offsetp); ! static const char *getrule(const char *strp, struct rule * rulep); ! static void gmtload(struct state * sp); ! static void gmtsub(const pg_time_t *timep, long offset, struct pg_tm * tmp); ! static void localsub(const pg_time_t *timep, long offset, struct pg_tm * tmp, const pg_tz *tz); static void timesub(const pg_time_t *timep, long offset, ! const struct state * sp, struct pg_tm * tmp); static pg_time_t transtime(pg_time_t janfirst, int year, ! const struct rule * rulep, long offset); ! int tzparse(const char *name, struct state * sp, int lastditch); /* GMT timezone */ static struct state gmtmem; --- 81,95 static const char *getnum(const char *strp, int *nump, int min, int max); static const char *getsecs(const char *strp, long *secsp); static const char *getoffset(const char *strp, long *offsetp); ! static const char *getrule(const char *strp, struct rule *rulep); ! static void gmtload(struct state *sp); ! static void gmtsub(const pg_time_t *timep, long offset, struct pg_tm *tmp); ! static void localsub(const pg_time_t *timep, long offset, struct pg_tm *tmp, const pg_tz *tz); static void timesub(const pg_time_t *timep, long offset, ! const struct state *sp, struct pg_tm *tmp); static pg_time_t transtime(pg_time_t janfirst, int year, ! const struct rule *rulep, long offset); ! int tzparse(const char *name, struct state *sp, int lastditch); /* GMT timezone */ static struct state gmtmem; *** *** 113,120 static long detzcode(const char *codep) { ! register long result; ! register int i; result = (codep[0] 0x80) ? ~0L : 0L; for (i = 0; i 4; ++i) --- 113,120 static long detzcode(const char *codep) { ! long result; ! int i; result = (codep[0] 0x80) ? ~0L : 0L; for (i = 0; i 4; ++i) *** *** 123,138 } int ! tzload(register const char *name, register struct state * sp) { ! register const char *p; ! register int i; ! register int fid; if (name == NULL (name = TZDEFAULT) == NULL) return -1; { ! register int doaccess; char fullname[MAXPGPATH]; if (name[0] == ':') --- 123,138 } int ! tzload(const char *name, struct state *sp) { ! const char *p; ! int i; ! int fid; if (name == NULL (name = TZDEFAULT) == NULL) return -1; { ! int doaccess; char fullname[MAXPGPATH]; if (name[0] == ':') *** *** 209,215 } for (i = 0; i sp-typecnt; ++i) { ! register struct ttinfo *ttisp; ttisp = sp-ttis[i]; ttisp-tt_gmtoff = detzcode(p); --- 209,215 } for (i = 0; i sp-typecnt; ++i) { ! struct ttinfo *ttisp; ttisp = sp-ttis[i]; ttisp-tt_gmtoff = detzcode(p); *** *** 227,233 sp-chars[i] = '\0'; /* ensure '\0' at end */ for (i = 0; i sp-leapcnt; ++i) { ! register struct lsinfo *lsisp; lsisp = sp-lsis[i]; lsisp-ls_trans = detzcode(p); --- 227,233 sp-chars[i] = '\0'; /* ensure '\0' at end */ for (i = 0; i sp-leapcnt; ++i) { ! struct lsinfo *lsisp; lsisp = sp-lsis[i]; lsisp-ls_trans = detzcode(p); *** *** 237,243 } for (i = 0; i sp-typecnt; ++i) { ! register struct ttinfo *ttisp; ttisp = sp-ttis[i]; if (ttisstdcnt == 0) --- 237,243 } for (i = 0; i sp-typecnt; ++i) { ! struct ttinfo *ttisp; ttisp = sp-ttis[i]; if