我创建了一个用户,如下所示。
现在我使用上述用户登录到PostgreSQL中,如下所示:
我得到了模板1的命令提示符,如下所示。
如何使用上述用户(例如新创建的用户)获取列信息。
create role testuser1 with password 'testuser1' login;
alter role testuser1 with createrole createdb;
现在我使用上述用户登录到PostgreSQL中,如下所示:
psql -U testuser1 -d template1
我得到了模板1的命令提示符,如下所示。
template1#
接下来,我创建了一个如下所示的样本数据库
模板# create database testdb; 我成功创建了数据库。现在,我退出postgres。然后,我尝试使用样本凭据登录,但使用数据库testdb,并尝试使用以下命令导入模式文件(让它成为test.sql)
psql -h localhost -p 5432 -U testuser1 -d testdb -f "/mnt/hgfs/shared_ubuntu/sample_test_schema/pg/test.sql"
导入成功。在testdb中,以下是表格。
Schema | Name | Type | Owner --------+------------+-------+---------- public | pretabinto | table | postgres public | serial | table | postgres public | temp | table | postgres
现在,我尝试使用以下查询获取表格及其列信息。但是,结果返回了0个列表。
SELECT table_name,column_name,data_type
FROM information_schema.columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema');
如何使用上述用户(例如新创建的用户)获取列信息。
template0
创建新的数据库
。请参阅手册http://www.postgresql.org/docs/9.3/static/manage-ag-templatedbs.html。默认情况下,它是`template1`。 - Sarfaraz Makandar