Liquibase labels - liquibase

I was playing around with liquibase (SQL syntax) and got stuck with labels. I have them in my changelog, but the 'labels' column in the changelog table is empty. Because of that, I can't run any command where labels are involved.
I saw an example here: https://docs.liquibase.com/concepts/advanced/labels.html
What am I doing wrong ???
Thanks in advance )

The doc appears to be wrong. The changeset/changelog example should be like the following:
--changeset Liquibase User:1 labels:1.0
create table primary_table (
id int primary key,
name varchar(50) not null,
address1 varchar(50),
address2 varchar(50),
city varchar(30)
)
Where labels:1.0 key-value pair is on the same line where the --changeset tag is.

Related

Create Table syntax error in sql Jupyter notebook

I tried to create a table in sql. But I keep getting a syntax error. I tried the solutions from other answers on this website. But, I keep getting the syntax error. This is the code that I tried.
CREATE TABLE STUDENT(
LastName VARCHAR(50) NOT NULL,
FirstName VARCHAR(50) NOT NULL,
StudentID int NOT NULL UNIQUE,
Major ARCHAR(20),
PRIMARY KEY (StudentID)
);
This is the error that I get.
File "<ipython-input-12-dff73a7a002a>", line 1
CREATE TABLE STUDENT(
^
SyntaxError: invalid syntax
I am running this on Jupyter notebook. Could anyone help me know where I am going wrong?
There's a small typo in your CREATE statement as below. You are missing V
Major ARCHAR(20),
should be
Major VARCHAR(20),
I guess you try to run SQL-code with python kernel. But it isn't the way that would work.
If you really want to execute SQL with Jupyter you should look at ipython-sql extension: https://github.com/catherinedevlin/ipython-sql
So at first install extension with pip install ipython-sql.
Then in a notebook load it with %load_ext sql.
And in the end, try your code, preliminarily it with %%sql-magic. I.e.:
%%sql sqlite://
CREATE TABLE STUDENT(
LastName VARCHAR(50) NOT NULL,
FirstName VARCHAR(50) NOT NULL,
StudentID int NOT NULL UNIQUE,
Major ARCHAR(20),
PRIMARY KEY (StudentID)
);
If my answer is off topic, just give me more information about what you do.

Creating Databases in SQLite

We were asked to create a database in sqlite3 and then create a table in it. I used this command:
$sqlite3 me5.db
and tried to create a table with this statement:
CREATE TABLE me5.petID(pet id PRIMARY KEY int(3), pet name varchar(10), pet type varchar(10), pet age int(3));
but it says that:
ERROR: near "CREATE" : syntax error
What could I have possible done wrong? Thanks.
try this
CREATE TABLE petID(pet_id int(3) PRIMARY KEY, pet_name varchar(10), pet_type varchar(10), pet_age int(3));
you dont have to specify the database name because you're already using it after the command sqlite3 me5.db.
you have spaces in the names of the fields, which is not allowed. so i've put underscores instead of spaces.
use PRIMARY KEY after int(3)

Liquibase ignorable comments

Is there a way we can add comments in liquibase file which are not parsed by the program?
We are using the text format for the changes.sql and this is how it looks
--changeset Sapan.Parikh:MyUniqueAlphaNumericId5
--comment: Table created for liquibase testing purpose with non numeric id
--6:10 PM 11/10/2015
create table liqui_test11 (
id int primary key,
name varchar(255)
);
create table liqui_test9 (
id int primary key,
name varchar(255)
);
create table liqui_test10 (
id int primary key,
name varchar(255)
);
Our organization has been using similar change log for years and while migrating to Liquibase we want to be able to do two things.
Add dashes or hashes after each changeset.
And after every production build we add a comment at the end of the changes file.
For instance
--changeset Sapan.Parikh:MyUniqueAlphaNumericId5
--comment: Table created for liquibase testing purpose with non numeric id
--6:10 PM 11/10/2015
create table liqui_test11 (
id int primary key,
name varchar(255)
);
-----------------------------------------------------------------
--changeset Sapan.Parikh:MyUniqueAlphaNumericId4
--comment: Table created for liquibase testing purpose with non numeric id
--6:10 PM 11/10/2015
create table liqui_test12 (
id int primary key,
name varchar(255)
);
###------------------Build 10.0.1 Made-------------------
Now if we add just dashes- or # the luqibase task is breaking and DB upgrade does not happen. Is there a way to accommodate comments which are not parsed by liquibase engine?
You can just persist your comments and strip them right before executing liquibase
- can be done easily using sed

Newly added table not working

I am working on DB2 9.7 database. I was using SquirrelSQL for GUI purpose. However ever since I applied an alter command to one of my tables , I started facing problems with the table, and any further select queries asked for "reorg" of the table. to overcome this, I renamed the old table and created new table. However the create query didn't execute properly in Squirrel ,and so downloaded DBViewer for my STS(Spring Source Tool Suite.)I executed the create table query from DBViewer, but the issue now is neither am I able to access the newly created table from my JAVA code , nor from Squirrel.
I am completely clueless as to what could be the problem. Has anyone got any idea?
Following is the Structure of my table:
CREATE TABLE DB2ADMIN.CERT
(
CERT_ID CHAR(36) NOT NULL,
CERT_CD CHAR(1) NOT NULL,
CERT_NBR CHAR(10) NOT NULL,
CERT_REQ_USR_CD_1 CHAR(10),
CERT_REQ_USR_CD_2 CHAR(10),
CERT_REQ_USR_CD_3 CHAR(10),
CERT_REQ_USR_CD_4 CHAR(10),
CERT_REQ_USR_TXT_1 VARCHAR(255),
CERT_REQ_USR_TXT_2 VARCHAR(255),
CERT_REQ_USR_TXT_3 VARCHAR(255),
CERT_REQ_USR_TXT_4 VARCHAR(255),
CERT_REQ_USR_TXT_5 VARCHAR(255),
CERT_REQ_USR_TXT_6 VARCHAR(255),
CERT_REQ_USR_TXT_7 VARCHAR(255),
CERT_REQ_USR_TXT_8 VARCHAR(255),
CERT_REQ_USR_TXT_9 VARCHAR(255),
CERT_REQ_USR_DT DATE,
LAST_MDF_USER_ID CHAR(25) NOT NULL,
LAST_MDF_ACY_TS TIMESTAMP(26,6) NOT NULL,
CONSTRAINT SQL111017085116710 PRIMARY KEY (CERT_ID)
);
In my alter query I changed the datatype of CERT_NBR form INTEGER to CHAR
using the command;
ALTER TABLE CERT ALTER COLUMN CERT_NBR SET DATA TYPE INTEGER
any further select queries asked for "reorg" of the table.
This is a common occurrence after altering tables in DB2. It should be trivially solved by calling:
reorg table table-name;
This is a command-line command, rather than an sql statement, but you can call it via SQL with the admin_cmd procedure:
call sysproc.admin_cmd('reorg table table-name');
I'm not sure why you are unable to access the new table. The error message should help you resolve this. Some possibilities:
You created it with a different username than the one you are trying to access it with.
You never committed after the create table statement.
Something went wrong and the table ended up in an inoperable state.

auto_increment causing errors with CREATE TABLE

I have been using netbeans as a tool for my java, and i have a problem. I read this tutorial and then i tried to create a table using this SQL:
CREATE TABLE CUSTOMERS (
ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(30),
ADDRESS VARCHAR(30),
CITY VARCHAR(30),
STATE_ VARCHAR(30),
ZIP VARCHAR(15),
COUNTRY_ID INTEGER,
PHONE VARCHAR(15),
EMAIL_ADDRESS VARCHAR(50)
)ENGINE=INNODB;
When i tried to run it, I got this error message:
sql state 42X01 : Syntax error :
encountered "AUTO_INCREMENT" at line 2
column 29
and when i delete the AUTO_INCREMENT, another error:
detected ENGINE=INNODB;
can someone help me? Thanks.
You seem to be using MySQL syntax with another database engine. The parts it complained about are precisely the MySQL-specific ones.
my sugestion would be the following
CREATE TABLE CUSTOMERS
( ID INTEGER NOT NULL auto_increment,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(30),
ADDRESS VARCHAR(30),
CITY VARCHAR(30),
STATE_ VARCHAR(30),
ZIP VARCHAR(15),
COUNTRY_ID INTEGER,
PHONE VARCHAR(15),
EMAIL_ADDRESS VARCHAR(50),
PRIMARY KEY (ID));
Dunno what the engine=innodb is for, have you tried without it?
The "engine=innodb" part specifies the database engine that gets used in the database. With MySQL you can specify different engines like "InnoDB", "MyISAM", etc. They have different properties and features - some allow foreign indexes, some do not. Some have different locking mechanisms, some have different atomicity/rollback properties. I don't know the details but if you need a really high-performance database setup you should investigate which engine is best for each type of table you're creating. Also, all my database experience has been with MySQL and I'm not sure if that's what you're using.
Been a long time but if anybody else stumbles on this like I did, a solution that worked for me is instead of using auto_increment, describe the ID column as
ID INTEGER GENERATED ALWAYS AS IDENTITY, WHATEVER VARCHAR(20), ETC ETC...