public inbox for [email protected]help / color / mirror / Atom feed
Incomplete or misleading explanation of the data types for mathematical operators 5+ messages / 3 participants [nested] [flat]
* Incomplete or misleading explanation of the data types for mathematical operators @ 2020-01-29 19:35 PG Doc comments form <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: PG Doc comments form @ 2020-01-29 19:35 UTC (permalink / raw) To: [email protected]; +Cc: [email protected] The following documentation comment has been logged on the website: Page: https://www.postgresql.org/docs/12/functions-math.html Description: "The bitwise operators work only on integral data types, whereas the others are available for all numeric data types. " Many math operators silently convert integral data types to double for calculations, so the result will not be the same data type as what was provided. select pg_typeof(10^2::bigint),pg_typeof(10^2::numeric) select pg_typeof(|/25::int), pg_typeof(|/25::numeric) select pg_typeof(10*10::bigint), pg_typeof(10*10::numeric) Multiplication preserves data type, exponentiation silently converts bigint to double, but preserves numeric data type, square root silently converts both int and numeric types to double. The best would be to explain this behaivior of operators like it was done for mathematical functions. ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Incomplete or misleading explanation of the data types for mathematical operators @ 2020-03-06 02:29 Bruce Momjian <[email protected]> parent: PG Doc comments form <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: Bruce Momjian @ 2020-03-06 02:29 UTC (permalink / raw) To: [email protected]; [email protected] On Wed, Jan 29, 2020 at 07:35:18PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/12/functions-math.html > Description: > > "The bitwise operators work only on integral data types, whereas the others > are available for all numeric data types. " > Many math operators silently convert integral data types to double for > calculations, so the result will not be the same data type as what was > provided. > select pg_typeof(10^2::bigint),pg_typeof(10^2::numeric) > select pg_typeof(|/25::int), pg_typeof(|/25::numeric) > select pg_typeof(10*10::bigint), pg_typeof(10*10::numeric) > > Multiplication preserves data type, exponentiation silently converts bigint > to double, but preserves numeric data type, square root silently converts > both int and numeric types to double. > The best would be to explain this behaivior of operators like it was done > for mathematical functions. Uh, how does this relate to bitwise operators? Why would we mention type changes for things like exponentiation in the bitwise operator documentation section? -- Bruce Momjian <[email protected]> https://momjian.us EnterpriseDB https://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription + ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Incomplete or misleading explanation of the data types for mathematical operators @ 2020-03-06 03:03 Sergei Agalakov <[email protected]> parent: Bruce Momjian <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: Sergei Agalakov @ 2020-03-06 03:03 UTC (permalink / raw) To: Bruce Momjian <[email protected]>; [email protected] On 3/5/2020 7:29 PM, Bruce Momjian wrote: > On Wed, Jan 29, 2020 at 07:35:18PM +0000, PG Doc comments form wrote: >> The following documentation comment has been logged on the website: >> >> Page: https://www.postgresql.org/docs/12/functions-math.html >> Description: >> >> "The bitwise operators work only on integral data types, whereas the others >> are available for all numeric data types. " >> Many math operators silently convert integral data types to double for >> calculations, so the result will not be the same data type as what was >> provided. >> select pg_typeof(10^2::bigint),pg_typeof(10^2::numeric) >> select pg_typeof(|/25::int), pg_typeof(|/25::numeric) >> select pg_typeof(10*10::bigint), pg_typeof(10*10::numeric) >> >> Multiplication preserves data type, exponentiation silently converts bigint >> to double, but preserves numeric data type, square root silently converts >> both int and numeric types to double. >> The best would be to explain this behaivior of operators like it was done >> for mathematical functions. > Uh, how does this relate to bitwise operators? Why would we mention > type changes for things like exponentiation in the bitwise operator > documentation section? > This chapter is named "Mathematical Functions and Operators". The table 9.4. is named "Mathematical Operators". I don't see on this page any section "Bitwise operators" so I don't really understand your complaint. How do you understand the phrase "The bitwise operators work only on integral data types, whereas the others are available for all numeric data types. " in the context of the table "Mathematical Operators"? I understand it that all other mathematical operators except bitwise operators do exist for all numeric data type. In what place by your opinion documentation should describe that some mathematical operators exist only for some numeric data types but not others? I have given examples of such operators - exponentiation and square root aren't defined for all numeric data types and do hidden conversion of the data types. ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Incomplete or misleading explanation of the data types for mathematical operators @ 2020-03-21 14:31 Bruce Momjian <[email protected]> parent: Sergei Agalakov <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: Bruce Momjian @ 2020-03-21 14:31 UTC (permalink / raw) To: Sergei Agalakov <[email protected]>; +Cc: [email protected] On Thu, Mar 5, 2020 at 08:03:19PM -0700, Sergei Agalakov wrote: > On 3/5/2020 7:29 PM, Bruce Momjian wrote: > > On Wed, Jan 29, 2020 at 07:35:18PM +0000, PG Doc comments form wrote: > > > Multiplication preserves data type, exponentiation silently converts bigint > > > to double, but preserves numeric data type, square root silently converts > > > both int and numeric types to double. > > > The best would be to explain this behaivior of operators like it was done > > > for mathematical functions. > > Uh, how does this relate to bitwise operators? Why would we mention > > type changes for things like exponentiation in the bitwise operator > > documentation section? > > > This chapter is named "Mathematical Functions and Operators". The table 9.4. > is named "Mathematical Operators". I don't see on this page any section > "Bitwise operators" so I don't really understand your complaint. > How do you understand the phrase "The bitwise operators work only on > integral data types, whereas the others are available for all numeric data > types. " in the context of the table "Mathematical Operators"? > I understand it that all other mathematical operators except bitwise > operators do exist for all numeric data type. > In what place by your opinion documentation should describe that some > mathematical operators exist only for some numeric data types but not > others? > I have given examples of such operators - exponentiation and square root > aren't defined for all numeric data types and do hidden conversion of the > data types. Ah, I see what you are saying now --- there are operators listed above that are not supported by all numeric data types, so "the others are available for all numeric data types" is false. I think the text was written because non-integer calls to bit-wise functions _fail_, rather than being silently converted: SELECT 1::float4 | 1; ERROR: operator does not exist: real | integer LINE 1: SELECT 1::float4 | 1; ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. but I see your point. I guess we could change the word "available" to "silently converted", but it seems best to just remove that phrase. Documentation patch attached. -- Bruce Momjian <[email protected]> https://momjian.us EnterpriseDB https://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription + Attachments: [text/x-diff] bit.diff (631B, 2-bit.diff) download | inline diff: diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 464a48ed6a..e1d70c251d 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -732,9 +732,8 @@ </table> <para> - The bitwise operators work only on integral data types, whereas - the others are available for all numeric data types. The bitwise - operators are also available for the bit + The bitwise operators work only on integral data types, and are also + available for the bit string types <type>bit</type> and <type>bit varying</type>, as shown in <xref linkend="functions-bit-string-op-table"/>. </para> ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Incomplete or misleading explanation of the data types for mathematical operators @ 2020-03-31 22:44 Bruce Momjian <[email protected]> parent: Bruce Momjian <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Bruce Momjian @ 2020-03-31 22:44 UTC (permalink / raw) To: Sergei Agalakov <[email protected]>; +Cc: [email protected] Patch applied through 9.5, thanks. --------------------------------------------------------------------------- On Sat, Mar 21, 2020 at 10:31:32AM -0400, Bruce Momjian wrote: > On Thu, Mar 5, 2020 at 08:03:19PM -0700, Sergei Agalakov wrote: > > On 3/5/2020 7:29 PM, Bruce Momjian wrote: > > > On Wed, Jan 29, 2020 at 07:35:18PM +0000, PG Doc comments form wrote: > > > > Multiplication preserves data type, exponentiation silently converts bigint > > > > to double, but preserves numeric data type, square root silently converts > > > > both int and numeric types to double. > > > > The best would be to explain this behaivior of operators like it was done > > > > for mathematical functions. > > > Uh, how does this relate to bitwise operators? Why would we mention > > > type changes for things like exponentiation in the bitwise operator > > > documentation section? > > > > > This chapter is named "Mathematical Functions and Operators". The table 9.4. > > is named "Mathematical Operators". I don't see on this page any section > > "Bitwise operators" so I don't really understand your complaint. > > How do you understand the phrase "The bitwise operators work only on > > integral data types, whereas the others are available for all numeric data > > types. " in the context of the table "Mathematical Operators"? > > I understand it that all other mathematical operators except bitwise > > operators do exist for all numeric data type. > > In what place by your opinion documentation should describe that some > > mathematical operators exist only for some numeric data types but not > > others? > > I have given examples of such operators - exponentiation and square root > > aren't defined for all numeric data types and do hidden conversion of the > > data types. > > Ah, I see what you are saying now --- there are operators listed above > that are not supported by all numeric data types, so "the others are > available for all numeric data types" is false. I think the text was > written because non-integer calls to bit-wise functions _fail_, rather > than being silently converted: > > SELECT 1::float4 | 1; > ERROR: operator does not exist: real | integer > LINE 1: SELECT 1::float4 | 1; > ^ > HINT: No operator matches the given name and argument types. You might > need to add explicit type casts. > > but I see your point. I guess we could change the word "available" to > "silently converted", but it seems best to just remove that phrase. > Documentation patch attached. > > -- > Bruce Momjian <[email protected]> https://momjian.us > EnterpriseDB https://enterprisedb.com > > + As you are, so once was I. As I am, so you will be. + > + Ancient Roman grave inscription + > diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml > index 464a48ed6a..e1d70c251d 100644 > --- a/doc/src/sgml/func.sgml > +++ b/doc/src/sgml/func.sgml > @@ -732,9 +732,8 @@ > </table> > > <para> > - The bitwise operators work only on integral data types, whereas > - the others are available for all numeric data types. The bitwise > - operators are also available for the bit > + The bitwise operators work only on integral data types, and are also > + available for the bit > string types <type>bit</type> and <type>bit varying</type>, as > shown in <xref linkend="functions-bit-string-op-table"/>. > </para> -- Bruce Momjian <[email protected]> https://momjian.us EnterpriseDB https://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription + ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2020-03-31 22:44 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-01-29 19:35 Incomplete or misleading explanation of the data types for mathematical operators PG Doc comments form <[email protected]> 2020-03-06 02:29 ` Bruce Momjian <[email protected]> 2020-03-06 03:03 ` Sergei Agalakov <[email protected]> 2020-03-21 14:31 ` Bruce Momjian <[email protected]> 2020-03-31 22:44 ` Bruce Momjian <[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