Hi, Joeri and Lefteris,
Thanks for the help. Here's a more specific scenario of what I want to achieve. Consider the following function definition statement:
set schema user_data_schema; create function functions_schema.csTest() returns table( yearAndWeek bigint ) begin return table( select functions_schema.getYearAndWeek( et ) from stats_table ); end;
Notice that I have explicitly indicated the schema for the functions that are shared among all users: *functions_schema*. The data tables, however, vary per user, and *stats_table* belongs to each of these different schemas.
I was expecting *stats_table* to be pulled, automatically, from the default schema that I'm using in the current session where I execute the function definition statement (i.e. *user_data_schema*). However, I get the following error: [Code: 0, SQL State: 42S02] SELECT: no such table 'stats_table'
It seems that any non-explicit-schema tables that appear in the body of a function are understood, by default, as belonging to the same function schema -- and therefore *stats_table* is not found in the *functions-schema*. And that's true, it's not there, and I'd like it to not be there.
It appears the limitation here is that if I have a function that uses data tables, both the function and the data tables must belong to the same schema. Please confirm if this is true.
If you know of another work around this issue, please let me know.
Luis Ángel
-----Original Message----- From: users-list [mailto:users-list-bounces+luis.larios=sysorex.com@monetdb.org] On Behalf Of Joeri van Ruth Sent: Thursday, March 16, 2017 7:12 AM To: Communication channel for MonetDB users users-list@monetdb.org Cc: Ron Edmeades Ron.Edmeades@sysorex.com; Austin Guthals Austin.Guthals@sysorex.com Subject: Re: How to execute a query string in MonetDB
Hi Luis!
I'm afraid there is currently no support for executing a string as SQL in MonetDB.
Without the specifics of your use case it is hard to come up with a suggestion for an alternative approach. If it involves for example several user specific schemas which all share some data and functionality from one common schema, you might be able to play games with the default schema for a user: refer to the common items with an explicit schema qualifier and to the user specific items without. But it's hard to tell in general.
Joeri
On Wed, Mar 15, 2017 at 11:22:42PM +0000, Luis Larios wrote:
Hi,
I'm attempting to declare a query string to execute in MonetDB. The documentation is not clear if this is possible, but other engines allow this functionality (such as MySQL and MS SQL Sever). Trying the following
execute 'select * from tables';
fails with the message
Error: syntax error, unexpected STRING, expecting IDENT or sqlINT
The reason behind this is that I need to declare a variable *schema name*, such that I can execute a query in the following way:
declare s varchar(32); set s = 'the_schema'; execute 'select * from ' || the_schema || '.the_table';
Please let me know if this is even possible in MonetDB or if you have some tips about that. I tried with a *prepared statement*, as given in MonetDB's documentation -- but the following code cannot execute
prepare 'select * from ' || the_schema || '.the_table'; because prepare expects an actual query, not a string.
I'd like to achieve this with only SQL stored functions. The client I have has to execute the SQL functions directly, and there's no intermediate Java/PHP/etc scripts to build the SQL on the fly before they're being sent to MonetDB server. Thus, I should create a function like so:
create function getData( dataSchema varchar(32) ) returns bigint begin declare query varchar(128); set query = 'select count(*) from ' || dataSchema || '.the_table'; return( execute query ); end;
My function is more complicated than this, with other tables and even functions. The issue is that functions belong to one schema, and data tables belong to another schema, which is not known in 'compile' time.
Thanks for the help!
Luis Ángel
The information transmitted, including any attachments, is intended only for the individual or entity to which it is addressed, and may contain confidential and/or privileged information. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by individuals or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you have received this communication in error, please delete the information from any computer and notify the sender.
users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list
_______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list