Questions tagged [string]
91 questions
45
votes
3 answers
Using PostgreSQL 8.4, how to convert bytea to text value in postgres?
In my application I insert data in database using C code, since the strings I receive from an untrusted source I have escaped them using PQescapeByteaConn of libpq library. Which is working perfectly fine i.e. results in Octet format String. See…
Amit
- 591
- 2
- 5
- 10
18
votes
3 answers
Convert string numeric values with comma as decimal separator to NUMERIC(10, 2)
I have an SQL table of varchar columns which contain Greek formatted numbers (. as thousand separator and comma as decimal separator)
The classic conversion
CONVERT(numeric(10,2),REPLACE([value],',','.'))
does not work because the . (thousand…
PanosPlat
- 521
- 1
- 6
- 14
13
votes
2 answers
Conditional string concatenation in PostgreSQL
I have a table parcels which currently contains the columns owner_addr1, owner_addr2, owner_addr3. Sometimes, one or both of the latter two fields is empty. I want to combine them into a single new field, owner_addr where each of the above fields is…
J. Taylor
- 379
- 2
- 5
- 17
13
votes
4 answers
Find if any of the rows partially match a string
I want to see if a table contains any sub-string of a given string.
Let's say I have a string
somedomain.com
In database I have:
blabladomain.com
testdomain.com
domain.com
I need to make a query that will return "domain.com" as it is a…
Emanuel
- 263
- 1
- 3
- 10
13
votes
2 answers
Is there an efficient way to see the cause for "String or binary data would be truncated"?
This is a follow-up on this question. It is also related to this feature request from Microsoft.
However, many years have passed and several major releases reached the market since it was reported.
Question: does SQL Server 2017 provide any…
Alexei
- 1,191
- 1
- 14
- 36
13
votes
2 answers
Likes or votes for posts
I am making a small program where users makes posts or write blogs. On those posts, other users can like or dislike the post as in facebook or upvote or downvote the post as in stackoverflow. I would like to know a good database structure which is…
Harshit
- 247
- 1
- 2
- 8
11
votes
2 answers
SQL Server - NTEXT columns and string manipulation
I have a table with an NTEXT column called comments. I have a second string, let's call it anothercomment (a varchar) that needs placing inside a given comments string after the word UPDATEHERE.
Casting to nvarchar(max) truncates the comments…
Philᵀᴹ
- 31,952
- 10
- 86
- 108
9
votes
1 answer
Why do string functions on SQL based database servers start at position 1 instead of 0?
This has always bothered me. It seems that string functions in SQL based servers always start at position 1 (at least this is the case with MySQL, SQL Server, Oracle and Postgres). For example the following query would be used to select the first…
VKK
- 203
- 1
- 2
- 4
8
votes
2 answers
varchar(MAX) text cuts off while going more than 8000 characters inside a procedure
I have a procedure in which i have declared a variable with datatype varchar(MAX),
declare @str varchar(MAX);
set @str='select * from Table1...'
print (@str);
exec (@str);
but when the text written inside @str goes above 8000 characters (i.e.…
Priyank Pahuja
- 83
- 1
- 1
- 4
7
votes
1 answer
text column compares equal to where clause but does not select matching row
We are having trouble when querying a table in our production database. One text column will compare equal to a string we filter on in the where clause, but postgres will not select the row.
(We are on postgres 11.11)
Our table set up like…
Nate
- 73
- 5
7
votes
2 answers
How do you count the occurrences of an anchored string using PostgreSQL?
If I have a string in a column on a row in a table like this
1 2 2 2 2 2 2
How would I count the occurrence of a substring 2 inside the string. Assume nothing other than a space-delimiter of " ".
For the purposes of this, let's treat the numbers as…
Evan Carroll
- 65,432
- 50
- 254
- 507
7
votes
3 answers
T-SQL - How to split (char separated) string into rows and columns
What is the best way to split a char separated string into rows and columns?
Here is my input string:
!1;100;10;200;0;500;2;1000;30!2;100;3;500;1;2000;5
And here is my desired output table:
Id Value Count
1 100 10
1 200 0
1 500 2
1…
Tpsamw1
- 99
- 1
- 2
- 3
6
votes
5 answers
PostgreSQL: how can I shorten a multi-word string to few words?
I'm using PostgreSQL 9.5.6. I have space separated multi-word strings that I need to shorten to say 3 words?
I've looked at the documentation and in order to use the substring() functions I need to know the index position of the char where I want…
S.Ro
- 95
- 1
- 5
5
votes
1 answer
Unexpected Unique Constraint Violation
Given the following CREATE TABLE statement:
CREATE TABLE [dbo].[Unit]
(
[id] SMALLINT NOT NULL IDENTITY(1,1),
[name] VARCHAR(100) NOT NULL,
CONSTRAINT [PK_Unit] PRIMARY KEY CLUSTERED ([id]),
…
Calgary Coder
- 315
- 1
- 3
- 11
5
votes
1 answer
Match .csv values as INTs. If one value from a group in the .csv matches one in another group, then merge strings
Here we have two sets of numbers. The problem is that I can't figure out how to get from the input to the output of numbers (DDL and DML below and also in the fiddle…
user3050153
- 67
- 2