2022 Developer Survey is open! Take survey.

Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
5 votes
1 answer
102 views

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 here). current_data 1,2,3 1,4 1,5,...
user avatar
0 votes
2 answers
71 views

Indexing on a fixed-length string (10 characters - phone numbers) for a large number of entries (performance)?

I understand that a lot of similar questions have already been asked but I could not find a definitive answer for my question. Briefly, I have to authenticate users using a REST API, with their phone ...
user avatar
  • 9
0 votes
1 answer
281 views

Calculating Average Value of JSONB array in Postgres

I have a column called "value" in my "answers" table. | value | |---------| | [1,2] | | [1] | | [1,2,3] | The type of "value" is "jsonb". I want to get ...
user avatar
6 votes
1 answer
107 views

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 ...
user avatar
  • 63
0 votes
1 answer
135 views

What exactly is the datatype input into a DATETIME value in MySQL

I am trying to get data from a PLC directly into a MySQL 8.0 database (using MySQL Workbench). I need to know what data type the input value is for a column set to DATETIME so I can send in the right ...
user avatar
  • 105
1 vote
2 answers
92 views

Replace specific part of a string

I've got a table with multiple columns, APGRPID, VIRTKEY, LFDNR and PARAMETERLIST. I want to change a part of some strings in the PARAMETERLIST column. In the PARAMETERLIST I want to replace the "...
user avatar
0 votes
2 answers
59 views

convert date in string format to date datatype sql [duplicate]

I have values in a column named Date as a nvarachar data type in the form of mmddyy and want to convert the values to a date datatype in the form of yyyy-mm-dd. What sql colde can I use to convert the ...
user avatar
2 votes
2 answers
309 views

WHERE Clause Compare VarChar(n) Column = VarChar(MAX) Variable Results in Inequality Comparison and Poor Query Performance

Earlier today I was working on a Reporting Stored Procedure which had poor performance. I was able to fix the issue by changing a static variable which held a string of ten characters or less from ...
user avatar
0 votes
1 answer
36 views

Levenshtein function returning different result based on limit value

The Levenshtein function is not working as I would have expect. Is there anything that I minsunderstood? Here is the query: SELECT c0.id, c0.engine_type, c0.mpg, c0.kwh, c0.price, c0.make, c0.model, ...
user avatar
1 vote
1 answer
232 views

How to write correct array string parameter for mysql query?

I'm trying to put up a correct string to pass as a parameter to a simple query. Correct query that returns records: SELECT id_s FROM group_of_id_s WHERE date IN ('2020-08-01','2020-08-01','2020-08-02',...
user avatar
2 votes
1 answer
28 views

Performing SQL string manipulations on a single column

I recently came across a problem at an interview which I wasn't able to answer. The ask was to write some SQL fetch the first three number(s) after crossing two 2 decimals. For example: Input table: ...
user avatar
0 votes
1 answer
20 views

String index for a list of values using IN($1,$2): will a btree index work?

We have a query that needs to compare a value to a list of values in a where clause. The strings are known and discrete. Does IN use the = operator to compare values? Would a b-tree index work for ...
user avatar
1 vote
1 answer
170 views

Count numbers in scientific notation (E-notation)

I'm trying to check if a part number field has scientific notation values and came up with this simple solution: SELECT count(*) as overall, count(*) filter (where partnumber ilike '%E+%') as ...
user avatar
  • 131
0 votes
1 answer
343 views

Mongodb index keeps growing in size eventhough the collection has a TTL index

