offwhitelotus
offwhitelotus

Reputation: 1079

hard coded selecting in postgres

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.

Upvotes: 1

Views: 2642

Answers (3)

D-Shih
D-Shih

Reputation: 46239

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

Upvotes: 1

Daniel Tran
Daniel Tran

Reputation: 6169

You need to use single quote, not double quote.

Select 'hi' as ham;

Upvotes: 1

HuntsMan
HuntsMan

Reputation: 792

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

select 'hi' as ham, 1 as eggs

Upvotes: 4

Related Questions