Project

General

Profile

« Previous | Next » 

Revision 14224

schemas/util.sql: added copy_struct(from_ regtype, to_ text) and copy_data(from_ regtype, to_ text), and use these in a general-purpose copy()

View differences:

trunk/schemas/util.sql
1513 1513

  
1514 1514

  
1515 1515
--
1516
-- Name: copy(regclass, text); Type: FUNCTION; Schema: util; Owner: -
1516
-- Name: copy(anyelement, text); Type: FUNCTION; Schema: util; Owner: -
1517 1517
--
1518 1518

  
1519
CREATE FUNCTION copy(from_ regclass, to_ text) RETURNS void
1519
CREATE FUNCTION copy(from_ anyelement, to_ text) RETURNS void
1520 1520
    LANGUAGE sql
1521 1521
    AS $_$
1522 1522
SELECT util.copy_struct($1, $2);
......
1525 1525

  
1526 1526

  
1527 1527
--
1528
-- Name: copy(regtype, text); Type: FUNCTION; Schema: util; Owner: -
1528
-- Name: FUNCTION copy(from_ anyelement, to_ text); Type: COMMENT; Schema: util; Owner: -
1529 1529
--
1530 1530

  
1531
CREATE FUNCTION copy(from_ regtype, to_ text) RETURNS void
1532
    LANGUAGE sql STRICT
1533
    AS $_$
1534
-- must be declared STRICT to handle NULL properly
1535
SELECT util.materialize_query(to_, $$SELECT (NULL::$$||from_||$$).*$$)
1536
$_$;
1531
COMMENT ON FUNCTION copy(from_ anyelement, to_ text) IS '
1532
from_: regclass/regtype
1533
';
1537 1534

  
1538 1535

  
1539 1536
--
......
1548 1545

  
1549 1546

  
1550 1547
--
1548
-- Name: copy_data(regtype, regclass); Type: FUNCTION; Schema: util; Owner: -
1549
--
1550

  
1551
CREATE FUNCTION copy_data(from_ regtype, to_ regclass) RETURNS void
1552
    LANGUAGE sql
1553
    AS $$
1554
SELECT NULL::void -- no-op
1555
$$;
1556

  
1557

  
1558
--
1551 1559
-- Name: copy_struct(regclass, text); Type: FUNCTION; Schema: util; Owner: -
1552 1560
--
1553 1561

  
......
1559 1567

  
1560 1568

  
1561 1569
--
1570
-- Name: copy_struct(regtype, text); Type: FUNCTION; Schema: util; Owner: -
1571
--
1572

  
1573
CREATE FUNCTION copy_struct(from_ regtype, to_ text) RETURNS void
1574
    LANGUAGE sql STRICT
1575
    AS $_$
1576
-- must be declared STRICT to handle NULL properly
1577
SELECT util.materialize_query(to_, $$SELECT (NULL::$$||from_||$$).*$$)
1578
$_$;
1579

  
1580

  
1581
--
1562 1582
-- Name: copy_types_and_data(regclass, text); Type: FUNCTION; Schema: util; Owner: -
1563 1583
--
1564 1584

  

Also available in: Unified diff