首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何删除PostgreSQL转储中用于在CloudSQL中导入的语言c函数?

问如何删除PostgreSQL转储中用于在CloudSQL中导入的语言c函数?
EN

Stack Overflow用户
提问于 2018-12-14 13:17:31
回答 1查看 330关注 0票数 1

我想将Postgres转储导入到CloudSQL中。实际上,我使用了uuid-ossp扩展,并将c语言中的一些函数导出到我的转储。

然而..。LANGUAGE c中的函数在云SQL https://cloud.google.com/sql/docs/postgres/extensions#language上是不允许的,我需要从转储中删除它们。(请注意,以后可以通过激活cloudSQL数据库中的扩展uuid重新启用这些函数)

所以..。我需要一个技巧来从我的转储文件中删除这些函数。

从转储中提取的包含以下功能:

代码语言:javascript
复制
--
-- 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';
EN

回答 1

Stack Overflow用户

发布于 2018-12-14 13:17:31

解决方案1:清理数据库并重新导出转储

(编辑:@Laurenz Albe注释)

  1. 对所有DROP FUNCTION函数执行LANGUAGE c
  2. 转储数据库
  3. 在转储处添加CREATE EXTENSION uuid-ossp

解决方案2:解析和清理转储

不是最好的,但似乎很管用。

这是基于这样一个事实:幸运的是,想要删除的函数有3行:

代码语言:javascript
复制
# 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53780554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档