Michi
Michi

Reputation: 5471

Blank spaces in column title in query

DB-Fiddle

CREATE TABLE inventory (
    id SERIAL PRIMARY KEY,
    product VARCHAR,
    quantity DECIMAL
);

INSERT INTO inventory
(product, quantity)
VALUES 
('product_01', '800'),
('product_02', '300'),
('product_03', '200'),
('product_04', '500'),
('product_05', '600'),
('product_06', '400');

Expected Result:

product_name  |   product name   |
--------------|------------------|---------
product_01    |   product_01     |
product_02    |   product_02     | 
product_03    |   product_03     |
product_04    |   product_04     |
product_05    |   product_05     |
product_06    |   product_06     |

My issue is that I am not able to name the column product name in the query as I did it in MariaDB.
As far as I can tell the reason for this is that postgresSQL does not accept the blank space between product and name.

I am currently using this query:

SELECT
iv.product AS product_name,
iv.product AS 'product name'
FROM inventory iv;

Is there a way to make this work in postgresSQL or is the only option to not have blank spaces?

Upvotes: 0

Views: 34

Answers (1)

diiN__________
diiN__________

Reputation: 7666

Use double quotes DB-Fiddle:

SELECT iv.product AS product_name,
    iv.product AS "product name"
FROM inventory iv;

Upvotes: 1

Related Questions