GreenPlum Database modifies the OWNER of a table, inserts null data, and common data types

When creating a table once, the wrong user was used, and the table was built under the gpadmin user. Although GreenPlum Database mainly uses SCHEMA instead of users when operating the table, it is still absolutely necessary to modify the table when it comes to permissions. OWNER. In the ORACLE database, it is not supported to directly modify the OWNER of the table, but the GreenPlum database does. The relationship between SCHEMA and OWNER in the GreenPlum database can be seen intuitively through the following information.

1 dbdream=# \d
2                  List of relations
3  Schema |     Name      | Type  |  Owner  | Storage
4 --------+---------------+-------+---------+---------
5  public | med_ord_pgm_d | table | gpadmin | heap
6  public | ord_pay       | table | gpadmin | heap
7  public | t_ctas        | table | dbdream | heap
8  (3 rows)

The concepts of SCHEMA, user and ORACLE in GreenPlum Database are completely different. From the above information, it can be seen that a SCHEMA can contain objects of multiple users. When operating on a table, SCHEMA.TABLENAME is used instead of OWNER.TABLENAME. Please see Demonstrate as follows.

01 dbdream=> \c
02 You are now connected to database "dbdream" as user "dbdream".
03 dbdream=> select * from dbdream.t_ctas;
04 ERROR:  schema "dbdream" does not exist
05 LINE 1: select * from dbdream.t_ctas;
06  
07 dbdream=> select * from public.t_ctas;
08  name | id
09 ------+----
10 (0 rows)

Within the consent SCHEMA, different users cannot create objects with the same name.

1 dbdream=> \c
2 You are now connected to database "dbdream" as user "dbdream".
3 dbdream=> create table med_ord_pgm_d(id int);
4 NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table.
5 HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
6 ERROR:  relation "med_ord_pgm_d" already exists

Different users need to have the authorization of the other party to directly access the other party's table, of course, except for the super user.

1 dbdream=> select * from public.med_ord_pgm_d;
2 ERROR:  permission denied for relation med_ord_pgm_d

To change the OWNER of a table, you can modify it directly through the alter table command.

01 dbdream=# ALTER TABLE ORD_PAY owner to dbdream;
02 ALTER TABLE
03  
04 dbdream=# \d
05                  List of relations
06  Schema |     Name      | Type  |  Owner  | Storage
07 --------+---------------+-------+---------+---------
08  public | med_ord_pgm_d | table | gpadmin | heap
09  public | ord_pay       | table | dbdream | heap
10  public | t_ctas        | table | dbdream | heap
11  (3 rows)

In GreenPlum Database, when inserting null values, fields of character type can be directly replaced with '', which is the same as in ORACLE database.

01 dbdream=> \d t_ctas
02            Table "public.t_ctas"
03  Column |         Type          | Modifiers
04 --------+-----------------------+-----------
05  name   | character varying(10) |
06  id     | integer               |
07 Distributed by: (name)
08 Tablespace: "tbs1"
09  
10 dbdream=> insert into t_ctas values ('',1);
11 INSERT 0 1

But for number and date types, this method will not work, '' in GreenPlum Database represents the character type.

1 dbdream=> insert into t_ctas values('a','');
2 ERROR:  invalid input syntax for integer: ""

For numeric or date type data, if you want to insert control, use null to specify it explicitly.

1 dbdream=> insert into t_ctas values('a',null);
2 INSERT 0 1

By the way, the data types commonly used in GreenPlum Database are introduced. The commonly used integer numeric types are int, bigint, and smallint, the commonly used decimal types are numeric and decimal, and the commonly used auto-increment types are serial and bigserial. The following creates a table of type numbers.

