How to trim double quotes from string variable in postgreSQL function
Asked Answered
C

3

11

I have a function in postgreSQL,One of my function argument is text type variable and that enclosed with in double quotes so i want to insert this variable to table with out double quotes ,when i search regarding this on net i got a query like SELECT trim(both ' ' from 'techonthenet.com'); but this not working in the case of double quotes so how will i remove double quotes from text string variable in postgreSQL function

Chevron answered 19/9, 2019 at 4:27 Comment(1)
@Kei when i SELECT trim(both '"' from "techonthenet.com"); try this it seems errorChevron
S
19

It is working:

postgres=# select '"Hello"';
┌──────────┐
│ ?column? │
╞══════════╡
│ "Hello"  │
└──────────┘
(1 row)

postgres=# select trim(both '"' from '"Hello"');
┌───────┐
│ btrim │
╞═══════╡
│ Hello │
└───────┘
(1 row)
Southeast answered 19/9, 2019 at 4:37 Comment(0)
D
3

Another simple solution would be:

SELECT REPLACE('"Hello"', '"', '');
Despotic answered 13/4, 2020 at 9:39 Comment(0)
S
1

SELECT TRIM('"Hello"', '"');

I used the above code to remove quotes from a column containing strings wrapped in double quotes:

SELECT trim(lower(content_category), '"') FROM Content;

Here I nested a function, lower, inside another function TRIM. IT WORKED FINE.

Standoffish answered 16/9, 2023 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.