dynamic-sql

How to get a result from dynamic SQL in Postgres?

五迷三道 提交于 2019-12-20 01:12:48
问题 Raw Table for which rule are stored in one table named md_formula , which are used to map in destination table Drop/Create/Insert for raw_dbs_transactiondetailscash : DROP TABLE raw_dbs_transactiondetailscash CREATE TABLE raw_dbs_transactiondetailscash( accountnumber VARCHAR(100), referencecurrency VARCHAR(100), transactiondate datetime) INSERT INTO raw_dbs_transactiondetailscash( accountnumber, referencecurrency, transactiondate) SELECT 'XYZ','$','01/01/2016' Drop/Create/Insert for md

Dynamically creating columns from row data using Select in Bigquery

≡放荡痞女 提交于 2019-12-19 10:21:33
问题 Background I want to rename my case statement in sql select statement dynamically. Eg: SELECT (case when id= x.id then x.sums end) x.id as (select id,count(*) sums from table group by id) x what i want the output is list of columns created ,with Labels as distinct id's from "id" column. However,this variable x.id is not dynamically outputing values,rather i get output a single column x.id. Eg: Columns in table... id---c1----c2 1----x1---x2 2----x2----x3 3----x4----x5 columns expected after

Trigger with dynamic field name

大兔子大兔子 提交于 2019-12-19 07:43:24
问题 I have a problem on creating PostgreSQL (9.3) trigger on update table. I want set new values in the loop as EXECUTE 'NEW.'|| fieldName || ':=''some prepend data'' || NEW.' || fieldName || ';'; where fieldName is set dynamically. But this string raise error ERROR: syntax error at or near "NEW" How do I go about achieving that? 回答1: You can implement that rather conveniently with the hstore operator #= : Make sure the additional module is installed properly ( once per database), in a schema

Trigger with dynamic field name

可紊 提交于 2019-12-19 07:41:51
问题 I have a problem on creating PostgreSQL (9.3) trigger on update table. I want set new values in the loop as EXECUTE 'NEW.'|| fieldName || ':=''some prepend data'' || NEW.' || fieldName || ';'; where fieldName is set dynamically. But this string raise error ERROR: syntax error at or near "NEW" How do I go about achieving that? 回答1: You can implement that rather conveniently with the hstore operator #= : Make sure the additional module is installed properly ( once per database), in a schema

Trigger with dynamic field name

♀尐吖头ヾ 提交于 2019-12-19 07:41:08
问题 I have a problem on creating PostgreSQL (9.3) trigger on update table. I want set new values in the loop as EXECUTE 'NEW.'|| fieldName || ':=''some prepend data'' || NEW.' || fieldName || ';'; where fieldName is set dynamically. But this string raise error ERROR: syntax error at or near "NEW" How do I go about achieving that? 回答1: You can implement that rather conveniently with the hstore operator #= : Make sure the additional module is installed properly ( once per database), in a schema

Oracle EXECUTE IMMEDIATE into a cursor

天大地大妈咪最大 提交于 2019-12-19 06:23:09
问题 I have a stored procedure which used the EXECUTE IMMEDIATE command to execute a very long string. How do I support a very long string and return the data into a refcursor? 回答1: Assuming that your SQL is not longer than 32K (as @Tony Andrews hinted at), you should be able to use something like this: declare SQL_Text varchar2(32760) := 'select * from dual'; --your query goes here cur sys_refcursor; begin open cur for SQL_Text; end; When working with Ref Cursors, open-for can be used directly,

Create A View With Dynamic Sql

柔情痞子 提交于 2019-12-19 05:48:13
问题 I'm trying to create a dynamic database creation script. There are a lot of steps and we create this database often so the script looks something like this. DECLARE @databaseName nvarchar(100) = 'DatabaseName' EXEC('/*A lot of database creation code built off of @databaseName*/') This is all well and good except for one view that we'd like to create in @databaseName . I've tried four different ways to create this view without success: My first thought was to simply set the database context

Dynamic SQL - Check syntax and semantics

天涯浪子 提交于 2019-12-19 04:00:58
问题 With Oracle dynamic SQL one is able to execute a string containing a SQL statement. e.g. l_stmt := 'select count(*) from tab1'; execute immediate l_stmt; Is it possible to not execute l_stmt but check that the syntax and semantics is correct programmitically? 回答1: EXPLAIN PLAN will check the syntax and semantics of almost all types of SQL statements. And unlike DBMS_SQL.PARSE it will not implicitly execute anything. The point of the explain plan is to show how Oracle will execute a statement.

Dynamic SQL - Check syntax and semantics

人盡茶涼 提交于 2019-12-19 04:00:10
问题 With Oracle dynamic SQL one is able to execute a string containing a SQL statement. e.g. l_stmt := 'select count(*) from tab1'; execute immediate l_stmt; Is it possible to not execute l_stmt but check that the syntax and semantics is correct programmitically? 回答1: EXPLAIN PLAN will check the syntax and semantics of almost all types of SQL statements. And unlike DBMS_SQL.PARSE it will not implicitly execute anything. The point of the explain plan is to show how Oracle will execute a statement.

Prepend table name to each column in a result set in SQL? (Postgres specifically)

让人想犯罪 __ 提交于 2019-12-18 20:49:51
问题 How can I get the label of each column in a result set to prepend the name if its table? I want this to happen for queries on single tables as well as joins. Example: SELECT first_name, last_name FROM person; I want the results to be: | person.first_name | person.last_name | |-------------------|------------------| | Wendy | Melvoin | | Lisa | Coleman | I could use "AS" to define an alias for each column, but that would be tedious. I want this to happen automatically. SELECT first_name AS