Skip to Main Content
IBM Power Ideas Portal


This portal is to open public enhancement requests against IBM Power Systems products, including IBM i. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

Status Not under consideration
Workspace IBM i
Categories Db2 for i
Created by Guest
Created on Aug 31, 2023

Add something like IF EXIST for a table, view, procedures, etc.

In SQL, I often need to check if a table exists and either delete or create it.

I opened a case and was told the functionality does not exist.

If a file exists, I need to delete/DROP it. Sometimes, I need to create the table.



Idea priority High
  • Admin
    Sabine Jordan
    Reply
    |
    Oct 18, 2023

    The CEAC has reviewed this requirement and recommends that IBM view this as a HIGH priority requirement that is important to address as it is a function that is available in other databases.

    Background: The COMMON Europe Advisory Council (CEAC) members have a broad range of experience in working with small and medium-sized IBM i customers. CEAC has a crucial role in working with IBM i development to help assess the value and impact of individual RFEs on the broader IBM i community and has therefore reviewed your RFE.

    To find out how CEAC help to shape the future of IBM i, see CEAC @ ibm.biz/BdYSYj and the article "The Five Hottest IBM i RFEs Of The Quarter" at ibm.biz/BdYSZT

    Sabine Jordan + Sara Anrdres – CEAC Program Manager, IBM

  • Guest
    Reply
    |
    Oct 1, 2023
    IBM does not intend to provide the solution described by this Idea at this time, so it is being closed.

    There are several ways to deal with existing objects, depending on what you need to accomplish.

    1. To drop an SQL object with no error if it does not exist, use the IF EXISTS clause on the DROP statement.
    DROP TABLE mytable IF EXISTS;

    2. To create a table if it might already exist, use the OR REPLACE clause on the CREATE TABLE statement. You can either keep the existing rows or remove them.
    create or replace table mytable ( id int, name varchar(100)) on replace preserve rows;
    create or replace table mytable ( id int, name varchar(100)) on replace delete rows;

    3. For logic similar to what you described, a compound statement can be used. The following is a single statement. It can be run from within RUNSQL or in Run SQL Scripts.
    begin
    if exists (select * from qsys2.systables where table_schema = 'MYLIB' and table_name = 'MYTABLE') then
    drop table mytable;
    else
    create table mytable ( id int, name varchar(100));
    end if;
    end;

    Db2 for i development team
    IBM Power Systems Development
  • Guest
    Reply
    |
    Sep 1, 2023

    There's not an IF EXISTS function, but wouldn't CREATE OR REPLACE TABLE/PROCEDURE/etc work in this scenario? Or if you want to delete all of the time and then create some of the time, use DROP TABLE/PROCEDURE/etc IF EXISTS (it will not cause an error if the object doesn't exist) followed by the CREATE TABLE/PROCEDURE/etc. statement.