声明适用于Mysql但不适用于Postgres

时间:2016-02-03 20:00:51

标签: sql postgresql

这基本上将数值转换为我们在系统中使用的唯一标识符。它在我们的MySql数据库中工作正常,但在Postres上运行时它无法工作,我不太清楚为什么

CONCAT( 
  (240000000000 + AA.id),   
 (SUBSTRING((10 - ((((SUBSTRING((240000000000 + AA.id) FROM 2 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 4 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 6 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 8 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 10 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 12 FOR 1))*3) + (SUBSTRING((240000000000 + AA.id) FROM 1 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 3 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 5 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 7 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 9 FOR 1) + SUBSTRING((240000000000 + AA.id) FROM 11 FOR 1))) MOD 10)) FROM -1 FOR 1)) 
  ) AS 'BI_1_240_SKU'

这是我在postgres中的错误

SET
psql:C:/Users/kevin.jeung/Desktop/sql/test2:103: ERROR:  syntax error at or near "MOD"
LINE 5: ...SUBSTRING((240000000000 + AA.id) FROM 11 FOR 1))) MOD 10)) F...

我确信对于知道

的人来说,这是一个简单的语法更改

2 个答案:

答案 0 :(得分:2)

您的错误非常有用。 PostgreSQL无法识别MOD函数。

如果您查看documentationMOD,则必须使用%符号。

╔══════════╦═══════════════════════════════════════════════╦═══════════╦════════╗
║ Operator ║                  Description                  ║  Example  ║ Result ║
╠══════════╬═══════════════════════════════════════════════╬═══════════╬════════╣
║ +        ║ addition                                      ║ 2 + 3     ║      5 ║
║ -        ║ subtraction                                   ║ 2 - 3     ║     -1 ║
║ *        ║ multiplication                                ║ 2 * 3     ║      6 ║
║ /        ║ division (integer division truncates results) ║ 4 / 2     ║      2 ║
║ %        ║ modulo (remainder)                            ║ 5 % 4     ║      1 ║
║ ^        ║ exponentiation                                ║ 2.0 ^ 3.0 ║      8 ║
║ |/       ║ square root                                   ║ |/ 25.0   ║      5 ║
║ ||/      ║ cube root                                     ║ ||/ 27.0  ║      3 ║
║ !        ║ factorial                                     ║ 5 !       ║    120 ║
║ !!       ║ factorial (prefix operator)                   ║ !! 5      ║    120 ║
║ @        ║ absolute value                                ║ @ -5.0    ║      5 ║
║ &        ║ bitwise AND                                   ║ 91 & 15   ║     11 ║
║ |        ║ bitwise OR                                    ║ 32 | 3    ║     35 ║
║ #        ║ bitwise XOR                                   ║ 17 # 5    ║     20 ║
║ ~        ║ bitwise NOT                                   ║ ~1        ║     -2 ║
║ <<       ║ bitwise shift left                            ║ 1 << 4    ║     16 ║
║ >>       ║ bitwise shift right                           ║ 8 >> 2    ║      2 ║
╚══════════╩═══════════════════════════════════════════════╩═══════════╩════════╝

答案 1 :(得分:0)

您是否为ean13条码生成校验位?

// main/core/index.ts
export * from './foo';
export * from './bar';
export * from './baz';

更具可读性和更简单的含义如下:

// Example consumer
import { Foo, Bar, Baz } from 'core';