1

Can someone tell me why this works in MySQL but not PostgreSQL?

select "hi" as ham, 1 as eggs

I'm trying to union a query with some hard-coded values.

Postgres says "ERROR: column "hi" does not exist Position: 8"

MySQL says the right thing.

2
  • Use single quote instead double quote.. Postgresql know hi as column not string.. Commented Nov 8, 2018 at 2:59
  • postgresql.org/docs/current/… Commented Nov 8, 2018 at 6:35

3 Answers 3

4

you need to change the " to ' double qoute to single qoute in postgress

select 'hi' as ham, 1 as eggs
Sign up to request clarification or add additional context in comments.

4 Comments

that works, thanks. i'll accept this answer in 11 minutes when I'm allowed ;)
is there any deep reason for this, or just arbirary syntactical design decision?
double quotes are used to name an identifier without changing its case like you want to create table CREATE TABLE "Sample" something like that
@offwhitelotus: that's not an "arbitrary design decision". This syntax was defined by the SQL standard 30 years ago.
1

You need to use single quote, not double quote.

Select 'hi' as ham;

Comments

1

If you want to let hi be row value you need to use single-qoute otherwise PostgreSQL DB Engine will take it as a column.

This sample ORDER is a keyword but I can use double-qoute to escape the keyword as column name, although I didn't encourage use keyword as a column name.

CREATE TABLE T("ORDER" INT);

INSERT INTO T VALUES (1);

SELECT "ORDER"
FROM T

sqlfiddle

so you might use like this.

select 'hi' as ham, 1 as eggs

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.