SQLite Foreign Key

You still have to create the column checklist_id INTEGER before you add it as a Foreign key. So it would be: CREATE TABLE checklist ( _id INTEGER PRIMARY KEY AUTOINCREMENT, checklist_title TEXT, description TEXT, created_on INTEGER, modified_on INTEGER ); CREATE TABLE item ( _id INTEGER PRIMARY KEY AUTOINCREMENT, checklist_id INTEGER, item_text TEXT, item_hint TEXT, item_order … Read more

Postgres table column name restrictions?

Here’s a nice table of reserved words in PostgreSQL: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html It is probably best to simply avoid using those words as table- or column-names. An alternative, however, is to enclose the identifier in double-quotes, e.g.: CREATE TABLE IF NOT EXISTS apiss ( skey TEXT, time INTEGER, “user” TEXT, ip TEXT); Additionally, Postgres reserves system column … Read more

Alter table if exists or create if doesn’t

MySQL INFORMATION_SCHEMA database to the rescue: — First check if the table exists IF EXISTS(SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=”db_name” AND table_name LIKE ‘wild’) — If exists, retreive columns information from that table THEN SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name=”tbl_name” AND table_schema=”db_name”; — do some action, i.e. ALTER TABLE if some columns … Read more

PostgreSQL create table if not exists

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 LANGUAGE plpgsql AS $func$ BEGIN IF EXISTS (SELECT FROM pg_catalog.pg_tables WHERE schemaname=”myschema” AND tablename=”mytable”) THEN RAISE NOTICE ‘Table myschema.mytable already exists.’; … Read more

Create Table in Hive with one file

There are many possible solutions: 1) Add distribute by partition key at the end of your query. Maybe there are many partitions per reducer and each reducer creates files for each partition. This may reduce the number of files and memory consumption as well. hive.exec.reducers.bytes.per.reducer setting will define how much data each reducer will process. … Read more

MySQL: Error Code: 1118 Row size too large (> 8126). Changing some columns to TEXT or BLOB

I tried all the solutions here, but only this parameter innodb_strict_mode = 0 solved my day… From the manual: The innodb_strict_mode setting affects the handling of syntax errors for CREATE TABLE, ALTER TABLE and CREATE INDEX statements. innodb_strict_mode also enables a record size check, so that an INSERT or UPDATE never fails due to the … Read more