标签: psql

在psql中垂直显示选择结果,就像MySQL的\ G一样

在MySQL中,您可以select使用\G(而不是\g)终止查询以垂直显示结果:

select * from foo \G

***************
 id: 1
bar: Hello
***************
 id: 2
bar: World
Run Code Online (Sandbox Code Playgroud)

如何使用psql为PostgreSQL做同样的事情?

postgresql psql

62
推荐指数
1
解决办法
2万
查看次数

Postgres JSON数据类型Rails查询

我正在使用Postgres的json数据类型,但想要使用嵌套在json中的数据进行查询/排序.

我想在json数据类型上使用.where进行排序或查询.例如,我想查询跟随者数> 500的用户,或者我想通过关注者或跟随计数来订购.

谢谢!

例:

model User

data: {
     "photos"=>[
       {"type"=>"facebook", "type_id"=>"facebook", "type_name"=>"Facebook", "url"=>"facebook.com"}
      ], 
     "social_profiles"=>[
         {"type"=>"vimeo", "type_id"=>"vimeo", "type_name"=>"Vimeo", "url"=>"http://vimeo.com/", "username"=>"v", "id"=>"1"},
         {"bio"=>"I am not a person, but a series of plants", "followers"=>1500, "following"=>240, "type"=>"twitter", "type_id"=>"twitter", "type_name"=>"Twitter", "url"=>"http://www.twitter.com/", "username"=>"123", "id"=>"123"}
     ]
}
Run Code Online (Sandbox Code Playgroud)

postgresql json rails-postgresql psql ruby-on-rails-4

51
推荐指数
2
解决办法
3万
查看次数

psql:命令找不到Mac

我通过http://www.postgresql.org/download/macosx/上的图形安装安装了PostgreSQL

我在我的应用程序中看到它,并且在我的应用程序中也有psql终端.我需要psql在常规终端中工作另一个bash脚本我正在为一个应用程序运行.

出于某种原因,当我跑步时

psql
Run Code Online (Sandbox Code Playgroud)

在Mac终端,我的输出是

-bash: psql: command not found
Run Code Online (Sandbox Code Playgroud)

我在终端上运行了以下内容:

locate psql | grep /bin
Run Code Online (Sandbox Code Playgroud)

而输出是

/Library/PostgreSQL/9.5/bin/psql
Run Code Online (Sandbox Code Playgroud)

然后我编辑了〜/ .bash_profile并将其添加到路径中,如下所示:

export PATH = /Library/PostgreSQL/9.5/bin/psql:$PATH
Run Code Online (Sandbox Code Playgroud)

〜/ .bash_profile中唯一的另一件事是SDK man,它位于脚本底部,因为它应该是.我已经尝试将浴缸设置为/Library/PostgreSQL/9.5/bin/.我也重启了我的终端.

我怎样才能让psql工作?

编辑 添加到.bashrc后,当我打开终端时返回此输出

