AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-63034

showkey's questions

Martin Hope
showkey
Asked: 2025-04-04 08:28:23 +0800 CST

如何从全外连接中获得增强的结果?

  • 7

有两个原始数据文件q4.csv和q3.csv。
显示q4.csv:

cat q4.csv    
nameofissuer,shares
nvr inc,11112
pool corp,598689
jefferies finl group inc,433558
constellation brands inc,5624324
bank amer corp,680233587
occidental pete corp,264178414

展示q3.csv:

cat /tmp/q3.csv
nameofissuer,shares
nvr inc,11112
pool corp,404057
jefferies finl group inc,433558
bank amer corp,797683307
occidental pete corp,255281524
vanguard index fds,43000
spdr s&p 500 etf tr,39400
ulta beauty inc,24203

进入psql准备表:

create database project;
\c project
create table q4(nameofissuer  text,shares int);
copy q4(nameofissuer,shares)
from '/tmp/q3.csv' delimiter ',' csv header;
create table q3(nameofissuer  text,shares int);
copy q3(nameofissuer,shares)
from '/tmp/q3.csv' delimiter ',' csv header;  

使用完全外连接:

select           
    q4.nameofissuer as issuer_q4,q4.shares as shares_end,q3.nameofissuer as issuer_q3,q3.shares as shares_start from q4
full outer join q3
on q4.nameofissuer  = q3.nameofissuer;

        issuer_q4         | shares_end |        issuer_q3         | shares_start 
--------------------------+------------+--------------------------+--------------
 bank amer corp           |  680233587 | bank amer corp           |    797683307
 constellation brands inc |    5624324 |                          |             
 jefferies finl group inc |     433558 | jefferies finl group inc |       433558
 nvr inc                  |      11112 | nvr inc                  |        11112
 occidental pete corp     |  264178414 | occidental pete corp     |    255281524
 pool corp                |     598689 | pool corp                |       404057
                          |            | spdr s&p 500 etf tr      |        39400
                          |            | ulta beauty inc          |        24203
                          |            | vanguard index fds       |        43000

如何使用纯 SQL 命令获得以下所需输出?

     nameofissuer         | shares_end | shares_start |   change   
--------------------------+------------+--------------+------------
 bank amer corp           |  680233587 |    797683307 | -117449720
 constellation brands inc |    5624324 |            0 |    5624324
 jefferies finl group inc |     433558 |       433558 |          0
 nvr inc                  |      11112 |        11112 |          0
 occidental pete corp     |  264178414 |    255281524 |    8896890
 pool corp                |     598689 |       404057 |     194632
 spdr s&p 500 etf tr      |          0 |        39400 |     -39400
 ulta beauty inc          |          0 |        24203 |     -24203
 vanguard index fds       |          0 |        43000 |     -43000
postgresql
  • 1 个回答
  • 149 Views
Martin Hope
showkey
Asked: 2023-03-27 11:00:04 +0800 CST

如何在不询问密码的情况下使 PG_DUMP 工作?

  • 5

我在以下位置设置了 pgpassword .bashrc:

vim .bashrc 
export PGPASSWORD=pass_for_postgresql

命令不需要输入密码 psql -U postgres。当我使用以下命令将表从 db1 转储到 db2 时:

pg_dump -U postgres -t table db1 | psql -U postgres -W db2

该命令将要求我输入密码。我用谷歌搜索了一篇文章来讨论这个
http://www.londatiga.net/it/database-it/how-to-use-postgresql-pgdump-in-crontab-without-password/

使用以下格式在用户的主目录中创建一个 ~/.pgpass 文件:

hostname:port:database:username:password
Ex: localhost:5432:mydatabase:lorenz:lorensxyz

这里有很多数据库,怎么写.pgpass文件呢?

localhost:5432:db1,db2,db3,db4:postgres:pass

如何在不询问密码的情况下使 PG_DUMP 适用于所有数据库?

