Unable to query PostgreSQL with Apache Drill 1.11, VALIDATION ERROR - apache-drill

I managed to connect Drill and PostgreSQL but even for a simple command like show tables I am receiving:
org.apache.drill.common.exceptions.UserException: VALIDATION ERROR: Multiple entries with same key: campaign_items=JdbcTable {campaign_items} and campaign_items=JdbcTable {campaign_items}
I have two schemas public and fdw which contains the same table name campaign_items. How can I force Drill to use the fully qualified name to avoid confusion? Any other suggestions?

To use show tables, you need to select the schema first:
First issue the USE command to identify the schema for which you want to view tables or views. For example, the following USE statement tells Drill that you only want information from the dfs.myviews schema:
USE dfs.myviews;
https://drill.apache.org/docs/show-tables/

Related

MySQL: How to list all tables that are used in a procedure?

I'm looking for a method or a query to retrieve all tables that are used in a procedure.
I tried information_schema.routinesbut it contains all the definition for a procedure.
Is there any system table that contains the dependency relationship for this ?
Or how can I get table names from the definitions using other language such as Python?
Thanks a lot!!
The current version of MySQL does not implement such a view in INFORMATION_SCHEMA.
MySQL 8.0.13 added I_S.VIEW_TABLE_USAGE, which allows you to look up the tables used by a view. This was done for WorkLog #11864. That WorkLog notes compatibility with PostgreSQL and Microsoft SQL Server.
However, there is no WorkLog I can find for an hypothetical I_S.ROUTINE_TABLE_USAGE table. I checked PostgreSQL, and it has this view: https://www.postgresql.org/docs/current/infoschema-routine-table-usage.html but MySQL does not.
So to get this information automatically, you would have to query the procedure body, and parse it for table references. Not an easy task.

How to scope a MySQL JOOQ rename table query to the same database?

I have a scala application that manages multiple MySQL database schemas, which includes modifying (adding, renaming, etc.) tables. The commands are issued over a connection pool that connects to a generic management database in the database server.
Because the application is designed to be cross-database, I use JOOQ to render SQL queries (execution is done via a separate JDBC module).
I experience issues with JOOQs alterTable(...).renameTo(...) DSL - consider the following example:
We have a table "TestTable" in database "TestDatabase". Let's say I want to rename that table simply to "Foo", keeping it in "TestDatabase".
This code:
...
val context = DSL.using(SQLDialect.MYSQL_5_7)
val query = context
.alterTable(table(name("TestDatabase", "TestDatabase")))
.renameTo(name("TestDatabase", "Foo"))
...
Generates: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `Foo`
However, since the connection pool I'm using is connected to my management database, it just renames the table to "Foo" and moves it to my management database. I would have expected the SQL to be: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `TestDatabase`.`Foo`. I tried a variety of alternatives to invoke the .renameTo method and convice it to use the fully qualified name, to no avail:
.renameTo(table(name(...) -> same behaviour.
.renameTo("`TestDatabase`.`Foo`") -> Escapes the name with backticks, treats it as one name instead of a qualified name.
I'm wondering if I'm missing something, if this is intended behaviour, or maybe even a bug or design shortcoming of JOOQ.
Is there a way to rename the table using fully qualified names?
Thank you!
That's a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/8042
Your workaround is close. This doesn't work:
.renameTo("`TestDatabase`.`Foo`")
As you've noticed, behind the scenes, the DSL.name() API is used to wrap the target name, because the renameTo() method doesn't implement the plain SQL templating API. You can, however, explicitly use plain SQL templating by writing as a workaround:
.renameTo(table("`TestDatabase`.`Foo`"))

Print status of database table

I need to print the current status of db table as the db sees it (not what the models think it is).
I'm using Django 1.8. And MySQL.
For example, https://code.djangoproject.com/ticket/23505 shows a status of a table at the bottom. How'd that happen?
In MySQL, you probably want to use DESCRIBE tablename; you can get more information about ways to inspect your database in the official docs.
Note that other databases will use other methods; Django itself is database-agnostic.

Dreamfactory Cannot Insert Rows Into SQL Server 2008 R2

Can connect and GET data from MS SQL Server from Dreamfactory.
Using dblib (library/driver)
When I try to use the createRecords method, I get a strange error.
If I try to insert records into a table called "iyer_test", I get an error that says table "EMP_OnRolls" does not exist in database.
Why do you think DSP should report an unrelated table as non-existent?
I am trying all this from the Swagger UI - so authentication, session and all other prerequisites are hopefully taken care of.
Service definition : Database Driver : dblib:host=del-xxxxxxxx:1433;dbname=utilities
I can connect to the database server with the user name supplied and the user has rights to read/write/modify rows in the tables. Confirmed with SQL Server Management Studio.
In the Swagger UI, if I enter the table name as "dbo.iyer_temp" I get an error that says dbo.iyer_temp table does not exist.
The body I pass to the createRecord method is {
"record": [ {
"lname" : "Iyer",
"fname" : "K Y
}]
}
The table iyer_temp has an id column called "id".
Why should the DSP report a strange table as not available?
Thanks in anticipation
Best wishes
Iyer
Current versions of the database service attempt to pull other schema from other tables that are viewable given the accessed credentials to determine relationships between tables (note, an upcoming release due out in the next week or so is smarter about what data is pulled). If you list tables available using the getResources() or getTables() method, does that table show up in the list?
If so, that is what is going on, the service is trying to pull schema from that table to determine if they are related. Is there a reason why that table is accessible for retrieving table names but not for schema?
Mark of Dreamfactory mentioned that the php5-sybase driver probably has a problem with MS SQL Server tables with hyphens in the table name.
After removing hyphens from the table name, inserts have worked fine.
Thanks
Iyer

How to accomplish "MySQL cross database reference" with PostgreSQL

We will migrate the database from mysql to postgresql in our product(through java). So we need to change the mysql query to postgresql query in java application. How to create the table i.e., databasename.tablename in postgresql.
For mysql, we can directly create the table e.g create table information.employee.
Here database name is "information" and table name is "employee" . Is it possible to achieve same query in postgresql.
I searched google it says cross database reference is not possible. Please help me.
I saw pg_class table it contains the table names in the specific database, like wise databse and tables relationships are stored in any other table.
This is normally done using schemas rather than databases, which is more or less like how MySQL organizes it anyway.
Instead of
create database xyz
use
create schema xyz
When you create tables, create them:
create table xyz.myTable
you will need to update your search path to see them on the psql command line tool, or if you want to query them without using the schema explicitly. The default schema is public, so when you create a table without a schema name, it ends up in public. If you modify your search_path as below, the default schema becomes the first in the list: xyz.
set search_path=xyz,public,pg_catalog;
and you must not have spaces in that statement. You can do it globally for a user/role too:
alter role webuser set search_path=xyz,public,pg_catalog;
Also, don't forget that postgresql string matches are case sensitive by default (this one catches people out a lot).
If you want to have different physical locations for the files for each schema, you can do that with tablespaces. If you have a look at the postgresql documentation page, they have info on how to do it, it's pretty easy.
database in MySQL == schema in PostgreSQL. So you will most probably want to migrate all your mysql dbs into one postgres db. Then you will be able to do "cross-database" queries.
See my answer to this question: Relationship between catalog, schema, user, and database instance