Object view (definitions)
The DDL of the selected object, reconstructed from the catalogs and the server's
pg_get_*def functions — pgAdmin's SQL tab. Read only.
The Default tab follows the tree
One catalog query with the object's OID as bind parameter, sent after the tree cursor has rested 200 ms. A result for a row the cursor has left is discarded.
What a definition contains
The layout follows pgAdmin: a header comment, the DROP as a comment, the CREATE, then
OWNER, COMMENT, GRANT and the dependent parts.
-- Table: sales.customer
-- DROP TABLE IF EXISTS sales.customer;
CREATE TABLE IF NOT EXISTS sales.customer
(
customerid integer NOT NULL DEFAULT nextval('sales.customer_customerid_seq'::regclass),
...
CONSTRAINT "PK_Customer_CustomerID" PRIMARY KEY (customerid),
...
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS sales.customer
OWNER to postgres;
COMMENT ON TABLE sales.customer
IS 'Current customer information. Also see the Person and Store tables.';
GRANT SELECT ON TABLE sales.customer TO reporting;
-- Index: ix_customer_territoryid
CREATE INDEX IF NOT EXISTS ix_customer_territoryid
ON sales.customer USING btree (territoryid);
| Object | Its definition also includes |
|---|---|
| Table, partition | Constraints, partition key, then indexes, triggers, rules and policies. |
| View | Rules and triggers. |
| Materialized view | Indexes. |
| Column, constraint, index, trigger, rule, policy | Only the statement that adds that part. |
| Part | Source |
|---|---|
| View and materialized view query | pg_get_viewdef() |
| Function, procedure, trigger function | pg_get_functiondef() |
| Index | pg_get_indexdef() |
| Constraint (table and domain) | pg_get_constraintdef() |
| Trigger | pg_get_triggerdef() |
| Rule | pg_get_ruledef() |
| Partition key | pg_get_partkeydef() |
| Defaults and other stored expressions | pg_get_expr() |
| Type names | format_type() |
| Comments | obj_description(), col_description() |
| Privileges | The ACL through aclexplode(), as GRANT statements. |
The rest — CREATE TABLE, SEQUENCE, TYPE, roles, databases, schemas — is
assembled by pgtc from catalog columns. Names are schema-qualified and quoted with quote_ident().
A group row lists its objects; a server row shows its parameters and pg_settings — see
Connections.
Reading a definition
F6 (or Alt+2) moves from the tree into the text and back. It is the query tab's editor in read-only mode: moving, selecting, copying and Ctrl+F work. Lines are not wrapped.
Keeping a definition open: F3
vindividualcustomer.F3 in the tree opens the object in its own tab, which does not follow the tree cursor. It is a snapshot: later DDL does not update it.
Changing an object: Edit in new query tab (Ctrl+E)
pgtc has no property dialogs. Ctrl+E (, context menu) copies the shown definition into a new query tab with a session on the object's database.
| Object | The text in the query tab |
|---|---|
| Function, procedure, view | CREATE OR REPLACE …: executable as it is. |
| Table | CREATE TABLE IF NOT EXISTS …: a no-op on the existing table; a reference for ALTER TABLE. |
| Index, trigger, constraint, policy | Uncomment the DROP line to re-create. |
Refused, with a hint in the status line:
- while the definition is loading, and on rows without one (groups, errors);
- on roles and tablespaces — cluster-wide, so there is no database for the tab's session;
- on a server that is not connected.
For CREATE and DROP from a form, see the
developer templates (F7).