ddl

SqlServer to Postgres DDL migration/conversion

断了今生、忘了曾经 提交于 2019-12-24 09:26:45
问题 We're looking to migrate from MSSQL to Postgres. I'm intending on using sql servers bcp tool for generating csv that we'll import into postgres with the bulk copy features. We are however, having trouble getting the DDL migrated. We've. I've gotten it to work by massaging the DDL generated by MMSQL by hand but We need something automated since we have a moving target (still adding tables, columns etc.) and will need to do this more than once. We're open to commercial and open source products

Trigger with multiple WHEN conditions

心不动则不痛 提交于 2019-12-24 07:04:25
问题 How do I include the columns I need to monitor? I.e. instead of one WHEN condition I want to have 3 WHEN conditions: CREATE TRIGGER freeradius.insert_into_day_summations BEFORE INSERT ON freeradius.day_guiding_usage FOR EACH ROW WHEN (OLD.col1 IS DISTINCT FROM NEW.col1) WHEN (OLD.col2 IS DISTINCT FROM NEW.col2) WHEN (OLD.col3 IS DISTINCT FROM NEW.col3) EXECUTE procedure update_sessioninfo(); 回答1: Form a single expression with OR or AND - depending on whether you want to trigger when all

Change schema of multiple PostgreSQL functions in one operation?

眉间皱痕 提交于 2019-12-24 04:24:10
问题 Recently I needed to move objects from PostgreSQL's default schema "public" to another schema. If found this post which shows how to move tables which was great, but I also need to move the functions. 回答1: You could refine the loop some more (demonstrating only the second query ): DO $do$ DECLARE r record; sql text = ''; BEGIN FOR r IN SELECT p.proname, pg_get_function_identity_arguments(p.oid) AS params FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace WHERE nspname = 'public' --

Does H2 support a collation defintion for one single column?

社会主义新天地 提交于 2019-12-24 03:54:31
问题 I want to make a single H2 column in a H2 database to have a other collation (case insensitive) then the other columns (that are case sensitive). In MySQL I would do this: ALTER TABLE users MODIFY login VARCHAR(255) COLLATE utf8_general_ci Is there a similar feature in H2? 回答1: H2 only supports one collation per database (via SET COLLATION statement). What it does support is a case-insensitive data type, VARCHAR_IGNORECASE. Internally, this data type is using String.compareToIgnoreCase. This

ORA 01400 and ORA 02296 : Cannot insert null or modify added column properties to NOT NULL

╄→尐↘猪︶ㄣ 提交于 2019-12-24 02:23:29
问题 "Modify your query to add a column that subtracts the old salary from the new salary. Label the column Increase. Run the revised query." Well, as per my interpretation, I first attempted to add the column by scripting: ALTER TABLE EMPLOYEES ADD ( INCREASE2 NUMBER(6)); Then: INSERT INTO EMPLOYEES(INCREASE2) SELECT (salary*1.155) - salary FROM EMPLOYEES; Error de SQL: ORA-01400: não é possível inserir NULL em ("HR"."EMPLOYEES"."EMPLOYEE_ID") 01400. 00000 - "cannot insert NULL into (%s)" "HR".

How to check which function uses a type?

久未见 提交于 2019-12-24 01:05:28
问题 I have a type which I'd like to change but I don't know who else is using it. How can I check for all functions that return this type? 回答1: You can find all dependencies in the system catalog pg_depend. This returns all functions depending on the type . I.e. not only those with the type in the RETURNS clause, but also those with the type as function parameter: SELECT objid::regproc AS function_name , pg_get_functiondef(objid) AS function_definition , pg_get_function_identity_arguments(objid)

Can Grails 2.x schema-export, or similar command, generate DDL for schema updates given a datasource?

一曲冷凌霜 提交于 2019-12-23 13:17:09
问题 Grails schema-export does a great job of generating the DDL to create database schemas for a particular database. However what I would like to do, is have grails just output the DDL for updates to an already created schema, not the DDL to create it from scratch. I'm thinking it should be possible, as grails does have the ability to actually update schemas if you specificy dbCreate = "update" in your datasource. But I just want grails to spit out what it would run, not actually do it, so I can

What is the difference between REFERENCES with, or without a FOREIGN KEY

南楼画角 提交于 2019-12-23 10:57:31
问题 In regards to SQLite , What is the difference between REFERENCES with, or without a FOREIGN KEY? What is the difference between this CREATE TABLE players_set ( _id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, player_id INTEGER REFERENCES players ( _id ) ON DELETE CASCADE, players_set_id INTEGER REFERENCES players_set_names ( _id ) ); and this: CREATE TABLE players_set ( _id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, player_id INTEGER, players_set_id INTEGER REFERENCES players_set_names ( _id

Redshift: add column if not exists

試著忘記壹切 提交于 2019-12-23 10:54:39
问题 The following works in Postgres 9.6 but not in Redshift: ALTER TABLE stats ADD COLUMN IF NOT EXISTS panel_exit timestamp; Can the same functionality be achieved in Redshift? 回答1: There is no Amazon Redshift command equivalent to ADD COLUMN IF NOT EXISTS . See: ALTER TABLE documentation To replicate this functionality, your application would first need to query the table metadata and then make the decision whether to issue the ADD COLUMN command. 回答2: John's answer set me in the right

MySQL to PostgreSQL table create conversion - charset and collation

别等时光非礼了梦想. 提交于 2019-12-23 02:49:27
问题 I want to migrate from MySQL to PostgreSQL.My query for create table is like this. CREATE TABLE IF NOT EXISTS conftype ( CType char(1) NOT NULL, RegEx varchar(300) default NULL, ErrStr varchar(300) default NULL, Min integer default NULL, Max integer default NULL, PRIMARY KEY (CType) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin; What is the converted form of this query. I am confused with DEFAULT CHARSET=latin1 COLLATE=latin1_bin part. How can I convert this part? 回答1: That one