Last active
September 24, 2023 05:27
-
-
Save portnov/215b3effc980be5f7dabc3bbc5144849 to your computer and use it in GitHub Desktop.
Dumping functions that reference other schmas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create schema portnov; | |
create schema s1; | |
set search_path = "$user", s1, public; | |
create domain s1.mytype as text; | |
create or replace function portnov.my_value(id int) returns mytype as $$ | |
declare | |
var mytype; | |
begin | |
var := 'my value' || id::mytype; | |
return var; | |
end | |
$$ language plpgsql immutable; | |
select my_value(1); | |
-- my_value1 | |
create table tst_data ( | |
id int primary key, | |
x int not null, | |
y mytype not null generated always as (my_value(id)) stored | |
); | |
insert into tst_data (id, x) values (1, 7); | |
select * from tst_data; | |
/* | |
id|x|y | | |
--+-+---------+ | |
1|7|my value1| | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- PostgreSQL database dump | |
-- | |
-- Dumped from database version 15.2 (Ubuntu 15.2-1.pgdg20.04+1) | |
-- Dumped by pg_dump version 15.2 (Ubuntu 15.2-1.pgdg20.04+1) | |
SET statement_timeout = 0; | |
SET lock_timeout = 0; | |
SET idle_in_transaction_session_timeout = 0; | |
SET client_encoding = 'UTF8'; | |
SET standard_conforming_strings = on; | |
SELECT pg_catalog.set_config('search_path', '', false); | |
SET check_function_bodies = false; | |
SET xmloption = content; | |
SET client_min_messages = warning; | |
SET row_security = off; | |
-- | |
-- Name: portnov; Type: SCHEMA; Schema: -; Owner: portnov | |
-- | |
CREATE SCHEMA portnov; | |
ALTER SCHEMA portnov OWNER TO portnov; | |
-- | |
-- Name: s1; Type: SCHEMA; Schema: -; Owner: portnov | |
-- | |
CREATE SCHEMA s1; | |
ALTER SCHEMA s1 OWNER TO portnov; | |
-- | |
-- Name: mytype; Type: DOMAIN; Schema: s1; Owner: portnov | |
-- | |
CREATE DOMAIN s1.mytype AS text; | |
ALTER DOMAIN s1.mytype OWNER TO portnov; | |
-- | |
-- Name: my_value(integer); Type: FUNCTION; Schema: portnov; Owner: portnov | |
-- | |
CREATE FUNCTION portnov.my_value(id integer) RETURNS s1.mytype | |
LANGUAGE plpgsql IMMUTABLE | |
AS $$ | |
declare | |
var mytype; | |
begin | |
var := 'my value' || id::mytype; | |
return var; | |
end | |
$$; | |
ALTER FUNCTION portnov.my_value(id integer) OWNER TO portnov; | |
SET default_tablespace = ''; | |
SET default_table_access_method = heap; | |
-- | |
-- Name: tst_data; Type: TABLE; Schema: portnov; Owner: portnov | |
-- | |
CREATE TABLE portnov.tst_data ( | |
id integer NOT NULL, | |
x integer NOT NULL, | |
y s1.mytype GENERATED ALWAYS AS (portnov.my_value(id)) STORED NOT NULL | |
); | |
ALTER TABLE portnov.tst_data OWNER TO portnov; | |
-- | |
-- Data for Name: tst_data; Type: TABLE DATA; Schema: portnov; Owner: portnov | |
-- | |
COPY portnov.tst_data (id, x) FROM stdin; | |
1 7 | |
\. | |
-- | |
-- Name: tst_data tst_data_pkey; Type: CONSTRAINT; Schema: portnov; Owner: portnov | |
-- | |
ALTER TABLE ONLY portnov.tst_data | |
ADD CONSTRAINT tst_data_pkey PRIMARY KEY (id); | |
-- | |
-- PostgreSQL database dump complete | |
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET | |
SET | |
SET | |
SET | |
SET | |
set_config | |
------------ | |
(1 row) | |
SET | |
SET | |
SET | |
SET | |
CREATE SCHEMA | |
ALTER SCHEMA | |
CREATE SCHEMA | |
ALTER SCHEMA | |
CREATE DOMAIN | |
ALTER DOMAIN | |
CREATE FUNCTION | |
ALTER FUNCTION | |
SET | |
SET | |
CREATE TABLE | |
ALTER TABLE | |
psql:tstexport1.sql:87: ОШИБКА: тип "mytype" не существует | |
LINE 3: var mytype; | |
^ | |
QUERY: | |
declare | |
var mytype; | |
begin | |
var := 'my value' || id::mytype; | |
return var; | |
end | |
CONTEXT: компиляция функции PL/pgSQL "my_value" в районе строки 3 | |
COPY tst_data, строка 1: "1 7" | |
ALTER TABLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment