postgresql remove characters start with - postgresql

I want to make a postgresql query which removing characters. For example, my datas are like this;
John Smith https://john.smith.com
Allen Paul https://allen.paul.com
I want to remove characters which start with https. I want to see in the final like this;
John Smith
Allen Paul
Can anybody help me. Thanks...

split_part is good for this:
t=# select split_part('Allen Paul https://allen.paul.com',' https://',1);
split_part
------------
Allen Paul
(1 row)
Time: 1.370 ms

Related

getting the "title" between the names

The name I'm working on is formatted like this:
King, Mr. Jay Thomas
Smith, Miss. Jane
How do I get the middle title part only using Postgres?
I'm a noob so this is definitely wrong:
SELECT position('%#," #"%#' for '#') AS TITLE
FROM titanic;`
You could use SUBSTRING with the regex pattern \w+\.:
SELECT SUBSTRING(title from '\w+\.')
FROM titanic;

How do I convert a string to sentence case in Postgres

With the caveat that this is not a silver bullet, I submit this question and provide my own answer, since after a reasonable college effort, I found myself with no solutions for PostgreSQL.
The task in my case is to convert a collection of largely upper-case-only sentences into a reasonable facsimile of a paragraph using capitalization for just the first letter of each sentence. If that solution is out there, either I'm blind or it was decently well hidden.
So, for example, how do I convert
THE NAME IS BOND. JAMES BOND. 007. AND THIS IS ONE COOL PIECE OF CODE.
to
The name is bond. James bond. 007. And this is one cool piece of code.
?
Here is what I came up with. I'd be glad to award the answer to a better solution!
WITH fixed_sentences_source AS (
WITH single_sentences_source AS (
WITH arrays_source AS (
SELECT
regexp_split_to_array(LOWER('THE NAME IS BOND. JAMES BOND. 007. AND THIS IS ONE COOL PIECE OF CODE.'), '\. ' ) AS arrays
)
SELECT TRIM(UNNEST(arrays)) AS single_sentences
FROM arrays_source
)
SELECT
UPPER(SUBSTRING(single_sentences, 1, 1)) || SUBSTRING(single_sentences, 2, LENGTH(single_sentences) - 1) AS fixed_sentence
FROM single_sentences_source
WHERE
single_sentences <> ''
)
SELECT ARRAY_TO_STRING(ARRAY(SELECT fixed_sentence FROM fixed_sentences_source), '. ')

Title the Result from SphinxSearch

Any way I can title the search results?
Example:
select name from person ;
Will give
abhilash joseph c
But i want it to be 'Abhilash Joseph C'
Can I write udf for sphinx? How can I do it ?

Simply select char, or string

What is the way to achieve expected result from psql select:
SELECT 'Hello world';
using this in SQuirreL I get value: in unnamed column. What is the way to get string Hello world as a result?
I want to use this approach to format outputs using commas, colons, etc. Is there another way to pre-prepare results for further usage?
Thanks in advance for any help
I want get one column with 'Hello word' as its content. Column name is unset here (in squirrel '?column?')
It's because you didn't give that column a name (alias)
If you'll do it like this
SELECT 'Hello world' AS column_name
you'll get
| COLUMN_NAME |
|-------------|
| Hello world |
Here is SQLFiddle demo
This is an old question, but I ran into the same problem with SQuirreL, and found a simple work-around. Try this in SQuirreL:
SELECT trim('Hello world') AS column_name;
Actually, any of the PostgreSQL string functions will work, like upper(), lower(), etc., depending on your needs.
The question is not clear but I give you the possible optionsin one block
begin
declare #PreDefinedVariable nvarchar(50)
Select #PreDefinedVariable = 'Hello World!'
select #PreDefinedVariable as [Result]
end
It is an SQuirreL SQL Client issue, using psql from bash I get expected:
tdb14=> SELECT 'Hello world' AS column_name;
column_name
-------------
Hello world
(1 row)

print column and count the string

I have large column wise text file with space demlimited
Name subject Result
John maths pass
John science fail
John history pass
John geography pass
Jack maths pass
jack history fail
kelly science pass
kelly history pass
I want to count for each name (it is long name list, each name should be appear only once), how many of them pass. For eg. For John, he passed 3 and similarily for Jack he passed 1. It should print the result as
Name Passcount
John 3
Jack 1
Kelly 2
Can anybody can help with awk or perl script. Thanks in advance
You can try something like this -
awk '
BEGIN{ print "Name\tPasscount"}
NR>1{if ($3=="pass") a[$1]++}
END{ for (x in a) print x"\t"a[x]}' file
Test:
$ cat file
Name subject Result
John maths pass
John science fail
John history pass
John geography pass
Jack maths pass
jack history fail
kelly science pass
kelly history pass
$ awk 'BEGIN{ print "Name\tPasscount"} NR>1{if ($3=="pass") a[$1]++}END{ for (x in a) print x"\t"a[x]}' file
Name Passcount
Jack 1
kelly 2
John 3