Tag Info

New answers tagged

0

The immediate cause of the infinite loop is this. Per documentation: Note in particular that EXECUTE changes the output of GET DIAGNOSTICS, but does not change FOUND. But there's more: CREATE FUNCTION upsert(_ins text, _upd text) RETURNS int AS $func$ DECLARE loop_ct int := 0; row_ct int; BEGIN LOOP IF loop_ct > 1 THEN -- terminate ...


0

The bad news: Prepared statements do not work like that. Parameters can only be data, not code or identifiers. The good news: you do not need parameters for a ALTER TABLE statement at all. final String sqlps = "ALTER TABLE filen ADD COLUMN gn_id integer"; ... ps = con.prepareStatement(sqlps); ps.execute(); Your column needs a data type. I added ...


0

You can't use ? parameters for identifiers. This is common across database brands. Use format() , like this: text sql = format('ALTER TABLE %I ADD COLUMN %I', table_name, column_name); %I means identifier. It will use identifier rules when substituting values for %I. For added security you can whitelist characters and identifier names and throw an ...


6

The other thing you could do is create a view that unions the like tables together, and include a defined column with the table name, then just do a select against that view with the tablename in the where clause. CREATE VIEW tablesviews AS SELECT columns, 'TABLE1' as tablename FROM Table1 UNION ALL SELECT columns, 'TABLE2' as tablename FROM Table2 ... ...


2

one way i could think of is below.. create proc dynamictable ( @name varchar(100) ) as begin if @name ='tablename1' begin select columns from tablename1 end if@name='tablename2' begin select columns from tablename2 end end


0

Perhaps you can use some user defined variables. I once wrote an answer to this : Disable trigger for just one table. I suggested setting up a user defined variable to disable a trigger. In your case, dynamic SQL is not necessary if you are simply changing parameter values for a SQL statement. If you are changing table names and column names for the query, ...



Top 50 recent answers are included