stored-functions

postgresql with function wrap sql so slow?

为君一笑 提交于 2019-12-23 06:21:14
问题 first sql explain analyse: explain analyse select * from ttq.ttq_post; Seq Scan on ttq_post (cost=10000000000.00..10000000014.71 rows=171 width=547) (actual time=0.005..0.027 rows=176 loops=1) Planning Time: 0.033 ms Execution Time: 0.041 ms but if use function wrap the same sql eg: create or replace function ttq.test_fn_slow() returns setof ttq.ttq_post language sql stable as $$ select * from ttq.ttq_post; $$ and exec blow function: explain analyse select ttq.test_fn_slow(); result:

How does Oracle process stored function calls in SQL?

放肆的年华 提交于 2019-12-22 10:38:41
问题 guys. Say, I have a query: select t.value, my_stored_function(t.value) from my_table t where my_stored_function(t.value) = n_Some_Required_Value I have rewritten it in the following way: select value, func_value from (select t.value, my_stored_function(t.value) func_value from my_table t) subquery where subquery.func_value = n_Some_Required_Value Let's think of my_stored_function as of resource-consuming one. I assume, in the second query it is called twice less, but I didn't experience any

MongoDB: Error executing stored JavaScript function

好久不见. 提交于 2019-12-21 17:15:53
问题 When I run below stored JavaScript function I get errors: > db.system.js.save({_id:"last_n_users", value: function(n){return db.users.find().sort({created_at:-1}).limit(n)}}) > db.eval("last_n_users(10)") Here is the errors: { "value" : "DBQuery: store.users -> undefined" } Why? Please help me? 回答1: The find() function returns a cursor, which can't be returned from JavaScript. The suggested workaround is to use toArray() to get an array return value. Example ... before : > use admin switched

Generate a random number of non duplicated random number in [0, 1001] through a loop

回眸只為那壹抹淺笑 提交于 2019-12-21 09:26:40
问题 I need to generate a random number of non duplicated random number in plpgsql. The non duplicated number shall fall in the range of [1,1001]. However, the code generates number exceeding 1001. directed2number := trunc(Random()*7+1); counter := directed2number while counter > 0 loop to_point := trunc((random() * 1/directed2number - counter/directed2number + 1) * 1001 +1); ... ... counter := counter - 1; end loop; 回答1: If I understand right You need a random number ( 1 to 8 ) of random numbers.

Mysql function call

落花浮王杯 提交于 2019-12-21 02:53:14
问题 If I call a function several time then will it execute every time or just execute once and the value will be used then after several time? Example: select my_function('filed'),my_function('filed')/field2, (my_function('filed')*field1)/field3, ...... from my_table where group by filed1; My question is my_function('filed') will be executed once and then the result will be used in my_function('filed')/field2 and (my_function('filed')*field1)/field3 or every time my_function('filed') will be

Required single query to fetch data from tables

耗尽温柔 提交于 2019-12-19 09:24:16
问题 I have the following tables //all users deails smsusers(id,fname , lname ,primary key(id)); //message details of users //one smsusers can have N messages user_messages(messageid,message,adddate ,sentby,visibility, userid,primary key(messageid),foreign key(userid) references smsusers(id), foreign key(sentby) references smsusers(id)); //One message(user_message) can have N comments comments(comment_id,comment_on ,commented_by,comment_date, comment,foreign key(commented_by) references smsusers

How to properly loop in a stored function on MySQL?

帅比萌擦擦* 提交于 2019-12-19 00:58:10
问题 I am having some difficulty getting a pretty simple stored procedure right. Consider the following article table snippet: id replaced_by baseID 1 2 0 2 3 0 3 0 0 A simple hierarchical table, using copy-on-write. When an article is edited, the replaced_by field of the current article is set to the id of it's new copy. I've added a baseID field, which in the future should store the baseID of an article. In my example above, there is one article (eg id 3). It's baseID would be 1. To get the

View stored procedure/function definition in MySQL

落爺英雄遲暮 提交于 2019-12-18 10:08:58
问题 What is the MySQL command to view the definition of a stored procedure or function, similar to sp_helptext in Microsoft SQL Server? I know that SHOW PROCEDURE STATUS will display the list of the procedures available. I need to see a single procedure's definition. 回答1: SHOW CREATE PROCEDURE <name> Returns the text of a previously defined stored procedure that was created using the CREATE PROCEDURE statement. Swap PROCEDURE for FUNCTION for a stored function. 回答2: You can use this: SELECT

How to pass a parameter from vb.net

假装没事ソ 提交于 2019-12-18 09:35:14
问题 I have a Program that will auto run each night, run a query, and email results. In my program I am calling a function as part of the query... What i'd like to is pass the date the program is run as the parameter. (@startdate and @enddate) @startdate will always be "today's" date at 00:00:00 and enddate will always be "Todays date" at 23:59:59. So for example. If the program was run tonight, it would pass 1/31/13 as the date. Tomorrow, it would pass 2/1/13 as the date, the next date 2/2/13,

C# call oracle stored function

隐身守侯 提交于 2019-12-17 19:51:48
问题 create or replace function ar_knyga_egzistuoja( id number ) return number is kiekis number; begin select count(*) into kiekis from knygos where kn_id = id; return kiekis; end; C# code: conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "ar_knyga_egzistuoja"; cmd.CommandType = CommandType.StoredProcedure; OdbcParameter param = new OdbcParameter(); cmd.Parameters.Add("id", OracleType.Number).Value = id; cmd.ExecuteNonQuery(); var kiekis = Convert