Sunday, 13 December 2020

create table inside the postgresql db

Mysql4=# show data_directory;

     data_directory

------------------------

 /var/lib/pgsql/12/data

(1 row)





 mysql4=# \dt+ myschema.table20

                        List of relations

  Schema  |  Name   | Type  |  Owner   |    Size    | Description

----------+---------+-------+----------+------------+-------------

 myschema | table20 | table | postgres | 8192 bytes |

(1 row)


mysql4=# create table test.emp(empno int primary key NOT NULL,ename varchar NOT NULL,job varchar,dob DATE,deptno int);

ERROR:  schema "test" does not exist

LINE 1: create table test.emp(empno int primary key NOT NULL,ename v...

                     ^

mysql4=# create table myschema.emp(empno int primary key NOT NULL,ename varchar NOT NULL,job varchar,dob DATE,deptno int);

CREATE TABLE

mysql4=#

mysql4=#

mysql4=# \dt +

ERROR:  invalid regular expression: quantifier operand invalid

mysql4=#

mysql4=# select schemaname,relname from pg_stat_user_tables;

 schemaname | relname

------------+---------

 myschema   | table20

 myschema   | emp

(2 rows)


mysql4=# create materialized view myschema.emp_mv as select * from myschema.emp;

SELECT 0

mysql4=#

mysql4=# select * from myschema.emp_mv;

 empno | ename | job | dob | deptno

-------+-------+-----+-----+--------

(0 rows)


mysql4=# insert into myschema.emp values(100,'Ram','Admin','10-Jan-1973',10);

INSERT 0 1

mysql4=# insert into myschema.emp values(101,'ravan','Admin','10-Jan-1972',11);

INSERT 0 1

mysql4=# select * from myschema.emp_mv;

 empno | ename | job | dob | deptno

-------+-------+-----+-----+--------

(0 rows)


mysql4=# refresh materialized view myschema.emp_mv;

REFRESH MATERIALIZED VIEW

mysql4=# select * from myschema.emp_mv;

 empno |  ename   |  job  |    dob     | deptno

-------+----------+-------+------------+--------

   100 | Ram | Admin | 1973-01-10 |     10

   101 | ravan  | Admin | 1982-01-10 |     11


No comments:

Post a Comment

Featured post

duplicate db from standy to other server

 Duplicate Testuat   $ export ORACLE_SID=Testuat3 $ sqlplus '/as sysdba' Testuat3 SQL> alter system set cluster_database=FALSE sc...