How do I apply liquibase changesets with question mark symbols in SQL - sql

I'm trying to apply a liquibase changeset in sql format with valid PostgreSQL syntax. The query contains a ? operator and a regexp with ? special character.
When running this query against DB from psql everything works perfect.
When I try to apply this changeset with liquibase, I get an error:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Looks like liquibase considers ? a prepared statement argument and fails. I don't have any prepared statements in my query and I don't want liquibase to transform my query to a prepared statement.
I've found a workaround for a ? operator (substituting it with double ?? seems to work, though undocumented), but there is no workaround for regexp.
How can I set liquibase to just run the query against my DB as is?

Found help here
Reference usage with liquibase:
<changeSet id="1234" author="xyz">
<sql>
UPDATE blog
SET blog__metadata = blog__metadata::JSONB - 'someUnwantedKey',
WHERE blog__metadata::JSONB ?? 'someUnwantedKey';
</sql>
</changeSet>

Related

Validate PL/SQL without permanent changes in database

Is it possible to validate a PL/SQL code without permanent changes.
I know one can commit and then rollback, but I'm looking if there's another solution.
If I write a procedure and I want to know it will compile correctly for example.
I'm using Oracle SQL Developer and didn't see any option to do this.
You can compile your procedure and check if it's valid (doesn't return compilation error).
But in this case Oracle does just Syntactic and Semantic analysis.
Syntactic analysis – Oracle verifies that keywords, object names, operators, delimiters, and so on are placed correctly in your SQL statement. So such queries like select * foRm dual will fail during this validation. For example, we can get here such errors like:
ORA-00900: invalid SQL statement
ORA-00923: FROM keyword not found where expected
ORA-00924: missing BY keyword
ORA-00933: SQL command not properly ended
…
Semantic analysis – it verifies that references to host variables and database objects are valid(including their grants) and that host-variable datatypes are correct. For example, select * from nonexisting_table will fail this validation.
Ie, you will not get errors like ORA-00979 not a group by expression on these steps, since Oracle them later, during optimization phase.
More about this:
http://orasql.org/2017/05/01/sql-validation-during-plsql-compilation/
A different answer is to try the editions feature which has been around for awhile now

Problem running embedded firebird sql query in LibreOffice

I am trying to run the following Firebird SQL query in LibreOffice, which has embedded Firebird:
SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') AS "VERSION"
FROM "RDB$DATABASE";
I get the message Syntax error in SQL statement. Can anyone tell me what I am doing wrong? This works in FlameRobin, but not in LibreOffice.
The error "Syntax error in SQL statement" is a HSQLDB error. So, first, make sure your LibreOffice Base project is actually created as a Firebird Embedded project.
I was able to reproduce the error in LibreOffice Base 6.4.4.2 with a Firebird Embedded project. It looks like LibreOffice first tries to parse the query using HSQLDB (probably to be able to transform HSQLDB syntax to Firebird syntax), and only then forwards it to Firebird.
The cause of the error is the $ in RDB$GET_CONTEXT which is not a valid character in an unquoted object name in the HSQLDB SQL syntax, while it is valid in the Firebird SQL syntax. Normally, double quoting the specific object name would solve this, but RDB$GET_CONTEXT is not actually a function, but a syntax construct, so it can't be quoted in Firebird.
To be able to execute this query, you need to enable the 'Run SQL command directly' option in the SQL View, either under Edit > 'Run SQL command directly', or using the 'Run SQL command directly' button in the toolbar (database icon with >_).

Creating Postgres Varchar Array Columns with Liquibase

Since using Arrays in columns is still more of a NoSQL than RDBMS way of storing a list, I understand that Liquibase doesn't officially support the type. However, when I use the PSQL statements from the docs, I get the following:
<column name="widgets" type="varchar(8)[]" />
Trace output:
liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: ERROR: syntax error at or near "("
...
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "("
The vary same DDL works as expected when run from the PSQL command line.
It must be a bug of sorts in the PSQL parser. Just adding a space fixes it.
<column name="widgets" type="varchar(8) []" />
Liquibase must be changing the SQL string in some mior way.

Sql error with backquotes, says there's a syntax error at or near "`"

I'm trying to load a database into Heroku from a sql file, however I get a syntax error from back quotes / backticks.
heroku pg:psql < backup.sql
Outputs this error:
syntax error at or near "`"
Why is that? Aren't backquotes valid?
I can find/replace them with something else if that would be good to try.
are you restoring from a postgresql system or another db software such mySQL?
can you search your backup.sql file for the back-ticks and post that section of your file?
it would help to know if your back-ticks are in the column field names or in the data portion of the SQL statement.

Liquibase : Error executing SQL SET DEFINE OFF

I'm using liquibase to execute oracle scripts. This oracle scripts, are executing merge into statements for oracle, this work fine, but the problem is that the data that I need to insert have strange characters, so in order to work we are using SET DEFINE OFF (at the beginning of the file) and SET DEFINE ON (at the end of the file) in order to avoid the errors.
But if I try to run the same script in liquiBase is not working and I get this error:
Liquibase Update Failed: Error executing SQL SET DEFINE OFF
My changelog looks like this:
<changeSet author="e-ballo" id="nopa_data_email" dbms="oracle" >
<sqlFile path="email/NOPA_ACTIVATE_SECURITY.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true" />
Anyone know how to avoid this problem ?
Thanks in advance
SET DEFINE is not SQL but a SQL*Plus command. SQL*Plus is an Oracle proprietary client, and most other clients (such as IDEs) don't recognise its commands.
The Liquibase forums suggest using CDATA as the best way to pass non-standard characters. Find out more.