tagDatabase and include SQL syntax for LiquiBase? - liquibase

As suggest official page I should ask this question at SO before filing bug/request.
There are XML syntax for tagDatabase and include.
Official docs on SQL syntax say nothing about such abilities.
Is it possible to instruct LiquiBase to create tag or include other file in SQL sytnax?

I checked current version of formatted sql parser (https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParser.java) and see nothing related to tagDatabase and include. So I would expect that it is not supported. 'tagDatabase' could be implemented with an update of databasechanbgelog table, and I think that there is no such easy implementation of 'include'.

Related

BigQuery DATE_DIFF Error: Encountered " <STRING_LITERAL>

I'm trying the following query from the BigQuery Standard SQL documentation:
SELECT DATE_DIFF(DATE '2010-07-07', DATE '2008-12-25', DAY) as days_diff;
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#date_diff
However, I'm receiving the following error from the UI:
Error: Encountered " "\'2010-07-07\' "" at line 1, column 23. Was expecting: ")" ... [Try using standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]
This is a simple copy and paste from the doc into the web UI Query Editor.
Any idea on how to resolve this?
Below are examples for respectively BigQuery Legacy SQL and Standard SQL
Make sure you try code as it is in answer below - not just second lines but 2(both) lines including first line that looks like comment - but in reality important part of query as it controls which SQL dialect will be in effect!
#legacySQL
SELECT DATEDIFF(DATE('2010-07-07'), DATE('2008-12-25')) AS days_diff
and
#standardSQL
SELECT DATE_DIFF(DATE '2010-07-07', DATE '2008-12-25', DAY) AS days_diff
both returns result as below
Row days_diff
1 559
Ideally, you should consider migrating to Standard SQL
Although the answer has already been provided in the comments to your questions and by Mikhail in the other answer, let me share with you a complete answer that hopefully addresses all your doubts:
ERROR MESSAGE
As explained in the error message you are getting, [Try using standard SQL (...)]. You are trying to run this sample using Legacy SQL (which instead would use the DATEDIFF function). You are actually right, you are running the exact same query provided in the documentation, but the issue here is that the documentation you are using is for Standard SQL (the preferred query language in BigQuery), but you are instead using Legacy SQL (the default language in the old UI, the one you are using).
CHANGE THE QUERY LANGUAGE IN USE
First of all, I would like to remark the importance of using Standard SQL instead of Legacy SQL, as the former adds new functionalities and is the current recommended language to use with BigQuery. You can see the whole list of comparisons in the documentation, but if you are starting with BigQuery, I would just go straight away with Standard SQL.
Now, that being clarified, in order to use Standard SQL instead of Legacy SQL, you can have a look at the documentation here, but let me summarize the available options for you:
In the BigQuery UI, you can toggle the Use legacy SQL option inside
the Show options menu. If this option is marked, you will be using
Legacy SQL; and if it is not, you will be using Standard SQL.
You can use a prefix in your query, like #standardSQL or #legacySQL, which would ignore the default configuration and use the language you specify with this option. As an example on how to use it, please have a look at the other answer by Mikhail, who shared with you a couple of examples using prefixes to identify the language in use. You should copy the complete query (including the prefix) in the UI, and you will see that it works successfully.
Finally, as suggested by Elliott, you can use the new UI, which has just recently released in Beta access. You can access it through this link https://console.cloud.google.com/bigquery instead of the old link https://bigquery.cloud.google.com that you were using until now. You can find more information about the new BigQuery Web UI in this other linked page too.

How to use ON DUPLICATE KEY on hsqldb 2.3.4

According to the update on hsqldb.org listed here: http://hsqldb.org/web/features200.html
It now supports the mysql syntax ON DUPLICATE KEY in hsqldb 2.3.4, yet Im still getting sql errors when trying to run it. If im reading correctly I may need to set certain flags. But I cant find what to set to be able to use this synatx.
MySQL compatibility is documented in the Guide http://hsqldb.org/doc/2.0/guide/compatibility-chapt.html#coc_compatibility_mysql
You need to execute SET DATABASE SQL SYNTAX MYS TRUE or the equivalent URL property sql.syntax_mys=true to enable it.

How can I rename a sequence with liquibase?

I have a sequence in my database, which I generated through Liquibase. During refactoring, we decided that we didn't like the name that we gave it, and we would like to rename it, preserving all data that currently exists for it.
It seems possible to alter a sequence, but I'm not seeing anything about how to rename the sequence. Is there a way to do it, or a reasonable workaround?
(If it matters, I'm using Oracle SQL)
Although not documented, this refactoring is supported by Liquibase. Not sure what version this change was implemented in, but the class supporting the feature was commited on 30 Jan 2014. What's interesting though, is that the original issue is still unresolved.
Anyway, the refactoring is supposed to be working only on Oracle and Postgres. I've tested it on Oracle with Liquibase 3.4.1:
databaseChangeLog:
- changeSet:
id: change_set_id
author: me
dbms: oracle
changes:
- renameSequence:
oldSequenceName: old_name_seq
newSequenceName: new_name_seq
The above refactoring is in YAML format, but you could easily guess its XML counterpart.
On Oracle, this generates the following statement:
RENAME old_name_seq TO new_name_seq;
2 other supported parameters are catalogName and schemaName.
There is not currently a built-in refactoring to rename a sequence. If your database engine supports it, you could execute whatever methods are supported using a <sql> or <sqlFile> change.
You said you were using Oracle SQL. The RENAME statement allows for renaming a sequence. So your Liquibase script would look like this:
<sql>RENAME old_sequence_name TO new_sequence_name</sql>

Liquibase : Migrate.sql does not check precondtions

I use liquibase to generate SQL files based on the changeset . But when I am using liquibase:updateSQL , it is not checking for preconditions before generating the SQL file
I have a preconditions saying to check if the table exists , before creating the table .
In this scenario even though the tables are present the 'create table SQL statement is still getting generated.'
Where as when i run liquibase:update goal this precondition is checked properly .
So does not liquibase check for precondition while generating the sql file?
Thanks.
You probably have found an answer already, but just in case this might help:
http://forum.liquibase.org/topic/unexpected-behaviour-of-preconditions-with-updatesql
onSqlOutput="TEST" attribute for the precondition sounds like what you are looking for.
Just be careful with the the preconditions you write or when to test them while generating the updateSQL. Preconditions that rely on previously applied patches that might have not been executed yet in your instance could cause errors.
Hope it helps
Might help to provide some code. Especially your precondition to allow other to evaluate if it is an issue.

How do I get the SQL Schema creation statements with Play! Framework?

This question shows how to get Play! to show SQL statments. I followed on the accepted solution (jpa.debugSQL=true), but I still don't see the SQL statements that are used to create the tables themselves in the log.
How can I get those statements? (I'm currently using the in-memory database that comes with Play!, all default settings)
Note - if one of the SQL Schema statements goes wrong, it is displayed as an error in the log.
Check in application.conf the value of your property:
application.log=INFO
It may be hiding the output.
If you are using a log4j.properties file you may want, as Zenklys says, check the appenders set up in there.
You should use a log4j.properties file. If you define a logger on debug level on hibernate package you should be able to get the SQL statements.