我曾经认为模式是数据库本身之前的"上层包装"对象.我的意思DB.schema.<what_ever_object_name_under_schema>.
那么,目录"包装器"现在非常令人困惑.我们为什么需要目录?出于何种目的,目前应该使用目录?
是否可以定义默认情况下创建新表的模式?(由"不合格的表名称"引用.)
我已经看到了在Postgres中使用"搜索路径"的一些细节,但我认为它只在检索数据时有效,而不是创建.
我有一堆SQL脚本,它们创建了许多表.我没有修改脚本,而是希望默认情况下在特定模式中设置数据库创建表 - 当它们具有非限定名称时.
这可能吗?
我有一个带有主表的数据库"DB_One",上面t_d_gate_out有8个索引.我创建了另一个带分区的数据库t_d_gate_out(让我们称之为"DB_Two").:它是由年份和月份(子表的例子分区t_d_gate_out09-2013有两个索引)(d _gate_out和每个孩子新列:i_trx_own)
这是我创建和插入子表的功能:
CREATE OR REPLACE FUNCTION ctm_test.gateout_partition_function()
RETURNS trigger AS
$BODY$
DECLARE new_time text;
tablename text;
seqname text;
seqname_schema text;
bulantahun text;
bulan text;
bulan2 text;
tahun text;
enddate text;
result record;
BEGIN new_time := to_char(NEW.d_gate_out,'MM-YYYY');
bulan:=to_char(NEW.d_gate_out,'MM');
bulan2:=extract(month from NEW.d_gate_out);
tahun:=to_char(NEW.d_gate_out,'YYYY');
bulantahun := new_time;
tablename := 't_d_gate_out'||bulantahun;
seqname := 't_d_gate_out'||bulantahun||'_seq';
seqname_schema := 'ctm_test.t_d_gate_out'||bulantahun||'_seq';
PERFORM 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE
c.relkind = 'r' AND …Run Code Online (Sandbox Code Playgroud) 我是PostgreSQL的新手.我有这样的表:
CREATE TABLE Person (
ID SERIAL PRIMARY KEY,
Name VARCHAR(32) NOT NULL DEFAULT '',
Surname VARCHAR(32) NOT NULL DEFAULT '',
Birthday DATE,
Gender VARCHAR(8)
);
-- Student table inherits from person
CREATE TABLE Student (
ID_Student SERIAL PRIMARY KEY,
MajorDept VARCHAR(32),
) INHERITS(Person);
-- Student table inherits from person
CREATE TABLE Employee (
ID_Employee SERIAL PRIMARY KEY,
Position VARCHAR(32),
Rank VARCHAR(32),
Salary NUMERIC(12,2)
) INHERITS(Person);
-- Address table references person
CREATE TABLE Address (
ID_Address SERIAL PRIMARY KEY,
Person_id …Run Code Online (Sandbox Code Playgroud) postgresql inheritance triggers database-design referential-integrity
postgresql ×3
schema ×2
catalog ×1
database ×1
indexing ×1
inheritance ×1
partitioning ×1
search-path ×1
triggers ×1