Does anyone know if it is possible to set auto-uppercase for function names in DBeaver?
For example, I'd like MIN(), MAX() to be my default, instead of min(), max().
I am already using the setting Keyword case: Upper in Preferences -> SQL Editor -> Formatting, but I don't see an option to do this for function names.
Related
I have a Postgres function defined as follows:
CREATE OR REPLACE FUNCTION my_test_function(query_since timestamp) RETURNS TABLE () ...
Can I update the name of the parameter, query_since, to query_from without dropping the function?
The documentation for CREATE OR REPLACE FUNCTION makes it clear that I can not change the argument types using this SQL command. While it does not specifically mention argument names, I suspect the same restriction applies.
Checking the manual: it does, in fact, mention the same restriction for argument names in the Description section:
To replace the current definition of an existing function, use CREATE OR REPLACE FUNCTION. It is not possible to change the name or
argument types of a function this way (if you tried, you would
actually be creating a new, distinct function).
Bold emphasis mine.
(But, like you commented, seems to refer to the function name rather than argument names.)
Either way, since you can refer to parameter (argument) names inside the function body in PL/pgSQL or SQL functions, simply renaming is not an option.
Using SQL I would like to know if its possible to do the following:
If I have a variable that the user inputs mutiple strings into seperated by a comma for example ('aa','bbb','c','dfd'), is it possible using LIKE with a wilcard at the end of each string in stead of having the user to enter each variations in multiple macros.
So say if user was looking for employee numbers that start with ('F','E','C') is it possible without using OR statements is the question I guess am asking?
It would be similar to that of an array I guess
No, LIKE is its own operator and therefore needs separated by an OR.
You might prefer ILIKE to LIKE, as it is a case-insensitive comparison.
You can also try to use REGEXP_LIKE, which is similar to what you want, except you'll have to use regex expressions instead of 'FEC%'
That depends on your SQL dialect; I don't know Impala at all, but other SQL engines have support for regular expressions in string matches, so that you can build a query string like
SELECT fld FROM tbl WHERE fld REGEXP '^[FEC].*$';
No matter what you do, you will need to build a query from your user's input. Passing through user input unprocessed into your SQL processor is a big "nope" anyways, from a "don't accidentally delete a table" point of view:
I need to create a WHERE-IN query (using Oracle) that is case insensitive. I've tried this way:
select user from users where lower(user) in lower('userNaMe1', 'useRNAmE2');
but I get ORA-00909: invalid number of arguments
The list is dynamically generated in my Spring app. That's why I can't add lower() to every single list's value.
Is there any other way to achieve it?
lower() takes a single argument, so you can use:
where lower(user) in (lower('userNaMe1'), lower('useRNAmE2'))
You could also express this using regular expressions (regexp_like() accepts a case sensitivity argument) if you prefer:
where regexp_like(user, '^(userNaMe1|useRNAmE2)$', 'i')
There is another more drastic approach, and is to make your session or your searching in the database case insensitive.
You can find how to do it in this answer:
Case insensitive searching in Oracle
I have a database of videos with a field for both the video width, and height.
I have queries set up to get videos of a specific resolution however it fails to return any videos that are portrait/vertical.
I would like to be able to do something like WHERE MIN(width, height) == 1080 but to my knowledge, this isn't possible.
Is there anyway I can get my desired effect in SQLite?
SQLite supports multi argument min function which behaves like LEAST function.
min(X,Y,...)
The multi-argument min() function returns the argument with the
minimum value. The multi-argument min() function searches its
arguments from left to right for an argument that defines a collating
function and uses that collating function for all string comparisons.
If none of the arguments to min() define a collating function, then
the BINARY collating function is used. Note that min() is a simple
function when it has 2 or more arguments but operates as an aggregate
function if given only a single argument.
So you must be able to use it in the WHERE clause as you have mentioned in the question
You are looking for a CASE expression in your SELECT.
Something like
CASE WHEN width>height THEN height ELSE width END = 1000
How am I going to use BETWEEN Operator with Text Value or what is the right syntax when you will select all products with a ProductName for example ending with any of the letter BETWEEN 'C' and 'M'?
Most SQL dialects provide the RIGHT() function. This allows you to do:
WHERE RIGHT(TextValue, 1) BETWEEN 'C' AND 'M'
If your database doesn't have this function, you can do something similar with the built-in functions. Also, the exact comparison might depend on the collation of the column/table/database/server. Sometimes comparisons are independent of case and sometimes they are dependent on case.
In case you are interested in an alternative method (which does work with the w3schools SQL editor), you can also use the LIKE operator:
WHERE ProductName LIKE '%[c-m]'
This will get you all Product Names ending on any character between C and M.
(It does work with the w3schools SQL Editor.)
In this case, the LIKE operator is using two wildcard characters:
1.%
Any string of zero or more characters.
2.[c-m]
Any single character within the specified range ([a-f]) or set
([abcdef]).
You can find more information about the LIKE operator here:
https://msdn.microsoft.com/en-us/library/ms179859.aspx