Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 873959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:01:40+00:00 2026-05-15T11:01:40+00:00

I have function CREATE OR REPLACE FUNCTION public.GetSoilCod ( cod1 integer = 0, cod2

  • 0

I have function

CREATE OR REPLACE FUNCTION "public"."GetSoilCod" ( 
  "cod1" integer = 0, 
  "cod2" integer = 0, 
  "cod3" integer = 0, 
  "cod4" integer = 0, 
  "cod5" integer = 0, 
  "cod6" integer = 0, 
  "cod7" integer = 0 
) 
RETURNS varchar AS 
$body$ 
declare result varchar; 
BEGIN 
  result = cast($1 as varchar(2)) || '.' || 
                cast($2 as varchar(2)) || '.' || 
                cast($3 as varchar(2)) || '.' || 
                cast($4 as varchar(2)) || '.' || 
                cast($5 as varchar(2)) || '.' || 
                cast($6 as varchar(2)) || '.' || 
                cast($7 as varchar(2)); 
  return trim('.0' from result); 
END; 
$body$ 
LANGUAGE 'plpgsql' 
VOLATILE 
CALLED ON NULL INPUT 
SECURITY INVOKER 
COST 100; 

When I execute this function and one or more of code is divided to 10, result of this function is wrong.

Examples:

SELECT * FROM "public"."GetSoilCod"(10, 0, 0, 0, 0, 0, 0); 
return: 1 
expected: 10 


SELECT * FROM "public"."GetSoilCod"(10, 20, 0, 0, 0, 0, 0); 
return: 10.2 
expected: 10.20 

Why is trimed last 0(zero)? I want to trim only “.0” (dot zero)

If I execute this query:

SELECT * FROM "public"."GetSoilCod"(10, 20, 0, 0, 0, 0, 1); 
all its OK 
return & expected is: 10.20.0.0.0.0.1 

or:

SELECT * FROM "public"."GetSoilCod"(10, 20, 0, 0, 0, 1, 0); 

all is OK . Return & expected is: 10.20.0.0.0.1

Where is my mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:01:41+00:00Added an answer on May 15, 2026 at 11:01 am

    Trim doesn’t treat the argument as a single string to remove, it treats it as an unordered list of characters all of which must be removed regardless of the order in which they appear from the beginning, end or both.

    The call trim('.0' from result); is the same as trim('0.' from result); and both cause the removal of all 0 and . from the end of the string.

    SELECT trim('0.' from '100.00')
    '1'
    

    Try using regexp_replace instead:

    SELECT regexp_replace('100.0.2.0.0.0', '(\\.0)+$', '')
    100.0.2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS
I have the following PostgreSQL script: CREATE OR REPLACE FUNCTION merge_fields() RETURNS VOID AS
I have this function: CREATE OR REPLACE FUNCTION CREATE_AIRSPACE_AVAILABILITY_RECORD (cur_user VARCHAR, start_time VARCHAR, start_date
I have a stored function CREATE OR REPLACE FUNCTION schedule(name in varchar2,pass in varchar2
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
I have function like this : CREATE OR REPLACE FUNCTION f_insert_account(usernames character varying, passwds
I have this function to create a request to another file to update the
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex
I have a function to create a pdf which should return bitarray. Below is
I have a function: def create(sender, **kw): [...] Which should be called when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.