我在表....中插入了一个数据我想看到整个表的行,列和数据。我如何通过命令显示它?
当前回答
我还注意到查询
SELECT * FROM tablename;
在PSQL命令提示符上给出错误 而且
SELECT * FROM "tablename";
运行正常,很奇怪,所以别忘了双引号。 我一直喜欢数据库:-(
其他回答
我将添加我的经验,一个命令,在windows机器上。 我想尝试运行一个命令,从中我将获得表内容。
这是一个对我有用的命令:
psql -U postgres -d typeorm -c "SELECT * FROM \"Author\";
- u postgres - user -d typeorm -我要连接的数据库 - c…-我的查询命令 ; ——分号
我遇到了一些问题,主要是弄清楚如何准确地设置查询部分。我尝试了不同的命令,比如:用',",(),但除了这个符号外,没有什么对我有效。
我还注意到查询
SELECT * FROM tablename;
在PSQL命令提示符上给出错误 而且
SELECT * FROM "tablename";
运行正常,很奇怪,所以别忘了双引号。 我一直喜欢数据库:-(
打开命令提示符,进入Postgres安装的目录。在我的情况下,我的Postgres路径是“D:\TOOLS\Postgresql-9.4.1-3”。然后移动到Postgres的bin目录。因此命令提示符显示为"D:\TOOLS\Postgresql-9.4.1-3\bin>" 现在我的目标是从用户表中使用“UserId”值选择“UserName”。数据库查询是"Select u "UserName" from users u其中u."UserId"=1"。
对于postgres的psql命令提示符,同样的查询如下所示。
D:\TOOLS\Postgresql-9.4.1-3\bin>psql - u postgress - D DatabaseName -h localhost - t -c "Select u.\"UserName\" from users u其中u.\"UserId\"=1;
I have no doubt on @Grant answer. But I face few issues sometimes such as if the column name is similar to any reserved keyword of postgresql such as natural in this case similar SQL is difficult to run from the command line as "\natural\" will be needed in Query field. So my approach is to write the SQL in separate file and run the SQL file from command line. This has another advantage too. If you have to change the query for a large script you do not need to touch the script file or command. Only change the SQL file like this
psql -h localhost -d database -U postgres -p 5432 -a -q -f /path/to/the/file.sql
SELECT * FROM my_table;
其中my_table是你的表名。
编辑:
psql -c "SELECT * FROM my_table"
或者只是PSQL,然后键入您的查询。
推荐文章
- 如果字符串包含
- 如何检查表上持有哪些锁
- 在MongoDB中查找重复的记录
- 对于PostgreSQL表来说,多大才算太大?
- 模式、表和数据库之间的区别是什么?
- 将一列的多个结果行连接为一列,按另一列分组
- 我看到VARCHAR(255)如此频繁地使用(而不是其他长度),有什么好的原因吗?
- 使用pgadmin连接到heroku数据库
- 在PostgreSQL中快速发现表的行数
- 更改varchar列的大小为较低的长度
- Delete_all vs destroy_all
- 我如何移动一个redis数据库从一个服务器到另一个?
- 如何首次配置postgresql ?
- 数据库性能调优有哪些资源?
- 如何在PostgreSQL中自动更新时间戳