Skip to main content
deleted 729 characters in body
Source Link
Russell Fulton
  • 3k
  • 3
  • 31
  • 56

I have this expression in the field calculator:

case
  when ident ~ '^B\\d+/\\d+' then regexp_replace(ident, '^B(\\d+)/(\\d+)', 'Hb' || rpad('\\1', 3, '0') || rpad('\\2', 3, '0'))
  when ident ~ '^\\w\\w' then regexp_replace(ident, '^(\\w+)/?(\\d+)','H' || lpad('\\1', 3, '_') || rpad('\\2' , 3, 0))
end

theregexp_replace('1', '^(\\d+)', rpad('\\1', 3, '0') ) gives pad01 functions appear to be behaving erratically, here are a bunch of inputs and outputs:

"WV6"   "HWV_06"
"B4/2"  "Hb0402"
"B3/10" "Hb03010"
"LWV1"  "HLWV_01"

Note that the padding is inconsistent in a number of different ways! In the case of the zero padding the padding is one character lessrather than specified, except when the original string is two characters and then we get the001 as expected number. with the '' padding I get the correct behaviour when there are two chars in the source but when there are three it still add an '' when it should not.

The behaviour is systematicthe *pad functions work fine when called outside regexp_replace

Weird! This has to be a bug? or am I missing something?

If it is a bug I'll log something in the issue tracker.

BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace! kudos to the QGIS developers!

I have this expression in the field calculator:

case
  when ident ~ '^B\\d+/\\d+' then regexp_replace(ident, '^B(\\d+)/(\\d+)', 'Hb' || rpad('\\1', 3, '0') || rpad('\\2', 3, '0'))
  when ident ~ '^\\w\\w' then regexp_replace(ident, '^(\\w+)/?(\\d+)','H' || lpad('\\1', 3, '_') || rpad('\\2' , 3, 0))
end

the pad functions appear to be behaving erratically, here are a bunch of inputs and outputs:

"WV6"   "HWV_06"
"B4/2"  "Hb0402"
"B3/10" "Hb03010"
"LWV1"  "HLWV_01"

Note that the padding is inconsistent in a number of different ways! In the case of the zero padding the padding is one character less than specified, except when the original string is two characters and then we get the expected number. with the '' padding I get the correct behaviour when there are two chars in the source but when there are three it still add an '' when it should not.

The behaviour is systematic

Weird! This has to be a bug? or am I missing something?

If it is a bug I'll log something in the issue tracker.

BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace! kudos to the QGIS developers!

I have this expression in the field calculator:

regexp_replace('1', '^(\\d+)', rpad('\\1', 3, '0') ) gives 01 rather than 001 as expected.

the *pad functions work fine when called outside regexp_replace

Weird! This has to be a bug? or am I missing something?

If it is a bug I'll log something in the issue tracker.

BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace! kudos to the QGIS developers!

Tweeted twitter.com/#!/StackGIS/status/424937019799003136
Turned title into a question
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Is this a Do pad functions of QGIS Field Calculator have bug in field calculator?

added 753 characters in body
Source Link
Russell Fulton
  • 3k
  • 3
  • 31
  • 56

I have this expression in the field calculator:

case
  when ident ~ '^B\\d+/\\d+' then regexp_replace(ident, '^B(\\d+)/(\\d+)', 'Hb' || rpad('\\1', 3, '0') || rpad('\\2', 3, '0'))
  when ident ~ '^\\w\\w' then regexp_replace(ident, '^(\\w+)/?(\\d+)','H' || lpad('\\1', 3, '_') || rpad('\\2' , 3, 0))
end

the regexp_replace('2', '(\\d+)', rpad('\\1',3,'0') )pad functions appear to be behaving erratically, here are a bunch of inputs and outputs:

"WV6"   "HWV_06"
"B4/2"  "Hb0402"
"B3/10" "Hb03010"
"LWV1"  "HLWV_01"

which yields '02' ratherNote that the padding is inconsistent in a number of different ways! In the case of the zero padding the padding is one character less than '002' asspecified, except when the original string is two characters and then we get the expected number. with the '' padding I get the correct behaviour when there are two chars in the source but when there are three it still add an '' when it should not.

OTOH rpad('1', 3, '0') yields '001' as expected.The behaviour is systematic

Weird! Is this This has to be a bug? or am I missing something? If so

If it is a bug I'll log something in the issue tracker.

BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace! kudos to the QGIS developers!`

I have this expression in the field calculator:

regexp_replace('2', '(\\d+)', rpad('\\1',3,'0') )

which yields '02' rather than '002' as expected

OTOH rpad('1', 3, '0') yields '001' as expected.

Weird! Is this a bug? or am I missing something? If so I'll log something in the issue tracker.

BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace! kudos to the QGIS developers!`

I have this expression in the field calculator:

case
  when ident ~ '^B\\d+/\\d+' then regexp_replace(ident, '^B(\\d+)/(\\d+)', 'Hb' || rpad('\\1', 3, '0') || rpad('\\2', 3, '0'))
  when ident ~ '^\\w\\w' then regexp_replace(ident, '^(\\w+)/?(\\d+)','H' || lpad('\\1', 3, '_') || rpad('\\2' , 3, 0))
end

the pad functions appear to be behaving erratically, here are a bunch of inputs and outputs:

"WV6"   "HWV_06"
"B4/2"  "Hb0402"
"B3/10" "Hb03010"
"LWV1"  "HLWV_01"

Note that the padding is inconsistent in a number of different ways! In the case of the zero padding the padding is one character less than specified, except when the original string is two characters and then we get the expected number. with the '' padding I get the correct behaviour when there are two chars in the source but when there are three it still add an '' when it should not.

The behaviour is systematic

Weird! This has to be a bug? or am I missing something?

If it is a bug I'll log something in the issue tracker.

BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace! kudos to the QGIS developers!

Source Link
Russell Fulton
  • 3k
  • 3
  • 31
  • 56
Loading