Solved

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

Posted on 2016-10-27
3
88 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 109

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 17

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 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