1

I have an application that was built by someone else that I need to edit. There is an area of code that I cannot find the right syntax for ... can someone please help.

The select statement in POSTGRES goes like this:

SELECT collection|| '/' ||color AS collection
FROM table
WHERE series = 'random number' <-- this is controlled by an array in the php 

in the php the existing code looks like this:

$tableName = $db->getOne('SELECT collection FROM item_series WHERE series = ?', array($series['marriage_1']));
}else{$tableName = $series['marriage_1'];}

I have tried this, but it is not working:

$tableName = $db->getOne('SELECT collection, ".'/'.", color AS collection FROM item_series WHERE series = ?', array($series['marriage_1']));
}else{
$tableName = $series['marriage_1'];}

Please help I have looked for an answer to this for hours!

1 Answer 1

1

Wouldn't it be this?

$db->getOne('select collection || \'/\' || color as collection ...', ...);

Or this?

$db->getOne("select collection || '/' || color as collection ...", ...);

Your attempt:

'SELECT collection, ".'/'.", color AS collection FROM item_series WHERE series = ?'

would end this SQL to the database:

SELECT collection, "/", color AS collection FROM item_series ...

and PostgreSQL wouldn't be upset with you for trying to use double quotes for a string literal, it would think you were trying to access a column called /. Besides, you want to concatenate and you want to use the || SQL operator for that.

Sign up to request clarification or add additional context in comments.

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.