postgresql
  • 1 个回答
  • 27 Views
Martin Hope
showkey
Asked: 2023-03-03 16:29:31 +0800 CST

如何在第一个位置添加表格列?

  • 6

在我的 PostgreSQL 数据库中:

select index from sample;
index
---------
1
2
3
1
2

我想放置index如下:

select index from sample;
index
---------
1
2
3
4
5

萨达姆汗提供了一个解决办法:

alter table sample add column sort_id serial;
-- Drop column index from sample table.
alter table sample drop column index;
-- Rename column sort_id to index in sample table
alter table sample rename column sort_id to index;
-- Add Primary Key.
alter table sample add primary key(index);

但是现在,该index列位于右侧(表的末尾)。我怎样才能把它放在左边?

 select * from sample;
 ticker |   roe   | income  | index 
--------+---------+---------+-------
 000820 | 2347.63 |  120.16 |     1
 300071 |  676.52 | 1035.38 |     2
 002188 |  289.69 |  273.95 |     3
 600734 |  151.58 |  921.82 |     4
 000523 |  139.94 | 2585.55 |     5
 600078 |  138.28 | 3333.41 |     6
postgresql
  • 3 个回答
  • 42 Views
Martin Hope
showkey
Asked: 2023-02-26 16:16:19 +0800 CST

如何将列设置为串行类型的主键?

  • 6

在我的 postgresql 中:

select index from sample;
index
---------
1
2
3
1
2

如何将列设置index为表的序列类型的主键sample?选择的值应如下所示:

select index from sample;
index
---------
1
2
3
4
5

我试图将其添加为主键:

alter table sample add primary key (index);
ERROR:  could not create unique index "sample_pkey"
DETAIL:  Key (index)=(1) is duplicated.
Time: 1.580 ms

如何删除字段中的所有值index,并为其分配一个连续的范围或序列值?

postgresql
  • 1 个回答
  • 19 Views
Martin Hope
showkey
Asked: 2022-10-03 14:21:10 +0800 CST

如何在 PostgreSQL 中获取用户的密码?

  • 6

我以超级用户身份登录我的数据库postgres。

postgres=# SELECT *  FROM pg_user;
+----------+----------+-------------+----------+---------+--------------+----------+----------+-----------+
| usename  | usesysid | usecreatedb | usesuper | userepl | usebypassrls |  passwd  | valuntil | useconfig |
+----------+----------+-------------+----------+---------+--------------+----------+----------+-----------+
| postgres |       10 | t           | t        | t       | t            | ******** | (null;)  | (null;)   |
| test     |    24763 | f           | f        | f       | f            | ******** | (null;)  | (null;)   |
+----------+----------+-------------+----------+---------+--------------+----------+----------+-----------+
(2 rows)

我已经列出了数据库中的所有用户。如何获取普通用户的密码test?

postgresql password
  • 1 个回答
  • 857 Views
Martin Hope
showkey
Asked: 2022-01-28 03:30:13 +0800 CST

何时将 csv 数据文件导入 postgresql 时未终止的 CSV 引用字段

  • 1

创建一个表:

CREATE TABLE num (
    id serial NOT NULL ,
    adsh VARCHAR(20) NOT NULL,
    tag VARCHAR(256) NOT NULL,
    version VARCHAR(20) NOT NULL,
    coreg VARCHAR(256),
    ddate date NOT NULL,
    qtrs DECIMAL(8) NOT NULL,
    uom VARCHAR(20),
    value DECIMAL(28,4),
    footnote VARCHAR(512)
);

我想将sample.txt数据导入num表中:

