ddl

CREATE SCHEMA IF NOT EXISTS raises duplicate key error

ε祈祈猫儿з 提交于 2020-01-14 07:33:09
问题 To give some context, the command is issued inside a task, and many task might issue the same command from multiple workers at the same time. Each tasks tries to create a postgres schema. I often get the following error: IntegrityError: (IntegrityError) duplicate key value violates unique constraint "pg_namespace_nspname_index" DETAIL: Key (nspname)=(9621584361) already exists. 'CREATE SCHEMA IF NOT EXISTS "9621584361"' Postgres version is PostgreSQL 9.4rc1. Is it a bug in Postgres? 回答1: This

How to get definition/source code of an aggregate in PostgreSQL?

浪尽此生 提交于 2020-01-13 11:34:00
问题 I found this related answer useful: Export "Create Aggregate" functions from PostgreSQL But how do I get the CREATE AGGREGATE statement without a GUI client (e.g. with psql command line)? 回答1: Something like this, but I'm not sure if this covers all possible ways of creating an aggregate (it definitely does not take the need for quoted identifiers into account) SELECT 'create aggregate '||n.nspname||'.'||p.proname||'('||format_type(a.aggtranstype, null)||') (sfunc = '||a.aggtransfn ||', stype

How to get definition/source code of an aggregate in PostgreSQL?

[亡魂溺海] 提交于 2020-01-13 11:32:11
问题 I found this related answer useful: Export "Create Aggregate" functions from PostgreSQL But how do I get the CREATE AGGREGATE statement without a GUI client (e.g. with psql command line)? 回答1: Something like this, but I'm not sure if this covers all possible ways of creating an aggregate (it definitely does not take the need for quoted identifiers into account) SELECT 'create aggregate '||n.nspname||'.'||p.proname||'('||format_type(a.aggtranstype, null)||') (sfunc = '||a.aggtransfn ||', stype

数据定义语言(DDL)

空扰寡人 提交于 2020-01-11 01:33:43
分类: ⑴.库的管理:创建(create)、修改(alter)、删除(drop)。 ⑵.表的管理:创建(create)、修改(alter)、删除(drop)。 介绍: ㈠.库的管理: ⑴.库的创建:(如果存在创建第二次会报错)。 CREATE DATABASE (IF NOT EXISTS) 库名; ⑵.库的修改:(尽量不修改,导致数据出错,字符集可以修改)。 ALTER DATABASE 库名 CHARACTER SET utf-8; ⑶.库的删除:(重复删除报错)。 DROP DATABASE IF EXISTS 库名; ㈡.表的管理: ⑴.表的创建: CREATE TABLE 表名( 字段名 字段类型 [(长度) 约束], 字段名 字段类型 [(长度) 约束], ... 字段名 字段类型 [(长度) 约束] ); ⑵.表的修改:(修改字段名,类型或约束,表名,增删列) ①.修改字段名(类型)。 ALTER TABLE 表名 CHANGE COLUMN 字段名 新字段名 类型(新类型); ②.修改类型或约束。 ALTER TABLE 表名 MODIFY COLUMN 字段名 新类型(新约束); ③.添加新字段(列)。 ALTER TABLE 表名 ADD COLUMN 字段名 类型; ④.删除字段(列)。 ALTER TABLE 表名 DROP COLUMN 字段名; ⑤

MySQL笔记-DDL、DML、DQL

僤鯓⒐⒋嵵緔 提交于 2020-01-10 21:10:55
## DDL:操作数据库、表 1. 操作数据库:CRUD 1. C(Create):创建 * 创建数据库: * create database 数据库名称; * 创建数据库,判断不存在,再创建: * create database if not exists 数据库名称; * 创建数据库,并指定字符集 * create database 数据库名称 character set 字符集名; * 练习: 创建db4数据库,判断是否存在,并制定字符集为gbk * create database if not exists db4 character set gbk; 2. R(Retrieve):查询 * 查询所有数据库的名称: * show databases; * 查询某个数据库的字符集:查询某个数据库的创建语句 * show create database 数据库名称; 3. U(Update):修改 * 修改数据库的字符集 * alter database 数据库名称 character set 字符集名称; 4. D(Delete):删除 * 删除数据库 * drop database 数据库名称; * 判断数据库存在,存在再删除 * drop database if exists 数据库名称; 5. 使用数据库 * 查询当前正在使用的数据库名称 * select

SQL四种语言:DDL,DML,DCL,TCL

帅比萌擦擦* 提交于 2020-01-10 14:52:47
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. DDL ( Data Definition Language ) 数据库 定义语言 statements are used to define the database structure or schema. DDL是 SQL 语言的四大功能之一。 用于定义数据库的三级结构,包括外模式、概念模式、内模式及其相互之间的映像,定义数据的完整性、安全控制等约束 DDL不需要commit. CREATE ALTER DROP TRUNCATE COMMENT RENAME 2. DML ( Data Manipulation Language ) 数据操纵语言 statements are used for managing data within schema objects. 由DBMS提供,用于让用户或程序员使用,实现对数据库中数据的操作。 DML分成交互型DML和嵌入型DML两类。 依据语言的级别,DML又可分成过程性DML和非过程性DML两种。 需要commit. SELECT INSERT UPDATE DELETE MERGE CALL EXPLAIN PLAN LOCK TABLE 3. DCL ( Data Control Language ) 数据库控制语言 授权,角色控制等 GRANT

DDL概念

Deadly 提交于 2020-01-09 23:40:38
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> DDL 数据库模式定义语言 DDL (Data Definition Language),是用于描述数据库中要存储的现实世界实体的语言。一个数据库模式包含该数据库中所有实体的描述定义。 这些定义包括结构定义、操作方法定义等。 数据库模式定义语言并非程序设计语言,DDL数据库模式定义语言是SQL语言(结构化程序设计语言)的组成部分。 SQL语言包括四种主要程序设计语言类别的语句:数据定义语言(DDL),数据操作语言(DML),数据控制语言(DCL)和事务控制语言(TCL)。 常见的DDL语句 CREATE DATABASE 创建数据库 CREATE {DATABASE | SCHEMA} db_name [create_specification [, create_specification] ...] create_specification: [DEFAULT] CHARACTER SET charset_name | [DEFAULT] COLLATE collation_name CREATE TABLE 创建数据库表格 CREATE [TEMPORARY] TABLE tbl_name [(create_definition,...)] [table_options] [select

PostgreSQL create table if not exists

泪湿孤枕 提交于 2020-01-08 19:41:14
问题 In a MySQL script you can write: CREATE TABLE IF NOT EXISTS foo ...; ... other stuff ... and then you can run the script many times without re-creating the table. How do you do this in PostgreSQL? 回答1: This feature has been implemented in Postgres 9.1: CREATE TABLE IF NOT EXISTS myschema.mytable (i integer); For older versions , here is a function to work around it: CREATE OR REPLACE FUNCTION create_mytable () RETURNS void AS $func$ BEGIN IF EXISTS (SELECT FROM pg_catalog.pg_tables WHERE

Can anyone find the error error in sql syntax

别等时光非礼了梦想. 提交于 2020-01-07 09:48:16
问题 Can someone tell me what wrong with this code Table structure for table epay_area_list CREATE TABLE epay_area_list( id tinyint( 3 ) unsigned NOT NULL AUTO_INCREMENT , titlechar( 30 ) NOT NULL default '', parent tinyint( 4 ) NOT NULL default '0', akey bigint( 20 ) NOT NULL default '0', PRIMARY KEY ( id ) ) TYPE = 'MyISAM'; MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE

Why is one identifier in a CREATE TABLE double-quoted, but not the others?

蓝咒 提交于 2020-01-06 19:00:13
问题 I set the table CREATE TABLE author ( id serial NOT NULL, name character varying(255) NOT NULL, orcid character varying(128) NOT NULL, "position" integer NOT NULL, CONSTRAINT author_pkey PRIMARY KEY (id ) ); Why does the "position" name contain "" ? How can I remove "" from position ? 回答1: Actually, position is non-reserved (cannot be function or type) I am referring to the list of reserved words in the manual. What you see is most probably the output of pgAdmin (which you should have