Обсуждение: String trim function - possible bug?
I am seeing weirdness using the trim function on a string: This works as expected: SELECT 'dhct:bn', trim(leading 'dhct:' from 'dhct:bn'); ?column? | ltrim ----------+------- dhct:bn | bn (1 row) However it fails for these cases: SELECT 'dhct:dn', trim(leading 'dhct:' from 'dhct:dn'); ?column? | ltrim ----------+------- dhct:dn | n (1 row) SELECT 'dhct:cn', trim(leading 'dhct:' from 'dhct:cn'); ?column? | ltrim ----------+------- dhct:cn | n (1 row) The second case truncates an extra character (which is unwanted or unexpected). It fails for both 8.1.4 and 8.2.3. It seems if the first character after the 'dhct:' is a 'd' or a 'c' it truncates it as well. I have not tested every letter of the alphabet yet. Any suggestions? Thanks, Woody ---------------------------------------- iGLASS Networks 211-A S. Salem St Apex NC 27502 (919) 387-3550 x813 www.iglass.net
On Wed, Jun 06, 2007 at 12:21:33PM -0400, Woody Woodring wrote: > I am seeing weirdness using the trim function on a string: <snip> You are missunderstanding the trim function. > However it fails for these cases: > > SELECT 'dhct:dn', trim(leading 'dhct:' from 'dhct:dn'); > ?column? | ltrim > ----------+------- > dhct:dn | n > (1 row) The bit after the leading is the set of *characters* to be removed. Like so: # select trim( leading 'dhct:' from 'dhdhda'); ltrim ------- a (1 row) It's matching characters, not the exact string... Have a nice day, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > From each according to his ability. To each according to his ability to litigate.
Вложения
On Wed, 6 Jun 2007, Woody Woodring wrote: > I am seeing weirdness using the trim function on a string: > > This works as expected: > > SELECT 'dhct:bn', trim(leading 'dhct:' from 'dhct:bn'); > ?column? | ltrim > ----------+------- > dhct:bn | bn > (1 row) > > However it fails for these cases: > > SELECT 'dhct:dn', trim(leading 'dhct:' from 'dhct:dn'); > ?column? | ltrim > ----------+------- > dhct:dn | n > (1 row) The 8.2 docs give this as the description in the table: "Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string" That implies that with characters 'dhct:' the string to remove is 'dhct:d' because that's the longest leading string made up of those characters. Maybe a form using something like regexp_replace might work better for you.
My fault, I apologize. I did realize my mistake while I was at lunch but had responses before I could post to fix my error. I can use the "replace()" function instead. Thanks, Woody -----Original Message----- From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Stephan Szabo Sent: Wednesday, June 06, 2007 1:33 PM To: Woody Woodring Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] String trim function - possible bug? On Wed, 6 Jun 2007, Woody Woodring wrote: > I am seeing weirdness using the trim function on a string: > > This works as expected: > > SELECT 'dhct:bn', trim(leading 'dhct:' from 'dhct:bn'); ?column? | > ltrim > ----------+------- > dhct:bn | bn > (1 row) > > However it fails for these cases: > > SELECT 'dhct:dn', trim(leading 'dhct:' from 'dhct:dn'); ?column? | > ltrim > ----------+------- > dhct:dn | n > (1 row) The 8.2 docs give this as the description in the table: "Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string" That implies that with characters 'dhct:' the string to remove is 'dhct:d' because that's the longest leading string made up of those characters. Maybe a form using something like regexp_replace might work better for you. ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly