public inbox for [email protected]  
help / color / mirror / Atom feed
chr(3) and 3::text
12+ messages / 5 participants
[nested] [flat]

* chr(3) and 3::text
@ 2020-03-28 13:21 gmail Vladimir Koković <[email protected]>
  2020-03-28 13:35 ` RE: chr(3) and 3::text Ken Benson <[email protected]>
  2020-03-28 14:57 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  2020-03-28 15:04 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  0 siblings, 3 replies; 12+ messages in thread

From: gmail Vladimir Koković @ 2020-03-28 13:21 UTC (permalink / raw)
  To: pgsql-novice

Hi,

Why is chr(3) is different than 3::text ?

Examples:

replace(Filler,chr(3),'') WORKS

replace(Filler3::text,'') WRONG

Vladimir Kokovic, DP senior (69)
Serbia, Belgrade, March 28, 2020




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
@ 2020-03-28 13:35 ` Ken Benson <[email protected]>
  2020-03-28 13:38   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2 siblings, 1 reply; 12+ messages in thread

From: Ken Benson @ 2020-03-28 13:35 UTC (permalink / raw)
  To: gmail Vladimir Koković <[email protected]>; pgsql-novice


From: gmail Vladimir Koković <[email protected]>
Sent: Saturday, March 28, 2020 6:22 AM
To: [email protected]
Subject: chr(3) and 3::text


Hi,

Why is chr(3) is different than 3::text ?



[Ken Benson] Chr(3) – means return the character that has the ASCII code of “3” – which is a control character.

https://w3resource.com/PostgreSQL/chr-function.php

Examples:

replace(Filler,chr(3),'') WORKS

replace(Filler3::text,'') WRONG

Vladimir Kokovic, DP senior (69)
Serbia, Belgrade, March 28, 2020




Ken Benson | ken @ infowerks-dot-com





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 13:35 ` RE: chr(3) and 3::text Ken Benson <[email protected]>
@ 2020-03-28 13:38   ` gmail Vladimir Koković <[email protected]>
  2020-03-28 14:39     ` RE: chr(3) and 3::text Ken Benson <[email protected]>
  0 siblings, 1 reply; 12+ messages in thread

From: gmail Vladimir Koković @ 2020-03-28 13:38 UTC (permalink / raw)
  To: Ken Benson <[email protected]>; pgsql-novice

OK,


And what is 3::text ?


On 28.3.20. 14:35, Ken Benson wrote:
>
> *From:* gmail Vladimir Koković <[email protected]>
> *Sent:* Saturday, March 28, 2020 6:22 AM
> *To:* [email protected]
> *Subject:* chr(3) and 3::text
>
> Hi,
>
> Why is chr(3) is different than 3::text ?
>
> */[Ken Benson] Chr(3) – means return the character that has the ASCII 
> code of “3” – which is a control character./*
>
> https://w3resource.com/PostgreSQL/chr-function.php*//*
>
> Examples:
>
> replace(Filler,chr(3),'') WORKS
>
> replace(Filler3::text,'') WRONG
>
> Vladimir Kokovic, DP senior (69)
> Serbia, Belgrade, March 28, 2020
>
>
>
> Ken Benson | ken @ infowerks-dot-com
>


^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 13:35 ` RE: chr(3) and 3::text Ken Benson <[email protected]>
  2020-03-28 13:38   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
@ 2020-03-28 14:39     ` Ken Benson <[email protected]>
  2020-03-28 14:59       ` Re: chr(3) and 3::text Bzzzz <[email protected]>
  0 siblings, 1 reply; 12+ messages in thread

From: Ken Benson @ 2020-03-28 14:39 UTC (permalink / raw)
  To: gmail Vladimir Koković <[email protected]>; pgsql-novice

From: gmail Vladimir Koković <[email protected]>
Sent: Saturday, March 28, 2020 6:39 AM
To: Ken Benson <[email protected]>; [email protected]
Subject: Re: chr(3) and 3::text


OK,



And what is 3::text ?



[Ken Benson]  that means convert the numeric value “3” to a text data type … similar to CAST(NumericValue as text) in MSSQL


On 28.3.20. 14:35, Ken Benson wrote:

From: gmail Vladimir Koković <[email protected]><mailto:[email protected]>
Sent: Saturday, March 28, 2020 6:22 AM
To: [email protected]<mailto:[email protected]>
Subject: chr(3) and 3::text


Hi,

Why is chr(3) is different than 3::text ?



[Ken Benson] Chr(3) – means return the character that has the ASCII code of “3” – which is a control character.

https://w3resource.com/PostgreSQL/chr-function.php

Examples:

replace(Filler,chr(3),'') WORKS

replace(Filler3::text,'') WRONG

Vladimir Kokovic, DP senior (69)
Serbia, Belgrade, March 28, 2020





Ken Benson | ken @ infowerks-dot-com





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 13:35 ` RE: chr(3) and 3::text Ken Benson <[email protected]>
  2020-03-28 13:38   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 14:39     ` RE: chr(3) and 3::text Ken Benson <[email protected]>
@ 2020-03-28 14:59       ` Bzzzz <[email protected]>
  0 siblings, 0 replies; 12+ messages in thread

From: Bzzzz @ 2020-03-28 14:59 UTC (permalink / raw)
  To: [email protected]

On Sat, 28 Mar 2020 14:39:09 +0000
Ken Benson <[email protected]> wrote:

From my console, simply "3".

Jean-Yves

> And what is 3::text ?






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
@ 2020-03-28 14:57 ` David G. Johnston <[email protected]>
  2 siblings, 0 replies; 12+ messages in thread

From: David G. Johnston @ 2020-03-28 14:57 UTC (permalink / raw)
  To: gmail Vladimir Koković <[email protected]>; +Cc: pgsql-novice

--0000000000001aed5e05a1eb72ea
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sat, Mar 28, 2020 at 6:21 AM gmail Vladimir Kokovi=C4=87 <
[email protected]> wrote:

> Hi,
>
> Why is chr(3) is different than 3::text ?
>

First place to start given two things you may or may not know what they are
is the index in the documentation:



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
@ 2020-03-28 15:04 ` David G. Johnston <[email protected]>
  2020-03-28 15:09   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2 siblings, 1 reply; 12+ messages in thread

From: David G. Johnston @ 2020-03-28 15:04 UTC (permalink / raw)
  To: gmail Vladimir Koković <[email protected]>; +Cc: pgsql-novice

On Sat, Mar 28, 2020 at 6:21 AM gmail Vladimir Koković <
[email protected]> wrote:

>
> replace(Filler,chr(3),'') WORKS
>
> replace(Filler3::text,'') WRONG
>
"Wrong" is not a helpful term unless you describe what you are expecting
and how the result you got is different.  In particular just reading what
you've typed the "wrong" one fails because you forgot the comma between
"Fillter" and "3::text".  But I suspect you had a different unsaid
expectation here.

In the future you should consider writing self-contained expressions,
ideally ones that don't use physical tables if the problem permits.

David J.


^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:04 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
@ 2020-03-28 15:09   ` gmail Vladimir Koković <[email protected]>
  2020-03-28 15:25     ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  0 siblings, 1 reply; 12+ messages in thread

From: gmail Vladimir Koković @ 2020-03-28 15:09 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: pgsql-novice; Ken Benson <[email protected]>

David,

Sorry for copy/paste error:replace(Filler,3::text,'') WRONG !

Character 0x03 is valid in ASCII and UTF-8 character sets.

Main question is, why is 3::text == '3' ?

On 28.3.20. 16:04, David G. Johnston wrote:
> On Sat, Mar 28, 2020 at 6:21 AM gmail Vladimir Koković 
> <[email protected] <mailto:[email protected]>> wrote:
>
>
>     replace(Filler,chr(3),'') WORKS
>
>     replace(Filler3::text,'') WRONG
>
> "Wrong" is not a helpful term unless you describe what you are 
> expecting and how the result you got is different.  In particular just 
> reading what you've typed the "wrong" one fails because you forgot the 
> comma between "Fillter" and "3::text".  But I suspect you had a 
> different unsaid expectation here.
>
> In the future you should consider writing self-contained expressions, 
> ideally ones that don't use physical tables if the problem permits.
>
> David J.
>


^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:04 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  2020-03-28 15:09   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
@ 2020-03-28 15:25     ` David G. Johnston <[email protected]>
  2020-03-28 15:39       ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 16:02       ` Re: chr(3) and 3::text Tom Lane <[email protected]>
  0 siblings, 2 replies; 12+ messages in thread

From: David G. Johnston @ 2020-03-28 15:25 UTC (permalink / raw)
  To: gmail Vladimir Koković <[email protected]>; +Cc: pgsql-novice; Ken Benson <[email protected]>

On Sat, Mar 28, 2020 at 8:09 AM gmail Vladimir Koković <
[email protected]> wrote:

> David,
>
> Sorry for copy/paste error:replace(Filler,3::text,'') WRONG !
>
> Character 0x03 is valid in ASCII and UTF-8 character sets.
>
> Main question is, why is 3::text == '3' ?
>
The convention here is to bottom or inline post, trimming unnecessary
content.

Its that way because :: is defined to make it that way.

3 has a type of integer
'3' has a type of text
::<type> is the PostgreSQL type casting operator that casts its left to to
<type> (see the documentation I linked to)

So:

integer::text == text

cast(integer as text) == text

is the SQL Standard equivalent expression

David J.


^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:04 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  2020-03-28 15:09   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:25     ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
@ 2020-03-28 15:39       ` gmail Vladimir Koković <[email protected]>
  2020-03-28 16:02         ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  1 sibling, 1 reply; 12+ messages in thread

From: gmail Vladimir Koković @ 2020-03-28 15:39 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: pgsql-novice; Ken Benson <[email protected]>

On 28.3.20. 16:25, David G. Johnston wrote:
>
> The convention here is to bottom or inline post, trimming unnecessary 
> content.
>
> Its that way because :: is defined to make it that way.
>
> 3 has a type of integer
> '3' has a type of text
> ::<type> is the PostgreSQL type casting operator that casts its left 
> to to <type> (see the documentation I linked to)
>
> So:
>
> integer::text == text
>
> cast(integer as text) == text
>
> is the SQL Standard equivalent expression
>
> David J.
>
integer::text == text, but which character 0x03 or 0x33 ?

Text should contain characters.

Characters is from character set.

Character 0x03 is valid in ASCII and UTF-8 character sets.




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:04 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  2020-03-28 15:09   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:25     ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  2020-03-28 15:39       ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
@ 2020-03-28 16:02         ` David G. Johnston <[email protected]>
  0 siblings, 0 replies; 12+ messages in thread

From: David G. Johnston @ 2020-03-28 16:02 UTC (permalink / raw)
  To: gmail Vladimir Koković <[email protected]>; +Cc: pgsql-novice; Ken Benson <[email protected]>

On Sat, Mar 28, 2020 at 8:39 AM gmail Vladimir Koković <
[email protected]> wrote:

> On 28.3.20. 16:25, David G. Johnston wrote:
>
> integer::text == text, but which character 0x03 or 0x33 ?
>
x33

Text should contain characters.
>
> Characters is from character set.
>
> Character 0x03 is valid in ASCII and UTF-8 character sets.
>
So is x33

Which one is more useful to the typical programmer (which given you concept
of works and wrong in the OP your problem space is probably not typical)?
Treating the integer value 3 as a code point reference or treating it as a
character in a given character set.

I hope you agree that the character interpretation is more useful, though
regardless of your agreement that is what happens.  Everything else is just
an implementation detail.

Numbers > 9 are converted digit-by-digit into their character
representations and then concatenated together.


David J.


^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: chr(3) and 3::text
  2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:04 ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
  2020-03-28 15:09   ` Re: chr(3) and 3::text gmail Vladimir Koković <[email protected]>
  2020-03-28 15:25     ` Re: chr(3) and 3::text David G. Johnston <[email protected]>
@ 2020-03-28 16:02       ` Tom Lane <[email protected]>
  1 sibling, 0 replies; 12+ messages in thread

From: Tom Lane @ 2020-03-28 16:02 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: gmail Vladimir Koković <[email protected]>; pgsql-novice; Ken Benson <[email protected]>

"David G. Johnston" <[email protected]> writes:
> On Sat, Mar 28, 2020 at 8:09 AM gmail Vladimir Koković <
> [email protected]> wrote:
>> Main question is, why is 3::text == '3' ?

> Its that way because :: is defined to make it that way.

More concretely: for most types, casting to text is defined to produce the
textual representation of the value.  An unadorned literal 3 starts life
as type integer, so what you've got here is an integer-to-text cast,
and that's going to convert the integer the same way it would be output.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2020-03-28 16:02 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 13:21 chr(3) and 3::text gmail Vladimir Koković <[email protected]>
2020-03-28 13:35 ` Ken Benson <[email protected]>
2020-03-28 13:38   ` gmail Vladimir Koković <[email protected]>
2020-03-28 14:39     ` Ken Benson <[email protected]>
2020-03-28 14:59       ` Bzzzz <[email protected]>
2020-03-28 14:57 ` David G. Johnston <[email protected]>
2020-03-28 15:04 ` David G. Johnston <[email protected]>
2020-03-28 15:09   ` gmail Vladimir Koković <[email protected]>
2020-03-28 15:25     ` David G. Johnston <[email protected]>
2020-03-28 15:39       ` gmail Vladimir Koković <[email protected]>
2020-03-28 16:02         ` David G. Johnston <[email protected]>
2020-03-28 16:02       ` Tom Lane <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox