Re: [GENERAL] connectby for BYTEA keys - Mailing list pgsql-patches
From | Joe Conway |
---|---|
Subject | Re: [GENERAL] connectby for BYTEA keys |
Date | |
Msg-id | 40395641.10403@joeconway.com Whole thread Raw |
List | pgsql-patches |
David Garamond wrote: > Joe Conway wrote: >> --with attached patch >> regression=# SELECT * FROM connectby('connectby_bytea', 'keyid', >> 'parent_keyid', 'row\\134', 0, '') AS t(keyid bytea, parent_keyid >> bytea, level int, branch text); > > Thanks for the fix. > I plan to apply this to 7.3 & 7.4 stable as well as the HEAD branch. If there are no objections, I'll apply in about 24 hours. Thanks, Joe Index: contrib/tablefunc/tablefunc.c =================================================================== RCS file: /cvsroot/pgsql-server/contrib/tablefunc/tablefunc.c,v retrieving revision 1.25 diff -c -r1.25 tablefunc.c *** contrib/tablefunc/tablefunc.c 2 Oct 2003 03:51:40 -0000 1.25 --- contrib/tablefunc/tablefunc.c 8 Feb 2004 15:36:29 -0000 *************** *** 79,84 **** --- 79,85 ---- MemoryContext per_query_ctx, AttInMetadata *attinmeta, Tuplestorestate *tupstore); + static char *quote_literal_cstr(char *rawstr); typedef struct { *************** *** 1319,1341 **** /* Build initial sql statement */ if (!show_serial) { ! appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = '%s' AND %s IS NOT NULL AND %s <> %s", key_fld, parent_key_fld, relname, parent_key_fld, ! start_with, key_fld, key_fld, parent_key_fld); serial_column = 0; } else { ! appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = '%s' AND %s IS NOT NULL AND %s <> %s ORDER BY %s", key_fld, parent_key_fld, relname, parent_key_fld, ! start_with, key_fld, key_fld, parent_key_fld, orderby_fld); serial_column = 1; --- 1320,1342 ---- /* Build initial sql statement */ if (!show_serial) { ! appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s", key_fld, parent_key_fld, relname, parent_key_fld, ! quote_literal_cstr(start_with), key_fld, key_fld, parent_key_fld); serial_column = 0; } else { ! appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s ORDER BY %s", key_fld, parent_key_fld, relname, parent_key_fld, ! quote_literal_cstr(start_with), key_fld, key_fld, parent_key_fld, orderby_fld); serial_column = 1; *************** *** 1690,1693 **** --- 1691,1712 ---- } return tupdesc; + } + + /* + * Return a properly quoted literal value. + * Uses quote_literal in quote.c + */ + static char * + quote_literal_cstr(char *rawstr) + { + text *rawstr_text; + text *result_text; + char *result; + + rawstr_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(rawstr))); + result_text = DatumGetTextP(DirectFunctionCall1(quote_literal, PointerGetDatum(rawstr_text))); + result = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(result_text))); + + return result; }
pgsql-patches by date: