Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
977 views
in Technique[技术] by (71.8m points)

php - Doctrine - PostgreSQL - Uppercase and Spaces in Table / Field names

Having issues with Doctrine 2.3 and PostgreSQL with Spaces and Upper case Field / Table names

Example: ( Yes we are working on migrating away from this )

SELECT "Field Name"
FROM "Table Name"

We also have a mix of the two formats

SELECT "Field Name", another_field_name
FROM "Table Name", another_table_name

When using doctrine I'm getting a PDOException. When looking at the error I see that there are no double quotes around Fields / Tables ( names ) that have Upper case and Spaces.

Is there a fix? Workaround?

Here is an example of what Doctrine is generating

SELECT t0.TheId AS theid1, t0.Name AS name2, t0.User AS user3
FROM The Table t0 
WHERE t0.TheId = 1234

Here is how I need it

SELECT t0."TheId" AS theid1, t0."Name" AS name2, t0."User" AS user3
FROM "The Table" t0 
WHERE t0."TheId" = 1234
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You may need to use backticks to let Doctrine know that it should be quoted: Quoting reserved words. E.g:

<?php
/** @Column(name="`number`", type="integer") */
private $number;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...