In kbase database, is there "!=" operator or some syntax can be used as "!="?
In kbase database, there is not "!=" usage, but can use "not" instead of "!=";
For example: select * from tableName where feildName1= value1 not feildName2=value2
Related
I am using pgv10. The function that I need seems this wrong function:
CREATE FUNCTION array_coalesce(ANYARRAY) RETURNS ANYARRAY AS $f$
SELECT CASE WHEN $1 IS NULL THEN array[]::ANYARRAY ELSE $1 END;
$f$ language SQL IMMUTABLE;
Curiosity
... I started to simplify a complex problem, and arrives in the test select coalesce(null::text[], array[]::text[]) that not worked... So it was a good question, how to implement it? But sorry, I do something workng, COALESCE(array,array) is working fine (phew!).
So, "coalesce problem" is merely illustrative/didatic. What I really want to understand here is: How to use ANYARRAY?
PS: other curiosity, the string concat(), || and other concatenation operators in PostgreSQL do some "coalescing",
select concat(NULL::text, 'Hello', NULL::text); -- 'Hello'
select null::text[] || array[]::text[]; -- []
select array[]::text[] || null::text[]; -- []
How to use anyarray?
It's an interesting issue, in the context of the usage described in the question. The only way I know is to use an argument as a variable. It's possible in plpgsql (not in plain sql) function:
create or replace function array_coalesce(anyarray)
returns anyarray as $f$
begin
if $1 is null then
select '{}' into $1;
end if;
return $1;
end
$f$ language plpgsql immutable;
select array_coalesce(null::int[]);
array_coalesce
----------------
{}
(1 row)
By the way, you can simply use coalesce() for arrays:
select coalesce(null::text[], '{}'::text[]);
coalesce
----------
{}
(1 row)
Is there 'concat' function in GreenPlum? I can use concat function in postgresql and it works well, but when i use it in Greenplum, I got an error.
select concat('a', 'b');
ERROR: function concat(unknown, unknown) does not exist at character 8
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
LINE 1: select concat('a', 'b');
^
Is there some other functions can instead of 'concat' function in GreenPlum? And I have tried to create a function to instead of it, but got some syntax errors also.
CREATE OR REPLACE FUNCTION my_concat(VARIADIC arr VARCHAR[] ) RETURNS VARCHAR AS $$ SELECT array_to_string(arr, ''); $$ LANGUAGE SQL;
ERROR: syntax error at or near "VARCHAR" at character 51
LINE 1: CREATE OR REPLACE FUNCTION my_concat(VARIADIC arr VARCHAR[] ...
^
Anyone can help? Thanks very much!
Like most databases, Greenplum uses "||" to concatenate two strings together.
SELECT 'Green' || 'plum';
Result:
Greenplum
its a versional issue , you have use || in place where ever u using contact function.
Greenplum doesn't have the concat function yet. May be you can modify your code to use "||" instead of concat.
Well,
First I agree that you should replace your code to use the correct SQL syntax '||' for concatenation.
If you really want to create a function to emulate the concat, you could do something like:
create or replace function myschema.concat(arg1 text, arg2 text)
returns text as
$body$
declare
v_arg1 text;
v_arg2 text;
begin
v_arg1 := arg1;
v_arg2 := arg2;
return v_arg1 || v_arg2;
end
$body$
language plpgsql volatile;
Then, the query will work:
select myschema.concat('test1', 'test2');
>>test1test2
Hope you are looking for the below query.
gpadmin=# CREATE OR REPLACE FUNCTION my_concat( character varying[] ) RETURNS VARCHAR AS $$ SELECT array_to_string($1, ''); $$ LANGUAGE SQL;
gpadmin=# select my_concat(ARRAY['Green','plum']);
my_concat
Greenplum
created Index
CREATE INDEX MasterIndex
ON [Attendance].[dbo].[Attendence] (location,createdby,program,batch,term)
tried query
SELECT *
FROM [Attendance].[dbo].[Attendence] USE INDEX (MasterIndex) WHERE createdby='pravin' and term='Term III' and batch='80' and program='computer' and location='AMD'
error
Incorrect syntax near 'INDEX'. If this is intended as a part of a
table hint,
A WITH keyword and parenthesis are now required.
Use the WITH Clause
SELECT *
FROM [Attendance].[dbo].[Attendence] WITH (INDEX (MasterIndex)) WHERE ...
q) Use COUNT and DISTINCT to determine how many distinct skus there are
in the skuinfo, skstinfo, and trnsact tables. Which skus are common to all tables, or unique to specific tables?
A) I was trying to find the solution to the above q in TERADATA. The first part was simple i was able to run three commands and got the distinct skus (stock keeping unit).
Now to find the common sku in all three table i am running the command but having errors :
SELECT COUNT(DISTINCT a.sku),COUNT(DISTINCT b.sku),COUNT(DISTINCT c.sku)
FROM skuinfo a INNER JOIN skstinfo b INNER JOIN trnsact c
ON a.sku=b.sku AND b.sku=c.sku;// Why is there error if i use **Where** in Place of ON?
**Error Occurred . . .**
[com.teradata.commons.datatools.sqlparsers.common.ParseException: Encountered ";" at line 3, column 31. Was expecting one of: "and" ... "at" ... "cross" ... "day" ... "full" ... "hour" ... "inner" ... "join" ... "left" ... "minute" ... "month" ... "on" ... "or" ... "right" ... "second" ... "timezone_hour" ... "timezone_minute" ... "year" ... "||" ... "(" ... "**" ... "+" ... "-" ... "*" ... "/" ... "mod" ... "." ... "[" ... ]
Please let me know why is my syntax not working, though most forums say the query is right. Thanks
I encounter an appengine error from a GQL query with "IN" operator. my query is as follows:
SELECT * FROM ratings WHERE rating >= 0.0 AND cat = 1 AND pid IN(44,14)
the error message is:
PHP Fatal error: Uncaught exception 'google\appengine\runtime\ApplicationError' with message 'Encountered "IN" at line 1, column 84.
Was expecting one of:
"contains" ...
"has" ...
"is" ...
"=" ...
"<" ...
"<=" ...
">" ...
">=" ...
"." ...
"(" ...
' in /base/data/home/runtimes/php/sdk/google/appengine/runtime/RealApiProxy.php:53
I put my query in datastore admin console It works without any error and showed the exactly result.
What's wrong??
You are confused about what the IN operator does. It can not do what you want.
Please read the docs on cloud datastore https://cloud.google.com/datastore/docs/apis/gql/gql_reference
Notice that the operator = is another name for the IN and CONTAINS operators. For example, <value> = <property-name> is the same as <value> IN <property-name>, and <property-name> = <value> is the same as <property-name> CONTAINS <value>. Also <property-name> IS NULL is the same as <property-name> = NULL.