Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate string in statement that assigns a variable in PostgreSQL

Tags:

sql

postgresql

I am trying to convert SQL Server procedure to PostgreSQL.

In the SQL Server procedure There are statements like below

SET @val = '(' + @someval + ')'

So in postgresql I wrote as below

SET val = '(' || someval || ')';

But the above statement giving error at ||

Any body can please tell me where am I making mistake

like image 440
compyutech Avatar asked Oct 17 '13 05:10

compyutech


People also ask

How do I concatenate a string to a variable?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

How do you assign a selected value to a variable in PostgreSQL?

In PostgreSQL, the select into statement to select data from the database and assign it to a variable. Syntax: select select_list into variable_name from table_expression; In this syntax, one can place the variable after the into keyword.

What is || in PostgreSQL?

The PostgreSQL concatenate operator ( || ) is used to concatenate two or more strings and non strings.


Video Answer


1 Answers

AFAIK, SET statement in PostgreSQL used for changing configutation parameters, for variable assignment just use :=:

val := '(' || someval || ')';

sql fiddle demo

like image 69
Roman Pekar Avatar answered Oct 24 '22 18:10

Roman Pekar