How to delete imported sql procedures - google-cloud-platform

I have an imported SQL procedure I would like to delete. Its syntax starts with:
DELIMITER ;;
CREATE DEFINER=`cloudsqlimport`#`127.0.0.1` PROCEDURE `someProc`(IN cui_in CHAR(8), IN kind CHAR(20))
...
When attempted to delete it with "root" user, using:
DROP PROCEDURE someProc
I get:
Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
How can I delete this procedure?

Actually the DROP PROCEDURE someProc; must works for this. I have tried at my end, I have created a SP and then I have deleted it using that command as you can see in the below image. So, from where you are trying to perform this task? I would recommend you to use the Cloud Shell since I performed this there with no issue.
UPDATED
It seems like you rae right regarding your comment. When you imported the SP using cloudsqlimport#127.0.0.1 it is not possible to delete it using the command DROP PROCEDURE within MySQL. Nevertheless, as a workaround, you can create a sql file with the following
USE `my-database`;
DROP PROCEDURE IF EXISTS someProc;
DELIMITER ;
Once you have created such a file, you only need to import it to your Cloud SQL database and the SP will be deleted.
As a recommendation I would like to suggest you to do not use cloudsqlimport#127.0.0.1 I think that a best option is to use root#%

DROP PROCEDURE DEFINER.someproc;
syntax :
DROP PROCEDURE .;

Related

PostgREST - How to create tables?

I want to create a new table using postgREST, but I was not able to find anything about this in the documentation. Is it possible to create tables? If yes, how?
Sorry if this questions was already asked, but unfortunately I always found solutions for postgres (without t :D)
Thx :)
you can create stored function that creates the table for you, then call that function via postgrest
something like:
create or replace function create_foo_table() returns void as
$$
begin
execute format('create table foo (id int primary key)')
end
$$ language plpgsql;
then call /rpc/create_foo_table in Postgrest
you'd need to reload Postgrest's schema cache after this, in order to read the table: https://postgrest.org/en/v7.0.0/admin.html?highlight=reload#schema-reloading
This likely has security implications, so be careful, especially if using dynamic SQL to create the table

Select stmt in source qualifier along with procedure call in Informatica

We have a situation where we are dealing with a relational source(Oracle). The system is developed in a way where we have to first execute a package which will enable data read from Oracle and user will be able to get results out of select statement. I am trying to find a way on how to implement this in informatica mapping.
What we tried
1. In PreSQL we tried to execute the package and in SQL query we wrote select statement - data not getting loaded in target.
2. In PreSQL we wrote a block in which we are executing the package and just after that(within same beging...end block) we wrote insert statement on top of select statement - This is inserting data through insert statement however I am not in favor of this solution as both source and target are dummy which will confuse people in future.
Is there any possibility to implement this solution somehow by using 1st option.
Please help and suggest.
Thanks
The stored procedure transformation is there for this purpose configure it to execute source pre load
Pre-Sql and data read are not a part of same session. From what I understand, this needs to be done within the same session as otherwise the read is granted only for the session.
What you can do, is create a stored procedure/package that will grant read access and then return the data. Use it as a SQL Override on your SQ. This way SQ will read the data as usual. The concept:
CREATE PROCEDURE ReadMyData AS
BEGIN
execute immediate 'GiveMeTheReadAccess';
select * from MyTable;
END;
And use the ReadMyData on the Source Qualifier.

flatbuffers: Using add_myTable(table) to encode data

I am trying to use the following method of building a table, as taken from the flatbuffers tutorial:
MonsterBuilder monster_builder(builder);
monster_builder.add_pos(&pos);
monster_builder.add_hp(hp);
But having done this for my root table I am unsure if I need to call .Finish() before adding it to the table that then contains the table above.
Is anyone able to provide me with an example of how usage of the add_member commands may be used in nested tables?
You call .Finish() on any tables you create with a table builder. You call .Finish(root) on your FlatBufferBuilder instance only once at the end to finish construction of the buffer.

In Redshift, how do you combine CTAS with the "if not exists" clause?

I'm having some trouble getting this table creation query to work, and I'm wondering if I'm running in to a limitation in redshift.
Here's what I want to do:
I have data that I need to move between schema, and I need to create the destination tables for the data on the fly, but only if they don't already exist.
Here are queries that I know work:
create table if not exists temp_table (id bigint);
This creates a table if it doesn't already exist, and it works just fine.
create table temp_2 as select * from temp_table where 1=2;
So that creates an empty table with the same structure as the previous one. That also works fine.
However, when I do this query:
create table if not exists temp_2 as select * from temp_table where 1=2;
Redshift chokes and says there is an error near as (for the record, I did try removing "as" and then it says there is an error near select)
I couldn't find anything in the redshift docs, and at this point I'm just guessing as to how to fix this. Is this something I just can't do in redshift?
I should mention that I absolutely can separate out the queries that selectively create the table and populate it with data, and I probably will end up doing that. I was mostly just curious if anyone could tell me what's wrong with that query.
EDIT:
I do not believe this is a duplicate. The post linked to offers a number of solutions that rely on user defined functions...redshift doesn't support UDF's. They did recently implement a python based UDF system, but my understanding is that its in beta, and we don't know how to implement it anyway.
Thanks for looking, though.
I couldn't find anything in the redshift docs, and at this point I'm
just guessing as to how to fix this. Is this something I just can't do
in redshift?
Indeed this combination of CREATE TABLE ... AS SELECT AND IF NOT EXISTS is not possible in Redshift (per documentation). Concerning PostgreSQL, it's possible since version 9.5.
On SO, this is discussed here: PostgreSQL: Create table if not exists AS . The accepted answer provides options that don't require any UDF or procedural code, so they're likely to work with Redshift too.

Drop constraints only if it exists in mysql server 5.0

i want to know how to drop a constraint only if it exists. is there any single line statement present in mysql server which will allow me to do this.
i have tried the following command but unable to get the desire output
alter table airlines
drop foreign key if exits FK_airlines;
any help to this really help me to go forward in mysql
I do not believe this is possible in a single line, unless you are willing to detect the error and move on (not a bad thing).
The INFORMATION_SCHEMA database contains the info you need to tell if the foreign key exists, so you could implement it in a 2 step process.
http://dev.mysql.com/doc/refman/5.1/en/table-constraints-table.html
yep not possible the if exist is available only for database table and view :
http://dev.mysql.com/doc/refman/5.0/en/replication-features-drop-if-exists.html
yep 2 step process is a good way like gahooa said