Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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.

744 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

12 Experts available now in Live!

Get 1:1 Help Now