?
Solved

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

Posted on 2016-10-27
3
Medium Priority
?
116 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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 17

Accepted Solution

by:
Chris Harte earned 1000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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