-bash: export: `/Library/PostgreSQL/9.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin': not a valid identifier
Run Code Online (Sandbox Code Playgroud)

postgresql macos bash psql

51
推荐指数
10
解决办法
8万
查看次数

PostgreSQL psql终端命令

我正在尝试psql很好地格式化并遵循这里的文档.现在,每当我对包含大量列的表进行查询时,无论我的屏幕有多大,每一行都会溢出到下一行并产生一整页不可读的垃圾.

文档(链接在上面)说有一种方法可以很好地对齐列以获得更可读的输出.

通常,首先psql,我输入:

PSQL

并按Enter键.现在我正在尝试:

psql\pset格式对齐

并得到一个错误:

could not change directory to "/root"
psql: warning: extra command-line argument "aligned" ingored
psql: FATAL: Indent authentication failed for user "format"
Run Code Online (Sandbox Code Playgroud)

关于如何让这些命令行参数为我工作的任何想法?

linux postgresql command-line psql

48
推荐指数
2
解决办法
18万
查看次数

用exec调用函数而不是select

是调用函数的默认方式select * from my_function()吗?

我问,因为我已经构建了一个不返回任何内容的函数,只是将数据插入到表中(来自SQL Server背景),调用它时"感觉"很奇怪 select * from...

我期待着类似的东西 exec my_function()

postgresql psql

47
推荐指数
3
解决办法
7万
查看次数

PG :: UndefinedTable:错误:使用连接时缺少表的FROM子句条目和where

我有两个型号,CourierOrder.

我在下面有以下查询:

active_couriers = Courier.
  available_courier_status.
  where(:service_region_id => @service_region.id).
  includes(:orders)
Run Code Online (Sandbox Code Playgroud)

但是,此查询有效,它会提取所有订单.我想将订单限制为当天的订单.所以我添加了以下查询where("orders.created_at >= ?", Time.zone.now.beginning_of_day).

active_couriers = Courier.
  available_courier_status.
  where(:service_region_id => @service_region.id).
  includes(:current_orders).
  includes(:orders).
  where("orders.created_at >= ?", Time.zone.now.beginning_of_day)
Run Code Online (Sandbox Code Playgroud)

这给了我错误:

PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "orders"
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

ruby-on-rails psql ruby-on-rails-4

47
推荐指数
2
解决办法
4万
查看次数

Postgresql - 无法识别的配置参数

我从外部服务器导出了一个postgresql数据库,并试图将其导入我的本地服务器,但是出现了这个错误:

unrecognized configuration parameter "idle_in_transaction_session_timeout"
Run Code Online (Sandbox Code Playgroud)

这种错误是否意味着两台服务器使用不同版本的postgresql?我调查了一下,外部服务器正在运行:

version
PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit 
Run Code Online (Sandbox Code Playgroud)

我的服务器正在运行:

version
PostgreSQL 9.5.5 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609, 64-bit 
Run Code Online (Sandbox Code Playgroud)

几乎是一回事.是否有一个站点,您可以在其中查看每个版本的所有有效配置参数?有没有办法同步这样的两个数据库,所以这样的不兼容性会自动修补?

postgresql psql

44
推荐指数
2
解决办法
3万
查看次数

PostgreSQL嵌套JSON查询

在PostgreSQL 9.3.4上,我有一个名为"person"的JSON类型列,其中存储的数据采用格式{dogs: [{breed: <>, name: <>}, {breed: <>, name: <>}]}.我想在索引0处检索狗的品种.以下是我运行的两个查询:

不行

db=> select person->'dogs'->>0->'breed' from people where id = 77;
ERROR:  operator does not exist: text -> unknown
LINE 1: select person->'dogs'->>0->'bree...
                                 ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

作品

select (person->'dogs'->>0)::json->'breed' from es_config_app_solutiondraft where id = 77;
 ?column?
-----------
 "westie"
(1 row)
Run Code Online (Sandbox Code Playgroud)

为什么必须进行铸造?是不是效率低下?我做错了什么或者这对于postgres JSON支持是否必要?

postgresql json psql postgresql-9.3

43
推荐指数
1
解决办法
3万
查看次数

PostgreSQL用户列表

我想获取psql中某个数据库的用户列表 - 例如"template0".谁是用户?或者对于"template1"数据库: - 谁是那里的用户?

已经尝试过:

\du+  -- no database is Listed not Users
Select * from "pg_users";  -- no database is listed
Run Code Online (Sandbox Code Playgroud)

postgresql privileges psql

39
推荐指数
3
解决办法
7万
查看次数

导入没有角色的postgres数据库

我有一个用pg_dump导出的数据库,但现在当我尝试再次导入它时:

psql -d databasename < mydump.sql
Run Code Online (Sandbox Code Playgroud)

它未能尝试将角色授予不存在的人.(错误说'角色'xxx"不存在')

有没有办法自动导入并设置所有角色给我的用户?

sql database postgresql import psql

39
推荐指数
5
解决办法
3万
查看次数