hard coded selecting in postgres

1378 views sql
7

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.

answered question

Use single quote instead double quote.. Postgresql know hi as column not string..

3 Answers

0

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

select 'hi' as ham, 1 as eggs

posted this
10

You need to use single quote, not double quote.

Select 'hi' as ham;

posted this
9

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

posted this

Have an answer?

JD

Please login first before posting an answer.