I work on a mongodb sharded cluster (3.0.2 i know it's very outdated, not my call), on which i have a sharded db and a sharded collection on which i have multiple indexes. One of the indexes is a TTL ...
user avatar
  • 101
0 votes
1 answer
22 views

How do I send an array of strings to PG from PHP without the former becoming confused?

I want to do this, but for more than one string: SELECT * FROM table WHERE label <> $1 That selects all records from table where the label column is different from a single string. It works. ...
user avatar
2 votes
1 answer
955 views

Is there some function in PostgreSQL to simply check if the input string is valid UTF-8 according to PG?

For several years now, I've been hunting this extremely quick-footed little bug which knows every hiding place in my metaphorical coding house. He lurks in the walls, sometimes takes months to show ...
user avatar
2 votes
1 answer
1k views

character varying vs. text as function parameter types in PostgreSQL

Is there any significant difference (in performance for example) between character varying vs. text as types for db function parameters? I have 2 usage examples: Example 1: CREATE OR REPLACE ...
user avatar
1 vote
1 answer
348 views

How to output string values in single quotes?

I'm trying to convert values stored in a json into its string representation. The #>> operator works for this purpose for numbers, e.g.: SELECT '{"a":[1,2,3],"b":["4","5","6"]}'::json#>>'...
user avatar
  • 2,807
0 votes
1 answer
62 views

How do you combine the input of three parameters into one?

I'm working on a query that will run via C# to SQL server. I'm trying to make the query flexible and provide parameters for all the inputs. Here is the query: SELECT Test_Matrix.tblTestMatrix....
user avatar
2 votes
1 answer
191 views

Prefix scale for UTL_MATCH.JARO_WINKLER_SIMILARITY

This is a repeat of a previous question from several years ago that did not receive an answer. Oracle has a string matching package, UTL_MATCH, which contains the subprogram JARO_WINKLER_SIMILARITY. ...
user avatar
  • 21
1 vote
3 answers
1k views

Is there a more concise way in Postgres to extract a portion of a string?

I'm using Postgres 9.5. I have a table with a column that records URLs. Sometimes the URL has a query string and sometimes it does not. I would like to extract the URL, minus any query string, so I ...
user avatar
  • 585
3 votes
1 answer
573 views

reverse the characters of a string without changing the position of the numeric value in T-SQL

With T-SQL, I'm trying to find the easiest way to reverse the characters of a string without changing the position of the numeric value. So for string: abc223de11 have edc223ba11
user avatar
  • 41
0 votes
1 answer
128 views

SQL Server 2017 - Extracting source and target column names within a string containing column mappings

I have the following format string stored in text (could be any number of columns): col1_source|col1_target;col2_source|col2_target;col3_source|col3_target;... I'm trying to come up with an ...
user avatar
0 votes
2 answers
42 views

How to chop off X number of characters across multiple records?

Hello all! I have a field that contains geographical locations in the city-state format: Boston, MA Los Angeles, CA Helena, MT ... The field spans for some 230 records. My task is to chop off the ...
user avatar
1 vote
2 answers
568 views

SELECT i.c.w. a COUNT and INNER JOIN gives different results with string literals and numeric values when they are used in a WHERE clause

I have a MySQL query: SELECT p.informationProvider as pGLN, p.productID, p.productStatus FROM tblproducts AS p WHERE -- informationProvider is of type varchar(14) p....
user avatar
  • 422
-2 votes
2 answers
156 views

How to convert a multi-row result set into a single-row text separated by commas

I'm using this query select Name, valueType from mytable where ID = 1 and getting this table: But I need to covert the result set into something like: 'idGasto int, noTicket string, fechaFact ...
user avatar
4 votes
2 answers
792 views

String comparison without CASE statements?

Is there a shorter more terse way to do a string comparison in SQL Server without wrapping it in a CASE WHEN ... THEN 1 END? In PostgreSQL, I can do SELECT c, c='foo' FROM ( VALUES ('foo'),('bar') ) ...
user avatar
  • 55.8k
2 votes
1 answer
472 views

Is there any string compaction option for PostgreSQL?

I have a table like this: CREATE TABLE BLOG( CATEGORY CHAR(32) ); Category is a column, which stored enum values. For example, I have 1 millions of rows and 10 unique values of Category. Let'...
user avatar
  • 123
9 votes
2 answers
13k views

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 ...
user avatar
  • 317
0 votes
1 answer
422 views

MariaDB are bitwise operators defined on strings?

Is the behavior of BITAND, (bitwise and) defined in MariaDB over strings? SELECT '0011' & '0011', 'ff' & 'ff', 'yy' & 'YY', '5' & '5'; +-----------------+-------------+-------------+--...
user avatar
  • 55.8k
1 vote
1 answer
459 views

Does a Levenshtein distance involve some computation for each single row?

Let's say I have, in a SQL DB, a table with 2 columns: id integer, description text and 100,000 rows. The column description has always < 20 characters. If I want to: SELECT * FROM mytable WHERE ...
user avatar
  • 161
13 votes
4 answers
60k views

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 ...
user avatar
  • 263
3 votes
1 answer
374 views

Test if a string is a valid, unquoted identifier?

I'm just wondering if there is an established method for testing if a string can be used as an unquoted PostgreSQL identifier? (unquoted because almost any string can be a quoted identifier). I ask ...
user avatar
  • 2,807
0 votes
1 answer
38 views

Value of columns inOracle tables

I have many schemas in one oracle databse named SCHEMA1, SCHEMA2...SCHEMA999 I want to find specific value of column named "JN_OSUSER" which is string 'Ed.Spencer' How to find in every table, in ...
user avatar
0 votes
0 answers
39 views

Storing a lot of text / string data strategies - analysis and solution

I have a LOB application backed by SQL Server 2016. Over the past few weeks, theres been issues whereby the SQL Server start throwing timeout errors - which has led to a bit more digging into the ...
user avatar
13 votes
2 answers
2k views

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. ...
user avatar
  • 1,199
5 votes
2 answers
3k views

Equivalent to PostgreSQL's Dollar-quoted String Constants for SQL Server

Is there an equivalent of PostgreSQL's Dollar-quoted String Constants, on SQL Server? I would like to enter HTML string literals that would potentially contain single or double quotes in them. ...
user avatar
  • 151
5 votes
2 answers
2k views

Optimizing a Query for splitting strings with a known size

I have a Column that has a . as a delimiter, it looks like so.... abc.efg.hij I want a query that turns this into three columns, Col1, Col2, and Col3. I am wondering what the fastest way to do this ...
user avatar
  • 153
1 vote
2 answers
349 views

SQL regex PostgreSQL

Let's consider a table like that: id | name 1 | This is a test sentence 2 | is a sentence TeST 3 | This a IS test sentence 4 | iS a tEst sentence tHis 5 | This a test sentence is How ...
user avatar
  • 15
6 votes
1 answer
10k views

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 ...
user avatar
2 votes
1 answer
765 views

How do you unescape "C-like backslash escape sequence" that come from a function?

This will unescape the \n\n sequence. SELECT E'\n\nFOO'; But if that same sequence comes from a function, what do you do. CREATE FUNCTION asdf() RETURNS text AS $$ SELECT '\n\nFOO'::text $$ ...
user avatar
  • 55.8k
6 votes
5 answers
2k views

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 ...
user avatar
  • 95
3 votes
2 answers
15k views

Is there an easy way in PostgreSQL to escape newlines, carriage returns, and tabs?

Let's say I want to escape these to see a similar string SELECT * FROM ( VALUES (E'\r\n\t FOO BAR \t\n\r') ) AS t(str); How do I get the c-style escapes, \r\n\t FOO BAR \t\n\r back out? SELECT * ...
user avatar
  • 55.8k
0 votes
2 answers
729 views

DevExpress formats columns differently if they're all numbers

I have a table with a 'Code' column, defined as varchar. However, if you have only numbers in some of the records, for this field, and you search on these records in our application, the results in ...
user avatar
5 votes
2 answers
14k views

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 " ". ...
user avatar
  • 55.8k
3 votes
2 answers
4k views

How could i search between two string type date

Consider these two tables. I use persian dates, so I have to declare startdate and enddate as a string(nvarchar(10)). crt table: id title startdate enddate -------------------------- 1 xyz 1395/...
user avatar
0 votes
1 answer
469 views

Return result set as string

I have a table with SELECT fName, lName FROM person It returns 3 results I want to return a concat(fName, ' ', lName) and 2 "and"s in between each concat. Jon Snow and Margaery Tyrell and Peter ...
user avatar
1 vote
1 answer
1k views

Mixture of byte and character semantics in Oracle DB

Are there any issues having a mixture of byte and character semantics in a table? E.g. Location table: location_type varchar2(3 byte) location_name varchar2(50 char) How about a schema having a ...
user avatar
11 votes
2 answers
8k views

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. ...
user avatar
  • 30.8k
1 vote
2 answers
5k views

Remove both Special Characters and String Characters from output SQL Server

I am looking to remove some string characters in an output that I have so that it only shows numbers rather then letters and numbers. My Query is: Select DISTINCT t.processed 'Title', (Select max(...
user avatar
  • 11