我试过这个:
create or replace function c3 (arg char(3))
returns void
language plpgsql as
$$
begin
raise notice 'Value: %', arg;
end;
$$;
但它接受三个以上的字符:
select c3('1234');
我试过这个:
create or replace function c3 (arg char(3))
returns void
language plpgsql as
$$
begin
raise notice 'Value: %', arg;
end;
$$;
但它接受三个以上的字符:
select c3('1234');
我正在使用此语句从另一个表插入记录:
SQL> insert into city(city_code, country_code, city)
select distinct(city_code), country_code, city_name
from airport_final;
2 3
9012 rows created.
我发现很多重复的记录:
SQL> SELECT city_code, COUNT(city_code)
FROM airport_final
GROUP BY city_code
HAVING COUNT(city_code) > 1;
VRA 2
WBU 3
YMQ 4
YPR 2
330 rows selected.
我不知道我正在选择不同的记录,但为什么它会插入重复项
此致
我使用复制监视器进行了查看,它向我显示了正在等待复制的命令:
我的问题是 - 我如何找出这些命令是什么?
我已经尝试过本·安德森的这个查询
select @@Servername,a.publication + ':' + s.srvname as [Agent],
v.undelivcmdsindistdb,
v.delivcmdsindistdb,
a.id
from distribution.dbo.msdistribution_status v
join distribution.dbo.msdistribution_agents a on v.agent_id = a.id
join master.dbo.sysservers s on a.subscriber_id = s.srvid
where v.undelivcmdsindistdb > 0
但数字并不完全匹配,尽管这绝对是一个好的开始,有没有办法我可以找到有关这些记录的更多信息?
创建由“Test”标识的用户 TESTING;
grant connect, resource to TESTING;
grant dba to TESTING;
connect TESTING/Test;
set define off;
create table airport_final
(
iata_code varchar2(3),
city_code varchar2(3),
city_name nvarchar2(24),
country_code varchar2(2),
country_name nvarchar2(33),
no_of_airports number(1),
airport_code varchar2(3),
city_with_country nvarchar2(61),
airport_name nvarchar2(80)
);
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('YVE','YVE', 'Vernon', 'CA', 'Canada');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('ZZW','ZZW', 'Day Trip Mystery', 'PG', 'Australia');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('VRA','VRA', 'Varadero', 'CU', 'Cuba');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('VRO','VRA', 'Varadero', 'CU', 'Cuba');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('BOL','BOL', 'Ballykelly', 'PG', 'United Kingdom');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('BMV','BMV', 'Buon Ma Thuot', 'PG', 'Vietnam');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('WBI','WBU', 'Boulder', 'US', 'United States');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('WBU','WBU', 'Boulder', 'US', 'United States');
INSERT INTO airport_final(iata_code, city_code, city_name, country_code, country_name)
VALUES ('WHH','WBU', 'Boulder', 'US', 'United States');
commit;
select iata_code, city_code, city_name, country_code, country_name from airport_final where city_code='VRA';
create table city(
city_code varchar2(3),
country_code varchar2(3),
city varchar2(24)
);
我已将数据从 CSV 文件插入到 oracle 表中airport_final
,并希望使用此语句将特定列插入到表 city 中
SQL> insert
into city(city_code, country_code,city)
with t as (
select distinct c.country_code,
a.city_name,
a.city_code
from airport_final a,
city c
where c.city_code = a.city_code
)
select
city_code,
country_code,
city_name
from t
/
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0 rows created.
该语句没有插入数据请告知如何从另一个表插入特定列数据
此致
当我读到“坚持”时,我仍然不明白它。
在sql server中的特定表中使用SQL代码“持久化”有什么好处。
当我使用sql代码“persisted”时我会得到什么值?
谢谢你!
作为公司所有者,我需要保护我的敏感数据免受网站/CRM 程序员的侵害。我知道我可以用一个简单的脚本来打乱数据库值,但它需要始终手动应用,当他们需要深入研究数据库结构时,他们可能会因为无法完全控制实际的数据库数据而感到恼火。
专业人士如何解决这个问题?
Postgres LATERAL JOIN 的 ON 谓词如何工作?
让我澄清一下问题。我已经阅读了官方文档和一堆关于这种 JOIN 的文章。据我了解,它是一个带有相关子查询的 foreach 循环 - 它迭代表 A 的所有记录,允许引用相关子查询 B 中“当前”行的列并将 B 的结果集连接到A 的“当前”行 - 如果 B 查询返回 1 行,则只有一对,如果 B 查询返回 N 行,则有 N 对与 A 的重复“当前”行。与通常的 JOIN 中的行为相同。
但为什么需要 ON 谓词呢?对我来说,在通常的 JOIN 中,我们使用 ON ,因为我们有 2 个表的笛卡尔积需要过滤掉,而 LATERAL JOIN 的情况则不同,后者直接生成结果对。换句话说,在我的开发经验中,我只见过 CROSS JOIN LATERAL 和 LEFT JOIN LATERAL () ON TRUE (不过后者看起来相当笨拙),但有一天,一位同事向我展示了
SELECT
r.acceptance_status, count(*) as count
FROM route r
LEFT JOIN LATERAL (
SELECT rts.route_id, array_agg(rts.shipment_id) shipment_ids
FROM route_to_shipment rts
where rts.route_id = r.route_id
GROUP BY rts.route_id
) rts using (route_id)
这让我大吃一惊。为什么using (route_id)
?我们已经有了where rts.route_id = r.route_id
子查询!也许我对横向连接机制的理解错误?
我搞砸了一个 Dockerized PostgreSQL 实例,并且意外地覆盖了POSTGRES_USER
和 的值POSTGRES_PASSWORD
。它们是随机生成的,所以猜测它们基本上是不可能的。根据 Dockerized PostgreSQL 的性质,如果您指定自己的用户名,则postgres
不会创建该角色。这意味着postgres
、admin
、root
在我的数据库实例上都是无效角色。
现在,我被困在一个我可以访问的卷中的一个数据目录和一个psql
我无法访问的数据目录,因为我不知道该数据库上的任何有效用户名。此数据目录中是否有用户名列表,我可以通过某种方式访问该用户名列表并更改密码?
我有以下函数用于创建 PostgreSQL 数据库psycopg
:
def create_database() -> None:
"""A function for creating a PostgreSQL database."""
db_name = ('test_db',)
sql_1 = """SELECT datname FROM pg_database"""
sql_2 = """CREATE DATABASE %s"""
with connect('create') as conn:
try:
cur = conn.cursor()
cur.execute(sql_1)
databases = cur.fetchall()
if db_name in databases:
print(f'Database named {db_name[0]} already exists.')
else:
cur.execute(sql_2, db_name)
cur.close()
print('Creating database...')
conn.commit()
print('Database created.')
except (Exception, DatabaseError) as error:
print(error, '\n-> Could not create database.')
它给出以下错误:
syntax error at or near "$1"
LINE 1: CREATE DATABASE $1
^
-> Could not create database.
问题是什么?
我正在使用 PostgreSQL。我曾尝试构建一个专门使用可串行化事务的系统,希望它能简化我的应用程序开发。我已将只读事务标记为 READ ONLY。然而,我的写入经常与只读查询获取的 SIReadLock 发生争用,从而将写入变成连续重试。从那时起,我就以 READ COMMITTED 方式运行只读查询,现在一切都运行顺利。
现在我想知道 - 如果事务是只读的,也就是说,如果我在隔离级别“可重复读取”下运行查询,可能会发生什么序列化异常,并且可以通过“可串行化”(及其相关成本)来防止?我很难想出一个例子来说明这种情况下所提供的好处。