From: | M Sarwar <sarwarmd02(at)outlook(dot)com> |
---|---|
To: | Scott Ribe <scott_ribe(at)elevated-dev(dot)com>, "Wetmore, Matthew (CTR)" <Matthew(dot)Wetmore(at)express-scripts(dot)com> |
Cc: | mahesh <mahesha_dba(at)yahoo(dot)com>, Mohammed Aslam <hmdaslam97(at)gmail(dot)com>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Subject: | Re: The same result for with SPACE and without SPACE |
Date: | 2023-06-15 17:43:51 |
Message-ID: | DM4PR19MB5978B9FAA449068BF3201D20D35BA@DM4PR19MB5978.namprd19.prod.outlook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin pgsql-advocacy |
Hello Scott and all,
Here the question comes with respect to CHAR(10) to CHARACTeR VARYING( 10 ) comparison results.
char_10 - type character ( 10 )
var_char_10 - type character varying ( 10)
When I do the comparison between char_10 and var_char_10 columns, I may get the wrong results.
var_char_10 is always trimmed from right.
char_10 has padded data of blank or spaces.
Now I compare char10 and var_char_10 columns, I will get the wrong results because char_10 has padded spaces.
Is that correct or will it ignore whitespaces at the end of char_10 column?
Thanks,
Sarwar
________________________________
From: Scott Ribe <scott_ribe(at)elevated-dev(dot)com>
Sent: Thursday, June 15, 2023 11:56 AM
To: Wetmore, Matthew (CTR) <Matthew(dot)Wetmore(at)express-scripts(dot)com>
Cc: mahesh <mahesha_dba(at)yahoo(dot)com>; Mohammed Aslam <hmdaslam97(at)gmail(dot)com>; pgsql-admin(at)lists(dot)postgresql(dot)org <pgsql-admin(at)lists(dot)postgresql(dot)org>; Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>; M Sarwar <sarwarmd02(at)outlook(dot)com>
Subject: Re: The same result for with SPACE and without SPACE
Nobody's kicking you out of any group. Someone requested themselves to be removed, with a typo that made it ambiguous.
The original question had nothing to do with INT, it was behavior of CHAR and trailing spaces.
> select c1 from matt_test where c1 = '123'
> -- all 3 rows returned.
> Is it expected behavior that all 3 rows would be returned (because the space isn’t an INT?)
Yes. Or more precisely, it is because when a string is cast to an int, leading and trailing spaces are ignored. The alternative would be to raise an error, as 'an integer plus some spaces' is not an integer...
> select c2 from matt_test2 where c2 = '123'
> -- 1 rows returned.
Yes, for TEXT column, which behaves the same as VARCHAR. Also 1 row for:
select c2 from matt_test2 where c2 = '123 '
But 2 rows returned for CHAR column, as inserting '123' and '123 ' into CHAR(n) results in the same value being inserted. And also 2 rows returned for:
select c2 from matt_test2 where c2 = '123 '
^^^ which was the original question
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2023-06-15 18:04:41 | Re: The same result for with SPACE and without SPACE |
Previous Message | M Sarwar | 2023-06-15 17:26:28 | Re: The same result for with SPACE and without SPACE |
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2023-06-15 18:04:41 | Re: The same result for with SPACE and without SPACE |
Previous Message | M Sarwar | 2023-06-15 17:26:28 | Re: The same result for with SPACE and without SPACE |