postgresql - 如何删除 PostgreSQL 转储中的 LANGUAGE c 函数以导入 CloudSQL?
问题描述
我想将 Postgres 转储导入 CloudSQL。我实际上使用了uuid-ossp
扩展,语言 c 中的一些函数被导出到我的转储中。
但是......云SQL https://cloud.google.com/sql/docs/postgres/extensions#languageLANGUAGE c
上不允许使用函数,我需要将它们从转储中删除。(注意,这些功能可以通过激活 cloudSQL 数据库中的扩展 uuid-ossp 来重新启用)
所以......我需要一个技巧来从我的转储文件中删除这些函数。
从包含这些函数的转储中提取:
--
-- TOC entry 542 (class 1255 OID 16529)
-- Name: uuid_generate_v1(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_generate_v1() RETURNS uuid
LANGUAGE c STRICT
AS '$libdir/uuid-ossp', 'uuid_generate_v1';
--
-- TOC entry 543 (class 1255 OID 16530)
-- Name: uuid_generate_v1mc(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_generate_v1mc() RETURNS uuid
LANGUAGE c STRICT
AS '$libdir/uuid-ossp', 'uuid_generate_v1mc';
--
-- TOC entry 544 (class 1255 OID 16531)
-- Name: uuid_generate_v3(uuid, text); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_generate_v3(namespace uuid, name text) RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_generate_v3';
--
-- TOC entry 545 (class 1255 OID 16532)
-- Name: uuid_generate_v4(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_generate_v4() RETURNS uuid
LANGUAGE c STRICT
AS '$libdir/uuid-ossp', 'uuid_generate_v4';
--
-- TOC entry 546 (class 1255 OID 16533)
-- Name: uuid_generate_v5(uuid, text); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_generate_v5(namespace uuid, name text) RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_generate_v5';
--
-- TOC entry 547 (class 1255 OID 16534)
-- Name: uuid_nil(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_nil() RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_nil';
--
-- TOC entry 548 (class 1255 OID 16535)
-- Name: uuid_ns_dns(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_ns_dns() RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_ns_dns';
--
-- TOC entry 549 (class 1255 OID 16536)
-- Name: uuid_ns_oid(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_ns_oid() RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_ns_oid';
--
-- TOC entry 550 (class 1255 OID 16537)
-- Name: uuid_ns_url(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_ns_url() RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_ns_url';
--
-- TOC entry 512 (class 1255 OID 16538)
-- Name: uuid_ns_x500(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION uuid_ns_x500() RETURNS uuid
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/uuid-ossp', 'uuid_ns_x500';
解决方案
解决方案 1:清理数据库并重新导出转储
(根据@Laurenz Albe 评论编辑)
DROP FUNCTION
对所有LANGUAGE c
功能执行 a- 转储数据库
CREATE EXTENSION uuid-ossp
在转储开始处添加
解决方案 2:解析并清理转储
不是最好的,但似乎有效。
这是基于这样一个事实,幸运的是,想要删除的功能位于 3 行:
# Extract all the language c functions (1 line before and 1 line after the "LANGUAGE c" line
grep -B 1 -A 1 "LANGUAGE c" schema.sql > language-c-functions.sql
# Make the diff between the files, and keep line that are not in both files
diff schema.sql language-c-functions.sql | grep \^\< | sed 's/^<\ //' > cleaned.sql
推荐阅读
- devexpress - DevExpress 和 Syncfusion
- scikit-learn - Python - RandomForestClassifier 和 XGBClassifier 具有完全相同的分数
- powerbi - 将 CSV 数据转换为 DAX 表
- node.js - 使用 Axios 创建文件系统缓存以在全局缓存 API 请求
- laravel - Laravel Vapor CLI 登录中止且没有错误。如何登录?
- selenium - java.lang.AssertionError:比较预期的错误消息
- r - 如何修复R中的行引用
- sql - 如何从 SQL 表中选择条目数中第 N 位的元素?
- mysql - 我如何通过使用 distinct 计算每个 productID 并单独显示
- java - 无法终止侦听端口 8080 的 java 进程