3

Here, I have a problem in the value from trim() function in PostgreSQL:

Ruby code:

    if(this.modelName=="ClientOffice")
       {    this.params="model_name="+this.modelName+"&action_name="+this.actionName+"&
find_condition=btrim(clients_corporate_billings.id,' ') %3D 
btrim('"+validString('populateValue0','text')+"',' ')
  & object_id="+this.objectId;
      }

 &action_name="+this.actionName+"
    &find_condition=btrim(clients_corporate_billings.id,' ') %3D
     btrim('"+validString('populateValue0','text')+"',' ')

In above code, btrim is function of PostgreSQL for trimming but it gives/produce error.

Muhammad Waheed
  • 1,048
  • 1
  • 13
  • 30
Rubyist
  • 6,486
  • 10
  • 51
  • 86
  • Error :: PGError: ERROR: function pg_catalog.btrim(integer, unknown) does not exist LINE 1: ...ient_offices".clients_corporate_billing_id WHERE (trim(clien... – Rubyist Oct 05 '10 at 16:00
  • That's quite alright - I also can't find a function "btrim" with a first parameter of type integer. You have to cast or convert the first argument to text. – Milen A. Radev Oct 05 '10 at 16:13

1 Answers1

6

From the documentation.

Function: btrim(string text [, characters text])
Return Type: text
Description: Remove the longest string consisting only of characters in characters (a space by default) from the start and end of string
Example: btrim('xyxtrimyyx', 'xy')
Result: trim


So you need to cast as text:

&find_condition=btrim(clients_corporate_billings.id::text,' ') %3D

vol7ron
  • 40,809
  • 21
  • 119
  • 172
  • 2
    Glad we could help. PostgreSQL errors are pretty descriptive. If there's ever a problem with a native function that you know exists, it's generally due to the arguments passed in. If you ever see a message regarding `typecast`, it gives you a big help in knowing what to look for. – vol7ron Oct 06 '10 at 23:34
  • hi @vol7ron can you plz help me, why does this `btrim('xyxtrimyyx', 'yzz')` display this `xyxtrimyyx` – ziMtyth Jan 07 '18 at 10:29
  • @ziMtyth it seems like you need to ask a new question and describe the full extent of your problem case, what you’re doing, and what you’ve tried – vol7ron Jan 07 '18 at 14:37
  • @vol7ron indeed, I did that and I got an answer thanks anyway =) – ziMtyth Jan 07 '18 at 14:51