How to enable calcite's dialect-specific operator like TO_TIMESTAMP - sql

I want to parser the sql query using calcite to do some SQL equivalence verification. But I found the default setting of calcite don't support dialect-specific operator such as TO_TIMESTAMP. The error is below:
No match found for function signature TO_TIMESTAMP(<CHARACTER>, <CHARACTER>)
The answer here said I can use jdbc to change the setting of calcite. But I cannot found where to use jdbc string to change the setting. Should I use some API in calcite to put the jdbc statement into calcite?

If you're not invoking Calcite via JDBC, how are you calling it? Other APIs to Calcite have an equivalent of the JDBC fun parameter in the answer you reference, but it's difficult to answer your question without more specifics.

Related

What does double question mark (??) mean in sql (postgres sql)

What does double question mark (??) mean in sql or sql query. (postgres sql).
My DB Server is Postgres and I am using columns that are of type jsonb.
I see a query that has ?? in it. Below is the query.
select rr.jdoc
from table_with_jsonb rr
where not (rr.jdoc ?? 'pivot')
and ((rr.jdoc->'mapping'->>'objectType')<>'meta');
Can some one explain what the ?? means and any references will be of great help.
Normally my understand is that - ? is to allow Parameterized Query.
But this table 9.4 ref -> FUNCTIONS-JSONB-OP-TABLE or 13.x ref -> FUNCTIONS-JSONB-OP-TABLE adds more usage scenerios for ?.
But still it does not say what ?? is.
PS: Plz ignore the doc references to 9.4. I am using 13.x currently.
It's the same as the ? operator when used through JDBC.
JDBC uses ? for parameter placeholders and thus there needs to be a way to distinguish the operator from the parameter placeholder. So the Postgres JDBC driver allows to escape the ? operator using ?? in a PreparedStatement.
I don't know if other technologies (ODBC, .Net) are using a similar mechanism.

How to use LEAST function in Calcite SQL with Apache Beam

I'm trying to call the LEAST function in Calcite SQL in my Apache Beam pipeline:
...
,LEAST(12.5 + (25 * Quartile), 100) AS PlayedPercentage
...
Where Quartile is an int32 column. I get the below error:
Caused by: org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.sql.validate.SqlValidatorException: No match found for function signature LEAST(<NUMERIC>, <NUMERIC>)
I've also tried to cast both arguments to Float, but get the same result. How am supposed to call the fuction?
According to Calcite's SQL Reference, LEAST is a dialect-specific operator that is only enabled in the Oracle operator table.
If you were connecting to Calcite directly, I would suggest that include fun=oracle in the JDBC connect string, and this will enable the Oracle operator table. I'm not sure what the steps are if you are using Calcite from within Beam.

How do I clear all the rows from a table using Entity Framework Core?

New to Entity Framework Core. How do I clear all the rows from a table?
I searched around and found the following solution:
_context.Database.ExecuteSqlCommand("TRUNCATE TABLE[TableName]");
Unfortunately using ExecuteSqlCommand throws a compiler error.
Am I missing a namespace or is there another way to do this?
Thanks, JohnB
ExecuteSqlCommand is Obsolete,you can see the details here.
For the execution of SQL queries using plain strings, use ExecuteSqlRaw instead. For the execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolated instead.
So you can use:
_context.Database.ExecuteSqlRaw("TRUNCATE TABLE[TableName]");

REGEXP_MATCH in BigQuery Standard SQL

Although the BigQuery Standard SQL documentation mentions the function REGEXP_MATCH[1], it seems to be unavailable when running a query, with the web interface returning:
Error: Function not found: REGEXP_MATCH
What would be an alternative to using it?
[1] https://cloud.google.com/bigquery/sql-reference/functions-and-operators#regexp_match
what would be an alternative to using it?
You should use REGEXP_CONTAINS

jOOQ MERGE support for PostgreSQL conditional insert

I had understood that jOOQ would simulate SQL MERGE on systems (such as PostgreSQL) that don't support it.
I have a table with a serial (autoincrement) "id" column and a string "uri" column. I want to use numeric IDs instead of URIs in my database, so I have to make sure I have a URI in the ID lookup table. So following the example in the jOOQ manual, I thought this would work:
createDSLContext().mergeInto(tableByName("uris"))
.using(createDSLContext().selectOne())
.on(fieldByName("uri").equal("http://example.com/"))
.whenNotMatchedThenInsert(fieldByName("uri"))
.values("http://example.com/").execute();
This gives me a DataAccessException saying something like:
SQL [merge into "uris" using (select 1) on "uri" = ? when not matched then insert ("uri") values (?)]; ERROR: syntax error at or near "merge"
But then the log says jOOQ goes ahead and tries to execute the query with bind values. But the table is never updated. So I'm guessing the jOOQ doesn't simulate MERGE on PostgreSQL?
So I then try the H2 database syntax:
createDSLContext().mergeInto(tableByName("uris"), fieldByName("uri")).values(uri.toString()).execute();
I get:
The H2-specific MERGE syntax is not supported in dialect : POSTGRES
What!? But the jOOQ documentation says that the H2 syntax "can be fully simulated by jOOQ for all other databases that support the SQL standard." Surely PostgreSQL supports the SQL standard. Does it really mean "...the SQL standard version of MERGE?"
Is there any way to get PostgreSQL support for MERGE via jOOQ, or am I stuck doing the same workarounds I would do anyway?
To be sure if a given SQL feature is supported by jOOQ for your database, please consider the Javadoc's #Support annotation on the relevant DSL method. This is also documented in the manual. In this case, DSLContext.mergeInto(), where you can see that this statement is currently only supported for these SQLDialects:
#Support(value={CUBRID,DB2,HSQLDB,ORACLE,SQLSERVER,SYBASE})
MERGE is a very powerful statement that is not really easy to emulate if your database doesn't natively support it.
"can be fully simulated by jOOQ for all other databases that support the SQL standard." Surely PostgreSQL supports the SQL standard. Does it really mean "...the SQL standard version of MERGE?"
Yes of course, the SQL standard MERGE statement must be supported :-) We'll clarify this in the manual. I have registered issue #3183 for this.
Is there any way to get PostgreSQL support for MERGE via jOOQ, or am I stuck doing the same workarounds I would do anyway?
Right now, unfortunately, we don't have a solution for this in PostgreSQL. Feel free to discuss possible solutions on the jOOQ User Group.
Yes , it can support which database support the merge in SQL stand.
but postgresql unsupport this feature in SQL standard.
Please see
F312 MERGE statement
F313 Enhanced MERGE statement
F314 MERGE statement with DELETE branch
http://www.postgresql.org/docs/9.3/static/unsupported-features-sql-standard.html