File: ex56.sql

package info (click to toggle)
pgformatter 5.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,964 kB
  • sloc: sql: 186,493; perl: 5,694; makefile: 2; sh: 1
file content (93 lines) | stat: -rw-r--r-- 2,324 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
CREATE VIEW ticket. "view_ticket_inquiry" AS
SELECT
    i.*,
    (
        SELECT
            max(tl.creation_time)
        FROM
            wf.transition_log tl
        WHERE
            tl.workflow_id = i.id
            AND tl.dst_station_id = 25346145527
            /* this is a comment */
) AS last_answered
FROM
    ticket.inquiry i;

CREATE FUNCTION state_update (id int4, new int4) RETURNS int4
    AS $$
BEGIN
    INSERT INTO state (id, state, when)
    VALUES (id, new, CURRENT_TIMESTAMP);
    INSERT INTO state (id, state, when)
    VALUES (id, new, CURRENT_TIMESTAMP)
ON CONFLICT (id) -- ### this line should not be dedented
    DO UPDATE SET
        state = excluded.state, when = excluded.when;
    RETURN 1;
END;
$$
LANGUAGE plpgsql;
CREATE PROCEDURE insert_data (a integer, b integer)
LANGUAGE SQL
AS $$
    INSERT INTO tbl VALUES (a);
INSERT INTO foo AS bar DEFAULT VALUES RETURNING foo.*;
    INSERT INTO tbl VALUES (b) RETURNING b;
$$;

INSERT INTO foo AS bar DEFAULT
    VALUES
    RETURNING
        foo.*;

CREATE TYPE foo AS enum (
    'busy',
    'help'
);

CREATE TYPE IF NOT EXISTS foo AS enum ( 'busy',
    'help'
);

CREATE TABLE IF NOT EXISTS foo (
    id bigint PRIMARY KEY,
    /*
     This text will receive an extra level of indentation
     every time pg_format is executed
     */
    bar text NOT NULL
    /* this is the end*/
);

CREATE INDEX onek_unique1 ON onek
    USING btree (unique1 int4_ops);

CREATE INDEX IF NOT EXISTS onek_unique1 ON onek
    USING btree (unique1 int4_ops);

CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;

CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;

SELECT a , b , Row_number() OVER (PARTITION BY Coalesce(c.order_id , c.id)ORDER BY c.id ASC) , e , d FROM c;

CREATE TABLE sh.z (
    id SERIAL NOT NULL
    , b SmALLINT NULL
    , v TEXT NULL
    , d TexT NULL
    , e TiMESTAMP NULL
    , f BOOLEAN NOT NULL
    , g BOoLEAN NOT NULL);

SET TIME ZONE 'CST7CDT';

SELECT f1, f1::INTERVAL DAY TO MINUTE AS "minutes",
  (f1 + INTERVAL '1 month')::INTERVAL MONTH::INTERVAL YEAR AS "years"
  FROM interval_tbl;

SELECT '19970210 173201' AT TIME ZONE 'America/New_York';

SELECT * FROM XMLTABLE('*' PASSING '<a>a</a>' COLUMNS a xml PATH '.', b text PATH '.', c text PATH '"hi"', d boolean PATH '. = "a"', e integer PATH 'string-length(.)');