Solved

put ' '   inside  ' '   in sql (postgres)   php statement

Posted on 2016-10-27
3
61 Views
Last Modified: 2016-10-28
SELECT
public.pong8_maintable.stockid,
public.pong8_maintable.filname,

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,

public.pong8_maintable."Turnover"
FROM
public.pong8_maintable

Open in new window


The code above is work

But when in php  - Postgres it not work
$sql ='

CREATE TABLE pong8_StepOneSection as
SELECT
public.pong8_maintable.stockid,
public.pong8_maintable.filname,

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,


public.pong8_maintable."Turnover"
FROM
Public.pong8_maintable

' ;

Open in new window

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,       , how can I  change 'hour'
0
Comment
Question by:teera
3 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 41863663
Try using HEREDOC notation.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

I don't know if the PostGreSQL syntax is right, but this works well for the PHP side of things!
$sql = <<<END

CREATE TABLE pong8_StepOneSection as
SELECT
public.pong8_maintable.stockid,
public.pong8_maintable.filname,

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,


public.pong8_maintable."Turnover"
FROM
Public.pong8_maintable

END;

Open in new window

0
 
LVL 16

Accepted Solution

by:
Chris Harte earned 250 total points
ID: 41864007
What Ray said, Or... just escape the quotes on the hour

date_trunc(\'hour\', public.pong8_maintable."timestamp8") as Date_hour,

Open in new window

0
 

Author Closing Comment

by:teera
ID: 41864860
Thank you
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now