adsh    tag version coreg   ddate   qtrs    uom value   footnote
0001213900-20-033598    DueToAsiyaCommunicationsSapiDeC.v.Current   0001213900-20-033598        20191231    0   USD     
0001213900-20-033598    DueToDinarZuzLLC    0001213900-20-033598        20200630    0   USD 178000.0000 Due to the April 6, 2020 180 days Loan Agreement with the Company to borrow up to $250 at an annual interest rate of nine percent (9.0%) ("the second "Dinar Zuz Note").
0001213900-20-033598    DueToNextCalaCurrent    0001213900-20-033598        20181231    0   USD -14000.0000 
0001213900-20-033598    DueToNextCalaCurrent    0001213900-20-033598        20191231    0   USD     

将数据sample.txt导入表中的命令:

COPY num(adsh,tag,version,coreg,ddate,qtrs,uom,value,footnote)
FROM 'sample.txt' 
DELIMITER E'\t'
CSV HEADER;

它遇到一个错误:

ERROR:  unterminated CSV quoted field
CONTEXT:  COPY num, line 6: "0001213900-20-033598   DueToDinarZuzLLC    0001213900-20-033598        20200630    0   USD 178000.0000 Due to the Ap..."

请在不编辑原始数据的情况下修复它。

postgresql import
  • 1 个回答
  • 1504 Views
Martin Hope
showkey
Asked: 2021-12-02 05:37:59 +0800 CST

为什么无法重置 postgres 的密码?

  • 0

我可以在没有密码的情况下登录 postgresql 数据库:

sudo -u postgres psql

现在我想为 postgres 重置密码“xxxxxxxx”:

sudo -u postgres psql
postgres=# ALTER USER postgres WITH PASSWORD 'xxxxxxxx';
ALTER ROLE
postgres=# \q
sudo passwd -d postgres
passwd: password expiry information changed.
sudo -u postgres passwd
New password: 
Retype new password: 
passwd: password updated successfully

现在重新启动 postgresql:

sudo systemctl restart postgresql

issu1:无法使用以下命令登录 postgres xxxxxxxx:

psql -d postgres  -U postgres  -W
Password: 
psql: error: FATAL:  Peer authentication failed for user "postgres"

issu2: 为什么不用密码的用户 postgres 仍然可以登录 postgres?

sudo -u postgres psql
postgresql password
  • 1 个回答
  • 243 Views
Martin Hope
showkey
Asked: 2021-11-21 00:30:57 +0800 CST

为什么不能用双引号将数据复制到csv文件中?

  • -1

可以在复制命令中使用单引号导出数据:

COPY mytest TO '/tmp/test.csv' DELIMITER ',' CSV HEADER;
COPY 5

带双引号:

COPY mytest TO "/tmp/test.csv" DELIMITER ',' CSV HEADER;
ERROR:  syntax error at or near ""/tmp/test.csv""
LINE 1: COPY mytest TO "/tmp/test.csv" DELIMITER ',' CSV HEADER;

限制使用双引号是一种奇怪的语法!

postgresql copy
  • 1 个回答
  • 1103 Views
Martin Hope
showkey
Asked: 2021-11-17 01:03:06 +0800 CST

如何使用新创建的超级用户登录 postgres?

  • 0

我创建了一个新的超级用户

sudo su - postgres
createuser --interactive --pwprompt

名字是showkey,密码是xxxxxx。

postgres=# \du+
                                           List of roles
 Role name  |                         Attributes                         | Member of | Description 
------------+------------------------------------------------------------+-----------+-------------
 dbuser     |                                                            | {}        | 
 debian     |                                                            | {}        | 
 postgres   | Superuser, Create role, Create DB, Replication, Bypass RLS | {}        | 
 showkey    | Superuser, Create role, Create DB                          | {}        | 
 test_user1 |                                                            | {}        | 

现在我想登录showkey:

psql -U showkey  -W
Password: 
psql: error: FATAL:  Peer authentication failed for user "showkey"

如何使用新创建的超级用户登录 postgres ?

postgresql psql
  • 2 个回答
  • 222 Views
Martin Hope
showkey
Asked: 2021-08-16 05:54:26 +0800 CST

可以显示create table命令中写的注释吗?

  • 0

我们可以写注释来创建一个表:

create database `mytest`;
use `mytest`;
create table `mytest` (
/* mytest mytest */ 
  `code` varchar(15) NOT NULL,
  `type` varchar(20) NOT NULL
);

如何/* mytest mytest */在创建表命令中显示注释?

show create table mytest;
+--------+------------------------------------+
| Table  | Create Table                                                                                                                  |
+--------+------------------------------------+
| mytest | CREATE TABLE `mytest` (
  `code` varchar(15) NOT NULL,
  `type` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 
mysql comments
  • 1 个回答
  • 27 Views
Martin Hope
showkey
Asked: 2017-01-30 06:33:28 +0800 CST

mysqlds 在我的 mysql 数据库中做什么?

  • 0

我在我的本地主机上构建了一个 wordpress,本地电脑无法连接到互联网。
使用命令登录mysql数据库。

mysql -u root -p
mysql> show processlist;
+-----+------+-----------+------------+---------+------+-------+------------------+
| Id  | User | Host      | db         | Command | Time | State | Info             |
+-----+------+-----------+------------+---------+------+-------+------------------+
| 385 | root | localhost | wpdatabase | Query   |    0 | NULL  | show processlist |
+-----+------+-----------+------------+---------+------+-------+------------------+
1 row in set (0.00 sec)

sudo pstree -pl  795
mysqld_safe(795)───mysqld(1188)─┬─{mysqld}(1286)
                                ├─{mysqld}(1287)
                                ├─{mysqld}(1288)
                                ├─{mysqld}(1289)
                                ├─{mysqld}(1290)
                                ├─{mysqld}(1291)
                                ├─{mysqld}(1292)
                                ├─{mysqld}(1293)
                                ├─{mysqld}(1294)
                                ├─{mysqld}(1295)
                                ├─{mysqld}(1385)
                                ├─{mysqld}(1386)
                                ├─{mysqld}(1387)
                                ├─{mysqld}(1388)
                                ├─{mysqld}(1403)
                                ├─{mysqld}(1420)
                                ├─{mysqld}(3435)
                                └─{mysqld}(22796)

mysqlds那么多,为什么show processlist列不出来?

mysql
  • 1 个回答
  • 40 Views
Martin Hope
showkey
Asked: 2015-10-13 16:53:26 +0800 CST

为什么 mysql MSI 安装程序比 wamp 安装程序包大小更大?

  • 0

在http://dev.mysql.com/downloads/windows/installer/5.6.html中,可以得到Windows (x86, 32-bit), MSI Installer 大小为252.6M。
在http://sourceforge.net/projects/wampserver/files/中,你可以得到只有39.8M大小的wampserver安装包。我对 wampserver 包含 apache\mysql\php 感到困惑,为什么 1+1+1<1?

mysql wamp
  • 1 个回答
  • 167 Views
Martin Hope
showkey
Asked: 2015-04-11 17:15:26 +0800 CST

字符'和`在mysql命令中是否相等?

  • 1
mysql> select 'user_url' from wp_users;
mysql> select `user_url` from wp_users;

可以得到相同的结果,字符'和`在mysql命令中是否相等?

mysql
  • 1 个回答
  • 28 Views
Martin Hope
showkey
Asked: 2015-04-10 00:56:40 +0800 CST

如何从远程机器连接到我的 vps 中的数据库?

  • 1

我已经在我的 VPS IP 上安装了 MySQL,并发出了以下命令:

mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'%'IDENTIFIED BY 'passwd' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

service mysql restart

现在我想从远程机器上用我的 VPS IP 登录 MySQL。

mysql -h vpsip -P 3306 -u root -ppasswd

ERROR 2003 (HY000): Can't connect to MySQL server on 'vpsip' (111)

为什么无法登录?如何从远程机器连接到 MySQL?

mysql
  • 1 个回答
  • 3307 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve