Expressions - noresources/ns-php-sql GitHub Wiki

SQL expressions

Literal expressions

Suitable for constant statements

Timestamp

Timestamp must follow the ISO 8601 format with the following restrictions

  • The midnight notation 24:00 is not supported
  • Fractional time is only accepted for seconds

Polish notation

Suitable for complex and programatically built statements.

Basic elements

General syntax

[ 'operator' => [ operand1, operand2 ]  ]

Operators

# Binary
[ '=' => [ left-expression, right-expression ]  ]
# Unary
[ 'not' => [ expression ]  ]

Functions

[ 'function-name()' => [arg1, arg2, ...] ]

SELECT result columns syntax

$query->column (
	'expression',                        // Evaluable expression string
	[ 'expression', 'alias' ],
	[ 'polish' => [ ... ] ],             // Polish notation expression
	[ ['polish' => [ ... ]], 'alias' ] 
	);

WHERE, HAVING and other constraint clauses syntax

$query->where (
	'expression',					    // Evaluable expression string
	[ 'column  => 'expression' ],        // Shorthand for [ '=' => [ 'column', 'expression' ]]  				
);

// ? Parameters => use expressions
// ? Functions => use expressions

References