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.
Related
In PostgreSQL, I have a column with people's height in meters. If the height is, say 1.75 m, it shows properly, but if the height is 1.70 m, it shows as 1.7. I would like to have this already formatted to two decimal places, showing as 1.70 without formatting in each and every SQL call. Can I specify this in the table creation? Or a stored procedure, or something? I've seen a few things about timestamps, but not for real fields. Knowing how to format the decimal point as a colon (1,70) would be a plus.
Basically, presentation and "cosmetics" are the job of the application, not the database.
Having a default number of decimal places for floats would also create a problem, because the data returned by the database would not be the actual data in the column. So if you did a SELECT and it returned a value of 1.75, then if you searched for this value, you might not find it because the actual value stored was not 1.75 but 1.7499999999 and it was only rounded for display.
Potential solutions:
If you want to store a specified number of digits, use NUMERIC. This will solve the 1.7499999999 problem above. If you use NUMERIC, when doing a SELECT you get the actual contents of the column.
In your app, if you use an ORM, use a Decimal (or similar) type for the column with the appropriate settings so it displays the way you want.
Or create a view with the format applied to the column, but in this case if you want the trailing zero, the type will be text and not float, and it will not be searchable unless you create an extra index on it.
Generated column with the number formatted as you want, maybe easier than a view
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.
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
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;
Message => FRM-40831: Truncation occurred: value too long for field PHONE.
I have table named 'CLIENT'. The table has many fields. One of the field name is 'PHONE'. The field data type and length is VARCHAR2(20 byte). By using the 'CLIENT' table I have created a form using Forms Developer 10g. It works fine. But I have changed the field length and Forms Property Value as VARCHAR2(40 byte) and Forms Property > Maximum Length = 40. Now the Form data save smoothly. But when I am going to retrieve data the message shows => FRM-40831: Truncation occurred: value too long for field PHONE.
N.B: The message shows when it gates the value over than 20 characters otherwise not.
How to solve the problem?
Please help me.
Apparently you are facing the multi-byte character set problem.
Define your column as VARCHAR2(40 CHAR).
Currently the column can contain only 40 bytes, so if - as I assume - you use multi-byte character set in your database, the truncation occurs.