0

I am migrating from mssql to postgresql

I am trying to assign a value to a temporary variable in select query

Below is the query in mssql

select flag = 0

It gives 0 as output wit flag as column identifier in mssql

I tried the following in postgresql

select flag := 0
select flag [:=0]

It says syntax error at or near :=

Does anybody know where I am going wrong?

2
  • I hope this will help you postgresqltutorial.com/plpgsql-variables Commented Oct 22, 2020 at 12:35
  • That's not a "variable" that's a column (expression) Commented Oct 22, 2020 at 12:38

1 Answer 1

2

It gives 0 as output wit flag as column identifier in mssql

Postgres honors the SQL standard and a column alias is defined with the AS keyword there.

So to get a column named flag with the value zero use the following:

select 0 as flag

flag = 0 in standard SQL (and Postgres) is a boolean expression that compares the the column flag with the value zero and returns either true, false or null depending on the column's value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.