01 dbdream=> create table t_int(autoinc serial,small smallint,standard int,big bigint,acc numeric) Distributed by(autoinc);
02 NOTICE:  CREATE TABLE will create implicit sequence "t_int_autoinc_seq" for serial column "t_int.autoinc"
03 CREATE TABLE
04 dbdream=> \d t_int
05                              Table "public.t_int"
06   Column  |   Type   |                        Modifiers                       
07 ----------+----------+---------------------------------------------------------
08  autoinc  | integer  | not null default nextval('t_int_autoinc_seq'::regclass)
09  small    | smallint |
10  standard | integer  |
11  big      | bigint   |
12  acc      | numeric  |
13 Distributed by: (autoinc)
14 Tablespace: "tbs1"

smallint is a subtype of short integer, and the supported range is negative 32K (32768) to positive 32K-1 (32767).

int is a standard integer that supports a range of plus or minus 2G (-2147483648 to 2147483647).

bigint is a long integer type that supports plus or minus 9E (-9223372036854775808 to 9223372036854775807).

numeric是小数类型,没有限制。

serial是自增长数字类型,支持范围是1到2G(最大数值2147483647)。

bigserial是长类型自增长数字类型,最大支持9E长度(最大数值9223372036854775807)。

再看看字符类型,字符类型和其他数据库基本一样,也是分定长和变长类型,下面创建一张包含这些类型的表。

01 dbdream=> create table t_char(c char(10),v varchar(10),t text) DISTRIBUTED BY(c);
02 CREATE TABLE
03 dbdream=> \d t_char
04            Table "public.t_char"
05  Column |         Type          | Modifiers
06 --------+-----------------------+-----------
07  c      | character(10)         |
08  v      | character varying(10) |
09  t      | text                  |
10 Distributed by: (c)
11 Tablespace: "tbs1"

char类型是定长字符类型,最大支持10485760字节,不足以空格补齐。

varchar类型是变长字符类型,最大支持10485760字节。

text字符类型,没有长度限制。

在看下时间类型的字段,主要能用到的时间类型包括date、time、timestamp类型,下面创建一张时间类型字段的表。

01 dbdream=> create table t_time(d date,t time,ts timestamp) DISTRIBUTED BY(d);
02 CREATE TABLE
03 dbdream=> \d t_time
04               Table "public.t_time"
05  Column |            Type             | Modifiers
06 --------+-----------------------------+-----------
07  d      | date                        |
08  t      | time without time zone      |
09  ts     | timestamp without time zone |
10 Distributed by: (d)
11 Tablespace: "tbs1"

下面插入一条数据,看看数据存储格式。

1 dbdream=> insert into t_time values(current_date,current_time,current_timestamp);
2 INSERT 0 1
3 dbdream=> select * from t_time;
4      d      |        t        |             ts            
5 ------------+-----------------+----------------------------
6  2016-01-29 | 17:29:49.197889 | 2016-01-29 17:29:49.197889
7 (1 row)

data类型存的仅是日期类型的数据(年月日),这和ORACLE数据库的date类型不一样。

time类型存放的是一天以内的时间(时分秒),精确到毫秒。

timestamp类型存放的是日期和时间(data+time)类型的数据,精确到毫秒。

本文固定链接: http://www.dbdream.com.cn/2016/01/29/greenplum%e6%95%b0%e6%8d%ae%e5%ba%93%e4%bf%ae%e6%94%b9%e8%a1%a8%e7%9a%84owner%e3%80%81%e6%8f%92%e5%85%a5%e7%a9%ba%e5%80%bc%e6%95%b0%e6%8d%ae%e5%8f%8a%e5%b8%b8%e7%94%a8%e6%95%b0%e6%8d%ae%e7%b1%bb/ | 信春哥,系统稳,闭眼上线不回滚!

This log was published by dbdream on January 29, 2016 under the category of GreenPlum . You can leave a comment and quote it to your website or blog while retaining the original address and author . Please indicate the original article reprint: GreenPlum Database modify the OWNER of the table, insert null data and common data types | keyword: greenplum

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326183993&siteId=291194637