Re: Incomplete or misleading explanation of the data types for mathematical operators

2020-03-21 Thread Bruce Momjian
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 +, 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  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 @@

 

-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 bit and bit varying, as
 shown in .



Re: optionally schema-qualified for table_name

2020-03-21 Thread Bruce Momjian
On Thu, Mar 12, 2020 at 05:58:02AM +, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
> 
> Page: https://www.postgresql.org/docs/12/sql-altersequence.html
> Description:
> 
> Although I can see that table_name in OWNED BY clause can be optionally
> schema-qualified by ᅟcarefully reading "The specified table must have the
> same owner and be in the same schema as the sequence.", it would be good if
> "optionally schema-qualified" is explicitly noted somehow like other pages
> such as CREATE TABLE and CREATE VIEW. The same applies to CREATE SEQUENCE
> page.

I see what you mean.  The attached patch fixes this, as well as
adjusting the error message.  I didn't see any other cases.

I thought maybe the schema wasn't mentioned because the table.column
defaults to the sequence's schema, but it does not --- you have to
specify the column's schema if would not be normally be found via
search_path:

CREATE SCHEMA zz;

SET search_path = zz, public;

CREATE TABLE zz.test (x INT);
CREATE SEQUENCE zz.ss;

ALTER SEQUENCE zz.ss OWNED BY test.x;

SET search_path = public, zz;
ALTER SEQUENCE zz.ss OWNED BY test.x;

SET search_path = public;

ALTER SEQUENCE zz.ss OWNED BY test.x;
--> ERROR:  relation "test" does not exist
ALTER SEQUENCE zz.ss OWNED BY zz.test.x;

-- 
  Bruce Momjian  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/ref/alter_sequence.sgml b/doc/src/sgml/ref/alter_sequence.sgml
index bfd20af6d3..b732a68d4e 100644
--- a/doc/src/sgml/ref/alter_sequence.sgml
+++ b/doc/src/sgml/ref/alter_sequence.sgml
@@ -30,7 +30,7 @@ ALTER SEQUENCE [ IF EXISTS ] name
 [ START [ WITH ] start ]
 [ RESTART [ [ WITH ] restart ] ]
 [ CACHE cache ] [ [ NO ] CYCLE ]
-[ OWNED BY { table_name.column_name | NONE } ]
+[ OWNED BY { [ schema . ] table_name.column_name | NONE } ]
 ALTER SEQUENCE [ IF EXISTS ] name OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
 ALTER SEQUENCE [ IF EXISTS ] name RENAME TO new_name
 ALTER SEQUENCE [ IF EXISTS ] name SET SCHEMA new_schema
@@ -238,7 +238,7 @@ ALTER SEQUENCE [ IF EXISTS ] name S
  
 

-OWNED BY table_name.column_name
+OWNED BY [ schema . ] table_name.column_name
 OWNED BY NONE
 
  
diff --git a/doc/src/sgml/ref/create_sequence.sgml b/doc/src/sgml/ref/create_sequence.sgml
index e4085804a4..cd72293df9 100644
--- a/doc/src/sgml/ref/create_sequence.sgml
+++ b/doc/src/sgml/ref/create_sequence.sgml
@@ -26,7 +26,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE [ IF NOT EXISTS ] increment ]
 [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
 [ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
-[ OWNED BY { table_name.column_name | NONE } ]
+[ OWNED BY { [ schema . ] table_name.column_name | NONE } ]
 
  
 
@@ -225,7 +225,7 @@ SELECT * FROM name;

 

-OWNED BY table_name.column_name
+OWNED BY [ schema . ] table_name.column_name
 OWNED BY NONE
 
  
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 6aab73bfd4..f9750d2cdf 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -1656,7 +1656,7 @@ process_owned_by(Relation seqrel, List *owned_by, bool for_identity)
 			ereport(ERROR,
 	(errcode(ERRCODE_SYNTAX_ERROR),
 	 errmsg("invalid OWNED BY option"),
-	 errhint("Specify OWNED BY table.column or OWNED BY NONE.")));
+	 errhint("Specify OWNED BY [schema.]table.column or OWNED BY NONE.")));
 		tablerel = NULL;
 		attnum = 0;
 	}
diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.out
index 8b928b2888..e66059fd75 100644
--- a/src/test/regress/expected/sequence.out
+++ b/src/test/regress/expected/sequence.out
@@ -19,7 +19,7 @@ ERROR:  CACHE (0) must be greater than zero
 -- OWNED BY errors
 CREATE SEQUENCE sequence_testx OWNED BY nobody;  -- nonsense word
 ERROR:  invalid OWNED BY option
-HINT:  Specify OWNED BY table.column or OWNED BY NONE.
+HINT:  Specify OWNED BY [schema.]table.column or OWNED BY NONE.
 CREATE SEQUENCE sequence_testx OWNED BY pg_class_oid_index.oid;  -- not a table
 ERROR:  referenced relation "pg_class_oid_index" is not a table or foreign table
 CREATE SEQUENCE sequence_testx OWNED BY pg_class.relname;  -- not same schema