Netezza substr function- how do i remove set number of chars from the right - substring

i am querying netezza server. i have a string in one of the column and i want to remove the last character in the string. The string is not a fixed length one and the last character is not constant either.
how do i do it?

If your string is s, then you can use substr(s,0,length(s)-1)
Just replace s with whatever you're querying.

Related

I always get a value of 255 characters

I have a table in my Postgres DB. In this table, there is a column city this column has type character and length 255.
When I try to add a city in this column, for example, London and after that, I try to get this city I get a value with 255 lengths.
Looks likes [London....................-255] where dots are empty characters
When I add value in db always doing trim.
I use pg for node js
As the comment says, you don't want to use character(255) as the field type, which is always 255 characters, padded with whitespace.
Instead, you might consider using varchar(255), but even so, you probably don't actually want to limit the length here – Postgres doesn't care, storage-wise!, whereas MySQL does – so just use text.

Getting NULL Value in Stored Procedure TEXT Column

Below Query, I am using to get the SP definition but in TEXT column I am getting as NULL Value in IBM DATA Studio but I am able to CALL the SP.
SELECT PROCNAME, TEXT FROM SYSCAT.PROCEDURES WHERE PROCNAME LIKE '%USP_ABC%'
Please Help
You have confirmed that the syscat.procedures.language is SQL, and that your query-tool is able to display a substr() of the text.
Workaround depends on the length(text) of the row of interest:
SELECT PROCNAME, substr(TEXT,1, 1024) FROM SYSCAT.PROCEDURES WHERE PROCNAME LIKE '%USP_ABC%'
You may need to adjust the length of the substr extract depending on the length of the text and your configuration. For example substr(TEXT, 1, 2048 ) or a higher value for the length as necessary that your query-tool can cope with.
You can find the length of the text column with the LENGTH(TEXT) for the row of interest.
You can also CAST a CLOB to char or varchar to a length that fits within their limits and whatever query tool limitations you have.
Another option is to use a different query tool that can work with CLOB.
Are you using the latest version of Data Studio with the latest fix? It sounds like you might have an invalid UTF-8 character in you SP, or as you are using SUBSTR and SUBSTRING you are breaking a mulit-byte character in two.
You could try setting
-Ddb2.jcc.charsetDecoderEncoder=3
in your eclipse.ini to get Java to use a replacment character rather than replace the invalid string with nul
See this tech note
https://www-01.ibm.com/support/docview.wss?uid=swg21684365
Otherwise, do raise this with IBM Suppport

Datastage decimal separator, how can modify?

I am using datastage in order to generate a csv file with teradata source, when i modifu the job properties searching comma as a decimal separator in local categories it dosnt change, what is the correct way to do this change ?
My issues: datasource teradata, with a job action need to transfor and get out a csv file, but had more than 8 decimal files, my datastage configuration have point as a decimal separator and i need comma. In teradata more than 8 oreplaces give u back row over size error.
Solution: Get the source and cast to varchar, and with datastage trasnform used change function converting the replacing comma in place to point, and get out fields with varchar data type with correct decimal separator.

Pulling a Substring which does not exist in the same position

I am looking to pull a substring from a Oracle database column using PL/SQL.
The column has a large string value which varies in size for different rows. Hence the substring I am referring to will not be in the same position for each row. But the substring is uniquely identifiable. It will be like ",RID!1455,". i.e. It will be preceded by a comma, have RID, followed by a !, followed by a number and then a comma.
I am interested in pulling this number followed by RID. Can you please help me with this. Thank you very much in advance
Consider below query:
Suppose table text1 has column text with string:
dfgggsdRID!3242dfgdfdg
Then below query will give you result '3242':
select substr(text, (select (INSTR(text, 'RID!', 1)+4) FROM text1),4) from text1;

How do I format a number of arbitrary length?

If I have data that includes a numeric column with values into the miillions (eg 63254830038), and I want to format the number as a US Dollar amount (eg. $63,254,830,038), I know I can use:
SELECT numeric_column, to_char(numeric_column, '$999G999G999G999') from table
to format the values, but to do so reliably I either have to include an unnecessarily long text string ('$999G999G999G999') or know the maximum number of possible digits. Is there a way to say, broadly, "group numbers with a comma" instead of explicitly saying "group the hundreds, group the thousands, Oh! and please group the millions"?
You just need cast integer to money type.
E.g.:
tests=> select cast(63254830038 as money);
Or alternative syntax:
tests=> select 6323254830038::money;
And output (I'm from Poland, so money type take my locales and set correct currency symbol):
money
----------------------
63.254.830.038,00 zł
Monetary Types documentation.
You can try something like this (works in sql-server, not sure about postgresql)
select convert(varchar,cast('63254830038' as money),1)
You could do things the hard way using regular expressions: convert the number into a string, reverse it, use regexp_replace to insert commas between pairs of 3 digits, and then reverse it again:
select '$' || reverse(regexp_replace(
reverse(numeric_column::varchar),
E'(\\d\\d\\d)(?=\\d)', '\1,', 'g'))
Explanation
The first argument to regexp_replace is the expression to match, which contains two parts:
(\\d\\d\\d) means 3 digits, which are captured
(?=\\d) is a positive lookahead constraint of a single digit, meaning the match only counts if there is a digit following it. (That is, this digit is checked to exist, but it does not count as part of the match.)
The second argument is what to replace with: the 3 captured digits, plus a comma.
The third argument 'g' is a flag indicating that it should match and replace as many times as possible.
For more information on regular expressions in PostgreSQL, see the documentation.