在MS SQL Server中,我创建脚本以使用可自定义的变量:
DECLARE @somevariable int
SELECT @somevariable = -1
INSERT INTO foo VALUES ( @somevariable )
Run Code Online (Sandbox Code Playgroud)
然后我将@somevariable在运行时更改值,具体取决于我在特定情况下所需的值.由于它位于脚本的顶部,因此很容易看到并记住.
我如何对PostgreSQL客户端做同样的事情psql?
我想liferay在PostgreSQL安装中列出数据库中的所有表.我怎么做?
我想SELECT * FROM applications;在liferay数据库中执行.applications是我liferay db中的一个表.这是怎么做到的?
这是我所有数据库的列表:
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
liferay | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | liferay=CTc/postgres
lportal | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
template0 | postgres …Run Code Online (Sandbox Code Playgroud) 我有PSQL运行,并试图让perl应用程序连接到数据库.是否有命令查找运行数据库的当前端口和主机?
我有一个包含多个模式的postgres数据库.当我从shell连接到数据库时psql,我运行\dt它使用默认的公共连接模式.是否有我可以指定的标志或如何更改架构?
我在OSX上安装了postgresql.当我运行psql时,我得到了
$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5433"?
Run Code Online (Sandbox Code Playgroud)
但是,来自/ etc/services
postgresql 5432/udp # PostgreSQL Database
postgresql 5432/tcp # PostgreSQL Database
# Tom Lane <tgl@sss.pgh.pa.us>
pyrrho 5433/tcp # Pyrrho DBMS
pyrrho 5433/udp # Pyrrho DBMS
Run Code Online (Sandbox Code Playgroud)
5433被pyrrho占据,5432被分配给pg.我可以联系
psql -p 5432
Run Code Online (Sandbox Code Playgroud)
但为什么psql认为它是5433,我如何让psql默认在正确的位置?
我正在使用'postgres'超级用户进行全新的postgresql安装.登录通过:
sudo -u postgres psql
postgres=# createdb database
postgres-# \list
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres
: postgres=CTc/postgres
Run Code Online (Sandbox Code Playgroud)
没有错误,但没有创建表.有任何想法吗?
在PostgreSQL交互式终端中输入以下命令会导致错误:
ALTER TABLE tbl_name ALTER COLUMN col_name varchar (11);
Run Code Online (Sandbox Code Playgroud)
更改列的数据类型的正确命令是什么?
有没有办法使用psql命令行界面显示表中的所有内容?
我可以\list用来显示所有数据库,\d显示所有表,但是如何显示表中的所有数据?
官方页面没有提到这种情况.但是许多用户只需要psql没有本地数据库(我在AWS上有它).Brew没有psql.
psql ×10
postgresql ×9
sql ×2
alter-column ×1
alter-table ×1
macos ×1
macos-sierra ×1
port ×1
variables ×1