I mean that in a column there are numbers, [NULL], and empty cell - how to exclude it from the output?
The column looks like that:
|123 |
|23,45 |
| |
|5,67 |
|1,06 |
|[NULL]|
Using expression
SELECT column from scheme.table1...,
how I can get the output like that:
123,
23,45
5,67
1,06
[NULL]
Take care with NULL / empty / 'NULL' values - it's significantly different.
About your task - try to use combine condition, but before - check this dbfiddle
Related
I have a table that stores values like this:
| id | thing | values |
|----|-------|--------|
| 1 | a |[1, 2] |
| 2 | b |[2, 3] |
| 3 | a |[2, 3] |
And would like to use an aggregate function to group by thing but store only the unique values of the array such that the result would be:
| thing | values |
|-------|---------|
| a |[1, 2, 3]|
| b |[2, 3] |
Is there a simple and performant way of doing this in Postgres?
First you take the JSON array apart with json_array_elements() - this is a set-returning function with a JOIN LATERAL you get a row with id, thing and a JSON array element for each element.
Then you select DISTINCT records for thing and value, ordered by value.
Finally you aggregate records back together with json_agg().
In SQL that looks like:
SELECT thing, json_agg(value) AS values
FROM (
SELECT DISTINCT thing, value
FROM t
JOIN LATERAL json_array_elements(t.values) AS v(value) ON true
ORDER BY value) x
GROUP BY thing
In general you would want to use the jsonb type as that is more efficient than json. Then you'd have to use the corresponding jsonb_...() functions.
Suppose there is a table with data:
+----+-------+
| id | value |
+----+-------+
| 1 | 0 |
| 2 | 0 |
+----+-------+
I need to do a bulk update. And use COPY FROM STDIN for fast insert to temp table without constraints and so it can contains duplicate values in id column
Temp table to update from:
+----+-------+
| id | value |
+----+-------+
| 1 | 1 |
| 2 | 1 |
| 1 | 2 |
| 2 | 2 |
+----+-------+
If I simply run a query like with:
UPDATE test target SET value = source.value FROM tmp_test source WHERE target.id = source.id;
I got wrong results:
+----+-------+
| id | value |
+----+-------+
| 1 | 1 |
| 2 | 1 |
+----+-------+
I need the target table to contain the values that appeared last in the temporary table.
What is the most effective way to do this, given that the target table may contain millions of records, and the temporary table may contain tens of thousands?**
Assuming you want to take the value from the row that was inserted last into the temp table, physically, you can (ab-)use the system column ctid, signifying the physical location:
UPDATE test AS target
SET value = source.value
FROM (
SELECT DISTINCT ON (id)
id, value
FROM tmp_test
ORDER BY id, ctid DESC
) source
WHERE target.id = source.id
AND target.value <> source.value; -- skip empty updates
About DISTINCT ON:
Select first row in each GROUP BY group?
This builds on a implementation detail, and is not backed up by the SQL standard. If some insert method should not write rows in sequence (like future "parallel" INSERT), it breaks. Currently, it should work. About ctid:
How do I decompose ctid into page and row numbers?
If you want a safe way, you need to add some user column to signify the order of rows, like a serial column. But do your really care? Your tiebreaker seems rather arbitrary. See:
Temporary sequence within a SELECT
AND target.value <> source.value
skips empty updates - assuming both columns are NOT NULL. Else, use:
AND target.value IS DISTINCT FROM source.value
See:
How do I (or can I) SELECT DISTINCT on multiple columns?
I have to get all the entries from a HBASE table which have values substring of the given input.
For example if my table is like below:
Table | Family | ColumnQualifier | Value
exp | family | column | 1000xyz
exp | family | column1 | 1000abc
exp | family | column2 | 1001abc
I need to get the entries 1000xyz and 1000abc by value filter with input - 1000
I tried the value filter :
scan 'exp', { FILTER => "ValueFilter( =, 'binary:1000')" }
which gives me the exact value 1000.
Thanks in advance!!!!
Use binaryprefix instead of binary as value comparator,
scan 'exp', { FILTER => "ValueFilter( =, 'binaryprefix:1000' )" }
How can I make the list separated by comma formatted as "param1","param2","param3",.."paramN"?
Im using Decision Manager.
In Decision Table
+----------------------------------------------------+
| **Condition** |
+----------------------------------------------------+
| **productDescription in ($param)** |
+----------------------------------------------------+
| FITI,FMSG,MSGC,RUNT,BEAU,LING- |
+----------------------------------------------------+
On Source
when
productDescription in (FITI,FMSG,MSGC,RUNT,BEAU,LING)
I tried putting "$param" but returned
productDescription in ("FITI,FMSG,MSGC,RUNT,BEAU,LING")
Any help would be very much appreciated!
Thanks!
The answer to this is the function MemberOf. This will match your value to the array of values then will tag true if both fields are equal.
After executing that query
select count(*) from tablename WHERE query=';';
that query will return count as 20.
But that table having totally 771498 records. while execute on SHOW STATUS LIKE 'sphinx_%';
it has return like this
+--------------------+--------+
| Variable_name | Value |
+--------------------+--------+
| sphinx_error | 5732 |
| sphinx_time | 837 |
| sphinx_total | 1000 |
| sphinx_total_found | 771498 |
| sphinx_word_count | 0 |
| sphinx_words | |
+--------------------+--------+
Here i have doubt .
what is sphinx_error?
what is sphinx_time?
what is sphinx_total?
what is sphinx_total_found?
what is sphinx_word_count?
what is sphinx_words?
It will be very helpful for me. Advance thanks
firstly sphinxse is not a real mysql table. Its a fake table. It accepts a query, then sphinxse forwards it to a running instance in the background, and returns the results to produce a 'table' to mysql.
So count(*) wont work. It simply runs the query and counts the rows. There are only 20 rows, unless you ask for more.
sphinx_error? - indicates an error - maybe SHOW WARNINGS would get the text.
sphinx_time? - how long in milisecons the query took
sphinx_total? - how many records you can actully retrieve (subject to max_matches)
sphinx_total_found? - how many records actully match
sphinx_word_count? - the number of words in your query
sphinx_words? - how many docs/hits match each of the words - because you have no query, its empty.