一、
psycopg2简介
psycopg2库是python的一个可直接操作postgresql数据库的类库,是一个用于Python编程语言的PostgreSQL数据库适配器。它允许开发人员使用Python语言与PostgreSQL数据库进行交互和操作,不同于java,需要专用的一个驱动,psycopg2就等于是一个驱动类,可以非常方便的与postgresql数据库交互,当然了,如果有大量的数据库更新语句或者维护语句,psycopg2也可以非常方便快速的完成。
本文主要是以一个实际的例子来说明如何使用psycopg2批量执行SQL文件
二、
psycopg2的安装
在进行psycopg2的安装前,也看了不少的资料,但大部分都是通过pip这个python的包管理器来安装,而pip是需要互联网,并不能离线化实现,其实Linux的社区对于python的环境支持是非常友好的,因此,本文是以rpm安装psycopg2为主,实验用的服务器是centos7,python的版本是3.6
为什么是python3而不是python2呢?其实主要的原因是python3对于中文字符的支持更加友好,python程序的调试更为简单,仅此而已
因此,整个实验过程使用的是centos7+python3.6+postgresql12+psycopg2-2.8.4-5
yum install -y python3-psycopg2* python36
离线安装包如下:
通过网盘分享的文件:psycopg2-3.6.tar.gz
链接: https://pan.baidu.com/s/17Ac_3fDOfMH58OtceZHchA?pwd=83tr 提取码: 83tr
解压psycopg2-3.6.tar.gz 这个文件,然后配置成本地仓库就可以了,仓库如何配置就不在这里废话了,太基础的东西,免得耽误大家时间
三、
数据库连接信息文件和程序源码
这里采用json文件的形式,python读取json文件,取json中的字典信息,不直接在程序内写数据库的连接信息也是由于数据库的一些信息比较敏感,出于安全方面的考虑
这里我用的json名字是test.json 文件内容如下:
cat > /root/test.json <<EXF
{
"db_config": {
"dbname": "postgres",
"user": "postgres",
"password": "XXXXXXXXXXXXX",
"host": "192.168.123.17",
"port": "5432"
}
}
EXF
这里还是需要简单说明一下,dbname是将要连接到哪个数据库,数据库服务器的IP地址是192.168.123.17,port时postgreslq数据库的连接端口,默认时5432,本次实验数据库的端口没有更改,因此,是默认的,连接时使用的user和password都是明文形式,但该json文件可以给予适当权限以保护数据库的安全
下面是非常重要的程序源码了,内容如下:
cat >test6.py <<EOF
import os
import time
import sys
import json
import psycopg2
from psycopg2 import sql, OperationalError, ProgrammingError
def print_colored_text(text, color_code):
"""打印带有颜色的文本"""
print(f"\033[{color_code}m{text}\033[0m")
# 定义颜色代码
COLORS = {
'BLACK': 30,
'RED': 31,
'GREEN': 32,
'YELLOW': 33,
'BLUE': 34,
'MAGENTA': 35,
'CYAN': 36,
'WHITE': 37
}
#def find_sql_files(path):
# """查找指定路径下的所有 .sql 文件"""
# for root, dirs, files in os.walk(path):
# for file in files:
# if file.endswith('.sql'):
# yield os.path.join(root, file)
def find_sql_files(path):
"""查找指定路径下的所有 .sql 文件,并按顺序排序返回列表"""
sql_files = []
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith('.sql'):
sql_files.append(os.path.join(root, file))
# 对文件路径进行排序
sql_files.sort()
return sql_files
def execute_sql_file(db_config, sql_file_path):
"""执行指定的 SQL 文件"""
conn = None
cursor = None
try:
conn = psycopg2.connect(**db_config)
cursor = conn.cursor()
with open(sql_file_path, 'r', encoding='utf-8') as file:
sql_statements = file.read().strip().split(';')
for stmt in sql_statements:
stripped_stmt = stmt.strip()
if stripped_stmt:
print(stripped_stmt)
print_colored_text('<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****', COLORS['CYAN'])
try:
cursor.execute(sql.SQL(stripped_stmt))
# 根据需要决定是否提交事务
# conn.commit() # 如果每条语句都需要单独提交,则取消注释
print_colored_text(f'执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||',COLORS['GREEN'])
except (Exception, psycopg2.DatabaseError) as e:
print(f'执行失败: {stripped_stmt}')
conn.rollback() # 回滚事务
sys.exit(1) # 或者选择记录错误并继续执行
# 如果所有语句都成功执行,最后提交事务,以整个SQL文件为一个事务
conn.commit()
print_colored_text(f"Executed SQL file successfully: {sql_file_path}",COLORS['RED'])
return True
except (OperationalError, ProgrammingError) as error:
print(f"Error executing SQL file {sql_file_path}: {error}")
if conn:
conn.rollback()
return False
finally:
if cursor:
cursor.close()
if conn:
conn.close()
def main():
if len(sys.argv) != 3:
print("Usage: python script.py <user> <path_to_search>")
sys.exit(1)
user = sys.argv[1]
search_path = sys.argv[2]
try:
with open('test.json', 'r', encoding='utf-8') as f:
params = json.load(f)
db_config = params.get('db_config', {})
required_keys = ['dbname', 'user', 'password', 'host', 'port']
if not all(key in db_config for key in required_keys):
print("Error: Missing required database configuration in test.json")
sys.exit(1)
db_config['user'] = user
except FileNotFoundError:
print("Error: test.json not found")
sys.exit(1)
except json.JSONDecodeError:
print("Error: test.json is not a valid JSON file")
sys.exit(1)
sql_files = list(find_sql_files(search_path))
print(f"Found {len(sql_files)} SQL files: {sql_files}")
print_colored_text(f'|||||二十秒后开始执行{sql_files},以打印出来的顺序依次执行SQL文件|||||||||||',COLORS['MAGENTA'])
#time.sleep(20)
if sql_files:
for sql_file in sql_files:
print_colored_text(f'这个文件将要执行: {sql_file}\n\n', COLORS['YELLOW'])
if not execute_sql_file(db_config, sql_file):
print(f"Failed to execute SQL file: {sql_file}. Exiting...")
sys.exit(1)
else:
print("No SQL files found in the specified path.")
if __name__ == "__main__":
main()
EOF
说明:
(1)
程序的延时
print_colored_text(f'|||||二十秒后开始执行{sql_files},以打印出来的顺序依次执行SQL文件|||||||||||',COLORS['MAGENTA'])
#time.sleep(20)
这里time.sleep函数是注释的,意思程序暂停20秒,以确定文件顺序是否正常,可以放开注释,此时程序会有20秒延迟,主要是一个确认SQL文件排序是否正确的确认时间
(2)
导包说明
import os
import time
import sys
import json
import psycopg2
from psycopg2 import sql, OperationalError, ProgrammingError
导的包里面,json,time,os,sys都是系统自带的,无需额外安装,前面的环境,只是安装了python3和psycopg2,最后一行是抛出异常用的
(3)
颜色修饰函数
def print_colored_text(text, color_code):
"""打印带有颜色的文本"""
print(f"\033[{color_code}m{text}\033[0m")
# 定义颜色代码
COLORS = {
'BLACK': 30,
'RED': 31,
'GREEN': 32,
'YELLOW': 33,
'BLUE': 34,
'MAGENTA': 35,
'CYAN': 36,
'WHITE': 37
}
这个是一个颜色函数,主要作用是美化代码,Linux的命令行比较单调,并且,有些内容需要醒目的颜色突出显示,比如执行的SQL文件名称,下面修饰成了红色
(4)
搜寻SQL文件函数
搜寻指定路径下的所有需要执行的SQL文件,这里用了sort排序函数,并且return了该排序,这里是一个列表,也就是list输出
def find_sql_files(path):
"""查找指定路径下的所有 .sql 文件,并按顺序排序返回列表"""
sql_files = []
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith('.sql'):
sql_files.append(os.path.join(root, file))
# 对文件路径进行排序
sql_files.sort()
return sql_files
(5)
SQL语句执行函数
这里是执行指定SQL文件的逻辑部分,也就是真正干活的代码,因为 print_colored_text这个函数是写在上面的,而python执行的顺序是顺序执行的,因此,可以调用得到,部分关键输出用了 print_colored_text函数来修饰
这里需要注意的是,提交和回滚,提交是整个SQL文件内的所有语句,回滚是单独一条SQL语句,也就是说,提交和回滚的位置大家可以仔细思考,为什么是这么写的
执行语句失败的话,打印是哪条SQL语句失败,并立即回滚整个事务,以保证数据库的安全
def execute_sql_file(db_config, sql_file_path):
"""执行指定的 SQL 文件"""
conn = None
cursor = None
try:
conn = psycopg2.connect(**db_config)
cursor = conn.cursor()
with open(sql_file_path, 'r', encoding='utf-8') as file:
sql_statements = file.read().strip().split(';')
for stmt in sql_statements:
stripped_stmt = stmt.strip()
if stripped_stmt:
print(stripped_stmt)
print_colored_text('<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****', COLORS['CYAN'])
try:
cursor.execute(sql.SQL(stripped_stmt))
# 根据需要决定是否提交事务
# conn.commit() # 如果每条语句都需要单独提交,则取消注释
print_colored_text(f'执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||',COLORS['GREEN'])
except (Exception, psycopg2.DatabaseError) as e:
print(f'执行失败: {stripped_stmt}')
conn.rollback() # 回滚事务
sys.exit(1) # 或者选择记录错误并继续执行
# 如果所有语句都成功执行,最后提交事务,以整个SQL文件为一个事务
conn.commit()
print_colored_text(f"Executed SQL file successfully: {sql_file_path}",COLORS['RED'])
return True
except (OperationalError, ProgrammingError) as error:
print(f"Error executing SQL file {sql_file_path}: {error}")
if conn:
conn.rollback()
return False
finally:
if cursor:
cursor.close()
if conn:
conn.close()
(6)
主函数--程序的整体逻辑封装
主要是上面的函数调用逻辑,这里需要指出json文件可以写成绝对路径,这里是相对路径
对于json文件是否存在或者内容有误的情况,分别做了异常抛出
对于SQL文件是否存在以及是否正常执行完,分别做了判断,并分别抛出了异常
def main():
if len(sys.argv) != 3:
print("Usage: python script.py <user> <path_to_search>")
sys.exit(1)
user = sys.argv[1]
search_path = sys.argv[2]
try:
with open('test.json', 'r', encoding='utf-8') as f:
params = json.load(f)
db_config = params.get('db_config', {})
required_keys = ['dbname', 'user', 'password', 'host', 'port']
if not all(key in db_config for key in required_keys):
print("Error: Missing required database configuration in test.json")
sys.exit(1)
db_config['user'] = user
except FileNotFoundError:
print("Error: test.json not found")
sys.exit(1)
except json.JSONDecodeError:
print("Error: test.json is not a valid JSON file")
sys.exit(1)
sql_files = list(find_sql_files(search_path))
print(f"Found {len(sql_files)} SQL files: {sql_files}")
print_colored_text(f'|||||二十秒后开始执行{sql_files},以打印出来的顺序依次执行SQL文件|||||||||||',COLORS['MAGENTA'])
#time.sleep(20)
if sql_files:
for sql_file in sql_files:
print_colored_text(f'这个文件将要执行: {sql_file}\n\n', COLORS['YELLOW'])
if not execute_sql_file(db_config, sql_file):
print(f"Failed to execute SQL file: {sql_file}. Exiting...")
sys.exit(1)
else:
print("No SQL files found in the specified path.")
if __name__ == "__main__":
main()
四、
程序测试
1、
json文件里的password错误时
可以看到,正常抛出异常,程序正常停止,并且标识是执行哪个SQL文件时出错的,测试使用的SQL语句存放目录时sql_dir 里面有四个文件,全部是绝对路径打印,完全正确
[root@centos6 ~]# python3 test6.py postgres sql_dir/
Found 4 SQL files: ['sql_dir/11111.sql', 'sql_dir/22222.sql', 'sql_dir/3333.sql', 'sql_dir/roles.sql']
|||||二十秒后开始执行['sql_dir/11111.sql', 'sql_dir/22222.sql', 'sql_dir/3333.sql', 'sql_dir/roles.sql'],以打印出来的顺序依次执行SQL文件|||||||||||
这个文件将要执行: sql_dir/11111.sql
Error executing SQL file sql_dir/11111.sql: connection to server at "192.168.123.17", port 5432 failed: FATAL: password authentication failed for user "postgres"
Failed to execute SQL file: sql_dir/11111.sql. Exiting...
2、
json文件格式有误的测试
任意删除json文件内的某一行,直接报错,测试通过
[root@centos6 ~]# python3 test6.py postgres sql_dir/
Error: test.json is not a valid JSON file
3、
顺序测试
第二个文件内容修改成错误的,看是否可以正常完成
可以看到,第二个文件是建表语句,id的属性是int422 ,因此,该条语句未成功执行,所有执行回退了,并且后面的SQL文件也没有执行,完美符合设计预期
[root@centos6 ~]# python3 test6.py postgres sql_dir/
Found 4 SQL files: ['sql_dir/11111.sql', 'sql_dir/22222.sql', 'sql_dir/3333.sql', 'sql_dir/roles.sql']
|||||二十秒后开始执行['sql_dir/11111.sql', 'sql_dir/22222.sql', 'sql_dir/3333.sql', 'sql_dir/roles.sql'],以打印出来的顺序依次执行SQL文件|||||||||||
这个文件将要执行: sql_dir/11111.sql
CREATE SEQUENCE if not exists my_table1_id_seq
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
Executed SQL file successfully: sql_dir/11111.sql
这个文件将要执行: sql_dir/22222.sql
DROP TABLE IF EXISTS "public"."my_table1"
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
CREATE TABLE "public"."my_table1" (
"id" int422 NOT NULL DEFAULT nextval('my_table1_id_seq'::regclass),
"first_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"last_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"age" int4 NOT NULL,
"gender" char(1) COLLATE "pg_catalog"."default",
"is_active" bool DEFAULT true,
"birth_date" date,
"city" varchar(100) COLLATE "pg_catalog"."default",
"phone_number" varchar(20) COLLATE "pg_catalog"."default",
"email" varchar(100) COLLATE "pg_catalog"."default",
"street_address" varchar(255) COLLATE "pg_catalog"."default",
"apartment_number" varchar(10) COLLATE "pg_catalog"."default",
"state" varchar(50) COLLATE "pg_catalog"."default",
"postal_code" varchar(20) COLLATE "pg_catalog"."default",
"country" varchar(100) COLLATE "pg_catalog"."default",
"international_phone_code" varchar(10) COLLATE "pg_catalog"."default",
"preferred_language" varchar(50) COLLATE "pg_catalog"."default",
"highest_education" varchar(100) COLLATE "pg_catalog"."default",
"field_of_study" varchar(100) COLLATE "pg_catalog"."default",
"employment_status" varchar(50) COLLATE "pg_catalog"."default",
"employer_name" varchar(100) COLLATE "pg_catalog"."default",
"annual_income" numeric(10,2),
"employment_type" varchar(50) COLLATE "pg_catalog"."default",
"hire_date" date,
"status" varchar(50) COLLATE "pg_catalog"."default",
"binary_flag" bit(8)
)
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行失败: CREATE TABLE "public"."my_table1" (
"id" int422 NOT NULL DEFAULT nextval('my_table1_id_seq'::regclass),
"first_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"last_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"age" int4 NOT NULL,
"gender" char(1) COLLATE "pg_catalog"."default",
"is_active" bool DEFAULT true,
"birth_date" date,
"city" varchar(100) COLLATE "pg_catalog"."default",
"phone_number" varchar(20) COLLATE "pg_catalog"."default",
"email" varchar(100) COLLATE "pg_catalog"."default",
"street_address" varchar(255) COLLATE "pg_catalog"."default",
"apartment_number" varchar(10) COLLATE "pg_catalog"."default",
"state" varchar(50) COLLATE "pg_catalog"."default",
"postal_code" varchar(20) COLLATE "pg_catalog"."default",
"country" varchar(100) COLLATE "pg_catalog"."default",
"international_phone_code" varchar(10) COLLATE "pg_catalog"."default",
"preferred_language" varchar(50) COLLATE "pg_catalog"."default",
"highest_education" varchar(100) COLLATE "pg_catalog"."default",
"field_of_study" varchar(100) COLLATE "pg_catalog"."default",
"employment_status" varchar(50) COLLATE "pg_catalog"."default",
"employer_name" varchar(100) COLLATE "pg_catalog"."default",
"annual_income" numeric(10,2),
"employment_type" varchar(50) COLLATE "pg_catalog"."default",
"hire_date" date,
"status" varchar(50) COLLATE "pg_catalog"."default",
"binary_flag" bit(8)
)
4、
所有成功执行的测试
执行的命令是python3 程序名称 数据库用户 SQL文件存放路径(可相对路径也可以绝对路径)总共是两个参数
当然,最后一个文件还是执行失败了,但在数据库内可以看到 1 2 3 文件内执行成功的都提交了,是可以看到mytabls1这个表的内容的,第四个文件整个回退了
整个测试完成
-bash-4.2$ python3 test6.py postgres sql_dir/
Found 4 SQL files: ['sql_dir/11111.sql', 'sql_dir/22222.sql', 'sql_dir/3333.sql', 'sql_dir/roles.sql']
|||||二十秒后开始执行['sql_dir/11111.sql', 'sql_dir/22222.sql', 'sql_dir/3333.sql', 'sql_dir/roles.sql'],以打印出来的顺序依次执行SQL文件|||||||||||
这个文件将要执行: sql_dir/11111.sql
CREATE SEQUENCE if not exists my_table1_id_seq
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
Executed SQL file successfully: sql_dir/11111.sql
这个文件将要执行: sql_dir/22222.sql
DROP TABLE IF EXISTS "public"."my_table1"
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
CREATE TABLE "public"."my_table1" (
"id" int4 NOT NULL DEFAULT nextval('my_table1_id_seq'::regclass),
"first_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"last_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"age" int4 NOT NULL,
"gender" char(1) COLLATE "pg_catalog"."default",
"is_active" bool DEFAULT true,
"birth_date" date,
"city" varchar(100) COLLATE "pg_catalog"."default",
"phone_number" varchar(20) COLLATE "pg_catalog"."default",
"email" varchar(100) COLLATE "pg_catalog"."default",
"street_address" varchar(255) COLLATE "pg_catalog"."default",
"apartment_number" varchar(10) COLLATE "pg_catalog"."default",
"state" varchar(50) COLLATE "pg_catalog"."default",
"postal_code" varchar(20) COLLATE "pg_catalog"."default",
"country" varchar(100) COLLATE "pg_catalog"."default",
"international_phone_code" varchar(10) COLLATE "pg_catalog"."default",
"preferred_language" varchar(50) COLLATE "pg_catalog"."default",
"highest_education" varchar(100) COLLATE "pg_catalog"."default",
"field_of_study" varchar(100) COLLATE "pg_catalog"."default",
"employment_status" varchar(50) COLLATE "pg_catalog"."default",
"employer_name" varchar(100) COLLATE "pg_catalog"."default",
"annual_income" numeric(10,2),
"employment_type" varchar(50) COLLATE "pg_catalog"."default",
"hire_date" date,
"status" varchar(50) COLLATE "pg_catalog"."default",
"binary_flag" bit(8)
)
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
-- ----------------------------
-- Uniques structure for table my_table1
-- ----------------------------
ALTER TABLE "public"."my_table1" ADD CONSTRAINT "my_table1_email_key" UNIQUE ("email")
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
-- ----------------------------
-- Primary Key structure for table my_table1
-- ----------------------------
ALTER TABLE "public"."my_table1" ADD CONSTRAINT "my_table1_pkey" PRIMARY KEY ("id")
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
Executed SQL file successfully: sql_dir/22222.sql
这个文件将要执行: sql_dir/3333.sql
INSERT INTO "public"."my_table1" VALUES (41, 'Charlie', 'Brown', 40, 'M', 'f', '1983-03-30', 'Chicago', '555-555-5555', 'charlie1.brown@example.com', '789 Oak St', 'Apt 3C', 'IL', '60601', 'USA', '+1', 'French', 'PhD', 'Physics', 'Self-employed', 'Consulting Firm', 120000.00, 'Contract', '2019-08-20', 'On Leave', '11111111')
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
INSERT INTO "public"."my_table1" VALUES (42, 'Diana', 'Prince', 35, 'F', 't', '1988-04-10', 'Houston', '444-444-4444', 'diana1.prince@example.com', '321 Pine St', 'House 23', 'TX', '77001', 'USA', '+1', 'German', 'Doctorate', 'Chemistry', 'Employed', 'Academic Inst', 80000.00, 'Full-time', '2021-03-10', 'Active', '10010010')
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
INSERT INTO "public"."my_table1" VALUES (43, 'Eve', 'Adams', 28, 'F', 't', '1995-05-25', 'Phoenix', '333-333-3333', 'eve.adams1@example.com', '654 Maple St', 'Apt 1A', 'AZ', '85001', 'USA', '+1', 'Italian', 'Undergraduate', 'Psychology', 'Employed', 'Non-Profit Org', 50000.00, 'Part-time', '2022-07-01', 'Active', '00110011')
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
INSERT INTO "public"."my_table1" VALUES (40, 'Alice', 'Johnson', 30, 'M', 't', '1998-02-20', 'Los Angeles', '098-765-4321', 'bob1.johnson@example.com', '456 Elm St', NULL, 'CA', '90001', 'USA', '+1', 'Spanish', 'Masters', 'Business Administration', 'Unemployed', NULL, NULL, NULL, '2022-01-15', 'Inactive', '01010101')
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
INSERT INTO "public"."my_table1" VALUES (39, 'Alice', 'Smith', 30, 'F', 't', '1993-01-15', 'New York', '123-456-7890', 'alic1e.smith@example.com', '123 Main St33333324234二位威风威风地方大师傅 第三方多少范德萨发生的', 'Apt 4B', 'NY', '10001', 'USA', '+1', 'English', 'Bachelor', 'Computer Science', 'Employed', 'TechCorp', 75000.00, 'Full-time', '2020-06-01', 'Active', '10101010')
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
Executed SQL file successfully: sql_dir/3333.sql
这个文件将要执行: sql_dir/roles.sql
--
-- PostgreSQL database cluster dump
--
SET default_transaction_read_only = off
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
SET client_encoding = 'UTF8'
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
SET standard_conforming_strings = on
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行成功,啦啦啦啦啦啦啦啦啦啦!~~~~~~~~~~~~~~~~=====================~~~~~~~~~~~~~~~|||||||||
--
-- Roles
--
CREATE ROLE module20_pms
<<<<<<<=======<<<<<++++++++<<<<<<上面这条语句将要执行了===----========*****
执行失败: --
-- Roles
--
CREATE ROLE module20_pms